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

Side by Side Diff: chrome/browser/extensions/api/browsing_data/browsing_data_api.cc

Issue 10855049: Deal correctly with BrowsingData API calls during startup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DCHECK. Created 8 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Defines the Chrome Extensions BrowsingData API functions, which entail 5 // Defines the Chrome Extensions BrowsingData API functions, which entail
6 // clearing browsing data, and clearing the browser's cache (which, let's be 6 // clearing browsing data, and clearing the browser's cache (which, let's be
7 // honest, are the same thing), as specified in the extension API JSON. 7 // honest, are the same thing), as specified in the extension API JSON.
8 8
9 #include "chrome/browser/extensions/api/browsing_data/browsing_data_api.h" 9 #include "chrome/browser/extensions/api/browsing_data/browsing_data_api.h"
10 10
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } // namespace 109 } // namespace
110 110
111 void BrowsingDataExtensionFunction::OnBrowsingDataRemoverDone() { 111 void BrowsingDataExtensionFunction::OnBrowsingDataRemoverDone() {
112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
113 this->SendResponse(true); 113 this->SendResponse(true);
114 114
115 Release(); // Balanced in RunImpl. 115 Release(); // Balanced in RunImpl.
116 } 116 }
117 117
118 bool BrowsingDataExtensionFunction::RunImpl() { 118 bool BrowsingDataExtensionFunction::RunImpl() {
119 // If we don't have a profile, something's pretty wrong.
120 DCHECK(profile());
121
119 if (BrowsingDataRemover::is_removing()) { 122 if (BrowsingDataRemover::is_removing()) {
120 error_ = extension_browsing_data_api_constants::kOneAtATimeError; 123 error_ = extension_browsing_data_api_constants::kOneAtATimeError;
121 return false; 124 return false;
122 } 125 }
123 126
124 // Grab the initial |options| parameter, and parse out the arguments. 127 // Grab the initial |options| parameter, and parse out the arguments.
125 DictionaryValue* options; 128 DictionaryValue* options;
126 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options)); 129 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options));
127 DCHECK(options); 130 DCHECK(options);
128 131
(...skipping 11 matching lines...) Expand all
140 // object. So we need to do special handling here. 143 // object. So we need to do special handling here.
141 remove_since_ = (ms_since_epoch == 0) ? 144 remove_since_ = (ms_since_epoch == 0) ?
142 base::Time::UnixEpoch() : 145 base::Time::UnixEpoch() :
143 base::Time::FromDoubleT(ms_since_epoch / 1000.0); 146 base::Time::FromDoubleT(ms_since_epoch / 1000.0);
144 147
145 removal_mask_ = GetRemovalMask(); 148 removal_mask_ = GetRemovalMask();
146 149
147 if (removal_mask_ & BrowsingDataRemover::REMOVE_PLUGIN_DATA) { 150 if (removal_mask_ & BrowsingDataRemover::REMOVE_PLUGIN_DATA) {
148 // If we're being asked to remove plugin data, check whether it's actually 151 // If we're being asked to remove plugin data, check whether it's actually
149 // supported. 152 // supported.
150 Profile* profile = GetCurrentBrowser()->profile();
151 BrowserThread::PostTask( 153 BrowserThread::PostTask(
152 BrowserThread::FILE, FROM_HERE, 154 BrowserThread::FILE, FROM_HERE,
153 base::Bind( 155 base::Bind(
154 &BrowsingDataExtensionFunction::CheckRemovingPluginDataSupported, 156 &BrowsingDataExtensionFunction::CheckRemovingPluginDataSupported,
155 this, 157 this,
156 PluginPrefs::GetForProfile(profile))); 158 PluginPrefs::GetForProfile(profile())));
157 } else { 159 } else {
158 StartRemoving(); 160 StartRemoving();
159 } 161 }
160 162
161 // Will finish asynchronously. 163 // Will finish asynchronously.
162 return true; 164 return true;
163 } 165 }
164 166
165 void BrowsingDataExtensionFunction::CheckRemovingPluginDataSupported( 167 void BrowsingDataExtensionFunction::CheckRemovingPluginDataSupported(
166 scoped_refptr<PluginPrefs> plugin_prefs) { 168 scoped_refptr<PluginPrefs> plugin_prefs) {
167 if (!PluginDataRemoverHelper::IsSupported(plugin_prefs)) 169 if (!PluginDataRemoverHelper::IsSupported(plugin_prefs))
168 removal_mask_ &= ~BrowsingDataRemover::REMOVE_PLUGIN_DATA; 170 removal_mask_ &= ~BrowsingDataRemover::REMOVE_PLUGIN_DATA;
169 171
170 BrowserThread::PostTask( 172 BrowserThread::PostTask(
171 BrowserThread::UI, FROM_HERE, 173 BrowserThread::UI, FROM_HERE,
172 base::Bind(&BrowsingDataExtensionFunction::StartRemoving, this)); 174 base::Bind(&BrowsingDataExtensionFunction::StartRemoving, this));
173 } 175 }
174 176
175 void BrowsingDataExtensionFunction::StartRemoving() { 177 void BrowsingDataExtensionFunction::StartRemoving() {
176 // If we're good to go, add a ref (Balanced in OnBrowsingDataRemoverDone) 178 // If we're good to go, add a ref (Balanced in OnBrowsingDataRemoverDone)
177 AddRef(); 179 AddRef();
178 180
179 // Create a BrowsingDataRemover, set the current object as an observer (so 181 // Create a BrowsingDataRemover, set the current object as an observer (so
180 // that we're notified after removal) and call remove() with the arguments 182 // that we're notified after removal) and call remove() with the arguments
181 // we've generated above. We can use a raw pointer here, as the browsing data 183 // we've generated above. We can use a raw pointer here, as the browsing data
182 // remover is responsible for deleting itself once data removal is complete. 184 // remover is responsible for deleting itself once data removal is complete.
183 BrowsingDataRemover* remover = new BrowsingDataRemover( 185 BrowsingDataRemover* remover = new BrowsingDataRemover(profile(),
184 GetCurrentBrowser()->profile(), remove_since_, base::Time::Now()); 186 remove_since_, base::Time::Now());
185 remover->AddObserver(this); 187 remover->AddObserver(this);
186 remover->Remove(removal_mask_, origin_set_mask_); 188 remover->Remove(removal_mask_, origin_set_mask_);
187 } 189 }
188 190
189 int BrowsingDataExtensionFunction::ParseOriginSetMask( 191 int BrowsingDataExtensionFunction::ParseOriginSetMask(
190 const base::DictionaryValue& options) { 192 const base::DictionaryValue& options) {
191 // Parse the |options| dictionary to generate the origin set mask. Default to 193 // Parse the |options| dictionary to generate the origin set mask. Default to
192 // UNPROTECTED_WEB if the developer doesn't specify anything. 194 // UNPROTECTED_WEB if the developer doesn't specify anything.
193 int mask = BrowsingDataHelper::UNPROTECTED_WEB; 195 int mask = BrowsingDataHelper::UNPROTECTED_WEB;
194 196
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 return BrowsingDataRemover::REMOVE_PLUGIN_DATA; 281 return BrowsingDataRemover::REMOVE_PLUGIN_DATA;
280 } 282 }
281 283
282 int RemovePasswordsFunction::GetRemovalMask() const { 284 int RemovePasswordsFunction::GetRemovalMask() const {
283 return BrowsingDataRemover::REMOVE_PASSWORDS; 285 return BrowsingDataRemover::REMOVE_PASSWORDS;
284 } 286 }
285 287
286 int RemoveWebSQLFunction::GetRemovalMask() const { 288 int RemoveWebSQLFunction::GetRemovalMask() const {
287 return BrowsingDataRemover::REMOVE_WEBSQL; 289 return BrowsingDataRemover::REMOVE_WEBSQL;
288 } 290 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698