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

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

Issue 2504943002: Remove the "one at a time" restriction from the browsingData API (Closed)
Patch Set: Created 4 years, 1 month 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
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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 const char kProtectedWebKey[] = "protectedWeb"; 58 const char kProtectedWebKey[] = "protectedWeb";
59 const char kSinceKey[] = "since"; 59 const char kSinceKey[] = "since";
60 const char kUnprotectedWebKey[] = "unprotectedWeb"; 60 const char kUnprotectedWebKey[] = "unprotectedWeb";
61 61
62 // Errors! 62 // Errors!
63 // The placeholder will be filled by the name of the affected data type (e.g., 63 // The placeholder will be filled by the name of the affected data type (e.g.,
64 // "history"). 64 // "history").
65 const char kBadDataTypeDetails[] = "Invalid value for data type '%s'."; 65 const char kBadDataTypeDetails[] = "Invalid value for data type '%s'.";
66 const char kDeleteProhibitedError[] = "Browsing history and downloads are not " 66 const char kDeleteProhibitedError[] = "Browsing history and downloads are not "
67 "permitted to be removed."; 67 "permitted to be removed.";
68 const char kOneAtATimeError[] = "Only one 'browsingData' API call can run at "
69 "a time.";
70 68
71 } // namespace extension_browsing_data_api_constants 69 } // namespace extension_browsing_data_api_constants
72 70
73 namespace { 71 namespace {
74 int MaskForKey(const char* key) { 72 int MaskForKey(const char* key) {
75 if (strcmp(key, extension_browsing_data_api_constants::kAppCacheKey) == 0) 73 if (strcmp(key, extension_browsing_data_api_constants::kAppCacheKey) == 0)
76 return BrowsingDataRemover::REMOVE_APPCACHE; 74 return BrowsingDataRemover::REMOVE_APPCACHE;
77 if (strcmp(key, extension_browsing_data_api_constants::kCacheKey) == 0) 75 if (strcmp(key, extension_browsing_data_api_constants::kCacheKey) == 0)
78 return BrowsingDataRemover::REMOVE_CACHE; 76 return BrowsingDataRemover::REMOVE_CACHE;
79 if (strcmp(key, extension_browsing_data_api_constants::kCookiesKey) == 0) { 77 if (strcmp(key, extension_browsing_data_api_constants::kCookiesKey) == 0) {
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 removal_mask_ &= ~BrowsingDataRemover::REMOVE_PLUGIN_DATA; 305 removal_mask_ &= ~BrowsingDataRemover::REMOVE_PLUGIN_DATA;
308 306
309 BrowserThread::PostTask( 307 BrowserThread::PostTask(
310 BrowserThread::UI, FROM_HERE, 308 BrowserThread::UI, FROM_HERE,
311 base::Bind(&BrowsingDataRemoverFunction::StartRemoving, this)); 309 base::Bind(&BrowsingDataRemoverFunction::StartRemoving, this));
312 } 310 }
313 311
314 void BrowsingDataRemoverFunction::StartRemoving() { 312 void BrowsingDataRemoverFunction::StartRemoving() {
315 BrowsingDataRemover* remover = 313 BrowsingDataRemover* remover =
316 BrowsingDataRemoverFactory::GetForBrowserContext(GetProfile()); 314 BrowsingDataRemoverFactory::GetForBrowserContext(GetProfile());
317 // TODO(msramek): This restriction is no longer needed. Remove it. 315 // Add a ref (Balanced in OnBrowsingDataRemoverDone)
318 if (remover->is_removing()) {
319 error_ = extension_browsing_data_api_constants::kOneAtATimeError;
320 SendResponse(false);
321 return;
322 }
323
324 // If we're good to go, add a ref (Balanced in OnBrowsingDataRemoverDone)
325 AddRef(); 316 AddRef();
326 317
327 // Create a BrowsingDataRemover, set the current object as an observer (so 318 // Create a BrowsingDataRemover, set the current object as an observer (so
328 // that we're notified after removal) and call remove() with the arguments 319 // that we're notified after removal) and call remove() with the arguments
329 // we've generated above. We can use a raw pointer here, as the browsing data 320 // we've generated above. We can use a raw pointer here, as the browsing data
330 // remover is responsible for deleting itself once data removal is complete. 321 // remover is responsible for deleting itself once data removal is complete.
331 observer_.Add(remover); 322 observer_.Add(remover);
332 remover->RemoveAndReply( 323 remover->RemoveAndReply(
333 BrowsingDataRemover::TimeRange(remove_since_, base::Time::Max()), 324 BrowsingDataRemover::TimeRange(remove_since_, base::Time::Max()),
334 removal_mask_, origin_type_mask_, this); 325 removal_mask_, origin_type_mask_, this);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 return BrowsingDataRemover::REMOVE_SERVICE_WORKERS; 442 return BrowsingDataRemover::REMOVE_SERVICE_WORKERS;
452 } 443 }
453 444
454 int BrowsingDataRemoveCacheStorageFunction::GetRemovalMask() { 445 int BrowsingDataRemoveCacheStorageFunction::GetRemovalMask() {
455 return BrowsingDataRemover::REMOVE_CACHE_STORAGE; 446 return BrowsingDataRemover::REMOVE_CACHE_STORAGE;
456 } 447 }
457 448
458 int BrowsingDataRemoveWebSQLFunction::GetRemovalMask() { 449 int BrowsingDataRemoveWebSQLFunction::GetRemovalMask() {
459 return BrowsingDataRemover::REMOVE_WEBSQL; 450 return BrowsingDataRemover::REMOVE_WEBSQL;
460 } 451 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698