Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: chrome/browser/chrome_quota_permission_context.cc

Issue 11644059: Change infobar creation to use a public static Create() method on the infobar delegate classes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chrome_quota_permission_context.h" 5 #include "chrome/browser/chrome_quota_permission_context.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 20 matching lines...) Expand all
31 namespace { 31 namespace {
32 32
33 // If we requested larger quota than this threshold, show a different 33 // If we requested larger quota than this threshold, show a different
34 // message to the user. 34 // message to the user.
35 const int64 kRequestLargeQuotaThreshold = 5 * 1024 * 1024; 35 const int64 kRequestLargeQuotaThreshold = 5 * 1024 * 1024;
36 36
37 class RequestQuotaInfoBarDelegate : public ConfirmInfoBarDelegate { 37 class RequestQuotaInfoBarDelegate : public ConfirmInfoBarDelegate {
38 public: 38 public:
39 typedef QuotaPermissionContext::PermissionCallback PermissionCallback; 39 typedef QuotaPermissionContext::PermissionCallback PermissionCallback;
40 40
41 // Creates a request quota infobar delegate and adds it to |infobar_service|.
42 static void Create(
43 InfoBarService* infobar_service,
44 ChromeQuotaPermissionContext* context,
45 const GURL& origin_url,
46 int64 requested_quota,
47 const std::string& display_languages,
48 const PermissionCallback& callback);
49
50 private:
41 RequestQuotaInfoBarDelegate( 51 RequestQuotaInfoBarDelegate(
42 InfoBarService* infobar_service, 52 InfoBarService* infobar_service,
43 ChromeQuotaPermissionContext* context, 53 ChromeQuotaPermissionContext* context,
44 const GURL& origin_url, 54 const GURL& origin_url,
45 int64 requested_quota, 55 int64 requested_quota,
46 const std::string& display_languages, 56 const std::string& display_languages,
47 const PermissionCallback& callback) 57 const PermissionCallback& callback)
48 : ConfirmInfoBarDelegate(infobar_service), 58 : ConfirmInfoBarDelegate(infobar_service),
49 context_(context), 59 context_(context),
50 origin_url_(origin_url), 60 origin_url_(origin_url),
51 display_languages_(display_languages), 61 display_languages_(display_languages),
52 requested_quota_(requested_quota), 62 requested_quota_(requested_quota),
53 callback_(callback) {} 63 callback_(callback) {}
54 64
55 private:
56 virtual ~RequestQuotaInfoBarDelegate() { 65 virtual ~RequestQuotaInfoBarDelegate() {
57 if (!callback_.is_null()) 66 if (!callback_.is_null())
58 context_->DispatchCallbackOnIOThread( 67 context_->DispatchCallbackOnIOThread(
59 callback_, 68 callback_,
60 QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_CANCELLED); 69 QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_CANCELLED);
61 } 70 }
62 71
63 virtual bool ShouldExpireInternal( 72 virtual bool ShouldExpireInternal(
64 const content::LoadCommittedDetails& details) 73 const content::LoadCommittedDetails& details)
65 const OVERRIDE { 74 const OVERRIDE {
66 return false; 75 return false;
67 } 76 }
68 77
69 virtual string16 GetMessageText() const OVERRIDE; 78 virtual string16 GetMessageText() const OVERRIDE;
70 virtual bool Accept() OVERRIDE; 79 virtual bool Accept() OVERRIDE;
71 virtual bool Cancel() OVERRIDE; 80 virtual bool Cancel() OVERRIDE;
72 81
73 scoped_refptr<ChromeQuotaPermissionContext> context_; 82 scoped_refptr<ChromeQuotaPermissionContext> context_;
74 GURL origin_url_; 83 GURL origin_url_;
75 std::string display_languages_; 84 std::string display_languages_;
76 int64 requested_quota_; 85 int64 requested_quota_;
77 PermissionCallback callback_; 86 PermissionCallback callback_;
78 DISALLOW_COPY_AND_ASSIGN(RequestQuotaInfoBarDelegate); 87 DISALLOW_COPY_AND_ASSIGN(RequestQuotaInfoBarDelegate);
79 }; 88 };
80 89
90 // static
91 void RequestQuotaInfoBarDelegate::Create(
92 InfoBarService* infobar_service,
93 ChromeQuotaPermissionContext* context,
94 const GURL& origin_url,
95 int64 requested_quota,
96 const std::string& display_languages,
97 const QuotaPermissionContext::PermissionCallback& callback) {
98 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
99 new RequestQuotaInfoBarDelegate(infobar_service, context, origin_url,
100 requested_quota, display_languages,
101 callback)));
102 }
103
81 string16 RequestQuotaInfoBarDelegate::GetMessageText() const { 104 string16 RequestQuotaInfoBarDelegate::GetMessageText() const {
82 return l10n_util::GetStringFUTF16( 105 return l10n_util::GetStringFUTF16(
83 (requested_quota_ > kRequestLargeQuotaThreshold ? 106 (requested_quota_ > kRequestLargeQuotaThreshold ?
84 IDS_REQUEST_LARGE_QUOTA_INFOBAR_QUESTION : 107 IDS_REQUEST_LARGE_QUOTA_INFOBAR_QUESTION :
85 IDS_REQUEST_QUOTA_INFOBAR_QUESTION), 108 IDS_REQUEST_QUOTA_INFOBAR_QUESTION),
86 net::FormatUrl(origin_url_, display_languages_)); 109 net::FormatUrl(origin_url_, display_languages_));
87 } 110 }
88 111
89 bool RequestQuotaInfoBarDelegate::Accept() { 112 bool RequestQuotaInfoBarDelegate::Accept() {
90 context_->DispatchCallbackOnIOThread( 113 context_->DispatchCallbackOnIOThread(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 InfoBarService::FromWebContents(web_contents); 164 InfoBarService::FromWebContents(web_contents);
142 if (!infobar_service) { 165 if (!infobar_service) {
143 // The tab has no infobar service. 166 // The tab has no infobar service.
144 LOG(WARNING) << "Attempt to request quota from a background page: " 167 LOG(WARNING) << "Attempt to request quota from a background page: "
145 << render_process_id << "," << render_view_id; 168 << render_process_id << "," << render_view_id;
146 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); 169 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED);
147 return; 170 return;
148 } 171 }
149 Profile* profile = 172 Profile* profile =
150 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 173 Profile::FromBrowserContext(web_contents->GetBrowserContext());
151 infobar_service->AddInfoBar(new RequestQuotaInfoBarDelegate( 174 RequestQuotaInfoBarDelegate::Create(
152 infobar_service, this, origin_url, requested_quota, 175 infobar_service, this, origin_url, requested_quota,
153 profile->GetPrefs()->GetString(prefs::kAcceptLanguages), 176 profile->GetPrefs()->GetString(prefs::kAcceptLanguages),
154 callback)); 177 callback);
155 } 178 }
156 179
157 void ChromeQuotaPermissionContext::DispatchCallbackOnIOThread( 180 void ChromeQuotaPermissionContext::DispatchCallbackOnIOThread(
158 const PermissionCallback& callback, 181 const PermissionCallback& callback,
159 QuotaPermissionResponse response) { 182 QuotaPermissionResponse response) {
160 DCHECK_EQ(false, callback.is_null()); 183 DCHECK_EQ(false, callback.is_null());
161 184
162 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 185 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
163 BrowserThread::PostTask( 186 BrowserThread::PostTask(
164 BrowserThread::IO, FROM_HERE, 187 BrowserThread::IO, FROM_HERE,
165 base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, 188 base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread,
166 this, callback, response)); 189 this, callback, response));
167 return; 190 return;
168 } 191 }
169 192
170 callback.Run(response); 193 callback.Run(response);
171 } 194 }
172 195
173 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} 196 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {}
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_metrics_unittest.cc ('k') | chrome/browser/chromeos/login/webui_login_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698