diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-18 23:12:08 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-18 23:12:08 +0000 |
commit | c8d98dd12686c1c350312337fa2aba310f0e537f (patch) | |
tree | 390fdc1f7df3653e74bab10928db68f24841ad26 /chrome/browser/chrome_quota_permission_context.cc | |
parent | 6651074b1d3efab5b291d7eda385809517a60653 (diff) | |
download | chromium_src-c8d98dd12686c1c350312337fa2aba310f0e537f.zip chromium_src-c8d98dd12686c1c350312337fa2aba310f0e537f.tar.gz chromium_src-c8d98dd12686c1c350312337fa2aba310f0e537f.tar.bz2 |
base::Bind: Convert QuotaPermissionContext::PermissionCallback.
BUG=none
TEST=none
R=csilv@chromium.org
Review URL: http://codereview.chromium.org/8348010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106163 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chrome_quota_permission_context.cc')
-rw-r--r-- | chrome/browser/chrome_quota_permission_context.cc | 52 |
1 files changed, 24 insertions, 28 deletions
diff --git a/chrome/browser/chrome_quota_permission_context.cc b/chrome/browser/chrome_quota_permission_context.cc index 09acedd..8988dd6 100644 --- a/chrome/browser/chrome_quota_permission_context.cc +++ b/chrome/browser/chrome_quota_permission_context.cc @@ -6,6 +6,7 @@ #include <string> +#include "base/bind.h" #include "base/utf_string_conversions.h" #include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/prefs/pref_service.h" @@ -39,7 +40,7 @@ class RequestQuotaInfoBarDelegate : public ConfirmInfoBarDelegate { const GURL& origin_url, int64 requested_quota, const std::string& display_languages, - PermissionCallback* callback) + const PermissionCallback& callback) : ConfirmInfoBarDelegate(infobar_helper), context_(context), origin_url_(origin_url), @@ -49,9 +50,9 @@ class RequestQuotaInfoBarDelegate : public ConfirmInfoBarDelegate { private: virtual ~RequestQuotaInfoBarDelegate() { - if (callback_.get()) + if (!callback_.is_null()) context_->DispatchCallbackOnIOThread( - callback_.release(), QuotaPermissionContext::kResponseCancelled); + callback_, QuotaPermissionContext::kResponseCancelled); } virtual bool ShouldExpire( @@ -59,6 +60,7 @@ class RequestQuotaInfoBarDelegate : public ConfirmInfoBarDelegate { const OVERRIDE { return false; } + virtual string16 GetMessageText() const OVERRIDE; virtual void InfoBarDismissed() OVERRIDE; virtual bool Accept() OVERRIDE; @@ -68,13 +70,13 @@ class RequestQuotaInfoBarDelegate : public ConfirmInfoBarDelegate { GURL origin_url_; std::string display_languages_; int64 requested_quota_; - scoped_ptr<PermissionCallback> callback_; + PermissionCallback callback_; DISALLOW_COPY_AND_ASSIGN(RequestQuotaInfoBarDelegate); }; void RequestQuotaInfoBarDelegate::InfoBarDismissed() { context_->DispatchCallbackOnIOThread( - callback_.release(), QuotaPermissionContext::kResponseCancelled); + callback_, QuotaPermissionContext::kResponseCancelled); } string16 RequestQuotaInfoBarDelegate::GetMessageText() const { @@ -87,13 +89,13 @@ string16 RequestQuotaInfoBarDelegate::GetMessageText() const { bool RequestQuotaInfoBarDelegate::Accept() { context_->DispatchCallbackOnIOThread( - callback_.release(), QuotaPermissionContext::kResponseAllow); + callback_, QuotaPermissionContext::kResponseAllow); return true; } bool RequestQuotaInfoBarDelegate::Cancel() { context_->DispatchCallbackOnIOThread( - callback_.release(), QuotaPermissionContext::kResponseCancelled); + callback_, QuotaPermissionContext::kResponseCancelled); return true; } @@ -111,23 +113,20 @@ void ChromeQuotaPermissionContext::RequestQuotaPermission( int64 requested_quota, int render_process_id, int render_view_id, - PermissionCallback* callback_ptr) { - scoped_ptr<PermissionCallback> callback(callback_ptr); + const PermissionCallback& callback) { if (type != quota::kStorageTypePersistent) { // For now we only support requesting quota with this interface // for Persistent storage type. - callback->Run(kResponseDisallow); + callback.Run(kResponseDisallow); return; } if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - NewRunnableMethod( - this, - &ChromeQuotaPermissionContext::RequestQuotaPermission, - origin_url, type, requested_quota, - render_process_id, render_view_id, callback.release())); + base::Bind(&ChromeQuotaPermissionContext::RequestQuotaPermission, this, + origin_url, type, requested_quota,render_process_id, + render_view_id, callback)); return; } @@ -137,7 +136,7 @@ void ChromeQuotaPermissionContext::RequestQuotaPermission( // The tab may have gone away or the request may not be from a tab. LOG(WARNING) << "Attempt to request quota tabless renderer: " << render_process_id << "," << render_view_id; - DispatchCallbackOnIOThread(callback.release(), kResponseCancelled); + DispatchCallbackOnIOThread(callback, kResponseCancelled); return; } @@ -145,26 +144,23 @@ void ChromeQuotaPermissionContext::RequestQuotaPermission( TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); InfoBarTabHelper* infobar_helper = wrapper->infobar_tab_helper(); infobar_helper->AddInfoBar(new RequestQuotaInfoBarDelegate( - infobar_helper, - this, - origin_url, - requested_quota, + infobar_helper, this, origin_url, requested_quota, wrapper->profile()->GetPrefs()->GetString(prefs::kAcceptLanguages), - callback.release())); + callback)); } void ChromeQuotaPermissionContext::DispatchCallbackOnIOThread( - PermissionCallback* callback_ptr, + const PermissionCallback& callback, Response response) { - DCHECK(callback_ptr); - scoped_ptr<PermissionCallback> callback(callback_ptr); + DCHECK_EQ(false, callback.is_null()); + if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, - NewRunnableMethod( - this, &ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, - callback.release(), response)); + base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, + this, callback, response)); return; } - callback->Run(response); + + callback.Run(response); } |