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

Side by Side Diff: chrome/browser/extensions/extension_clear_api.cc

Issue 8223004: Check whether clearing LSO data is supported in clients of the BrowsingDataRemover. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix unit test Created 9 years, 2 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 Clear API functions, which entail 5 // Defines the Chrome Extensions Clear 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 7 // honest, are the same thing), as specified in
8 // chrome/common/extensions/api/extension_api.json. 8 // chrome/common/extensions/api/extension_api.json.
9 9
10 #include "chrome/browser/extensions/extension_clear_api.h" 10 #include "chrome/browser/extensions/extension_clear_api.h"
11 11
12 #include <string> 12 #include <string>
13 13
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/browsing_data_remover.h" 15 #include "chrome/browser/browsing_data_remover.h"
16 #include "chrome/browser/extensions/extension_clear_api_constants.h" 16 #include "chrome/browser/extensions/extension_clear_api_constants.h"
17 #include "chrome/browser/plugin_data_remover.h"
18 #include "chrome/browser/plugin_prefs.h"
17 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/browser_list.h" 20 #include "chrome/browser/ui/browser_list.h"
19 #include "chrome/common/extensions/extension.h" 21 #include "chrome/common/extensions/extension.h"
20 #include "chrome/common/extensions/extension_error_utils.h" 22 #include "chrome/common/extensions/extension_error_utils.h"
21 #include "content/browser/browser_thread.h" 23 #include "content/browser/browser_thread.h"
22 24
23 namespace keys = extension_clear_api_constants; 25 namespace keys = extension_clear_api_constants;
24 26
25 namespace { 27 namespace {
26 28
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 90 }
89 91
90 bool BrowsingDataExtensionFunction::RunImpl() { 92 bool BrowsingDataExtensionFunction::RunImpl() {
91 if (BrowsingDataRemover::is_removing()) { 93 if (BrowsingDataRemover::is_removing()) {
92 error_ = keys::kOneAtATimeError; 94 error_ = keys::kOneAtATimeError;
93 return false; 95 return false;
94 } 96 }
95 97
96 // Parse the |timeframe| argument to generate the TimePeriod. 98 // Parse the |timeframe| argument to generate the TimePeriod.
97 std::string timeframe; 99 std::string timeframe;
98 BrowsingDataRemover::TimePeriod period;
99 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &timeframe)); 100 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &timeframe));
100 EXTENSION_FUNCTION_VALIDATE(ParseTimePeriod(timeframe, &period)); 101 EXTENSION_FUNCTION_VALIDATE(ParseTimePeriod(timeframe, &period_));
101 102
103 removal_mask_ = GetRemovalMask();
104
105 if (removal_mask_ & BrowsingDataRemover::REMOVE_LSO_DATA) {
106 // If we're being asked to remove LSO data, check whether it's actually
107 // supported.
108 Profile* profile = GetCurrentBrowser()->profile();
109 BrowserThread::PostTask(
110 BrowserThread::FILE, FROM_HERE,
111 base::Bind(
112 &BrowsingDataExtensionFunction::CheckRemovingLSODataSupported,
113 this,
114 make_scoped_refptr(PluginPrefs::GetForProfile(profile))));
115 } else {
116 StartRemoving();
117 }
118
119 // Will finish asynchronously.
120 return true;
121 }
122
123 void BrowsingDataExtensionFunction::CheckRemovingLSODataSupported(
124 scoped_refptr<PluginPrefs> plugin_prefs) {
125 if (!PluginDataRemover::IsSupported(plugin_prefs))
126 removal_mask_ &= ~BrowsingDataRemover::REMOVE_LSO_DATA;
127
128 BrowserThread::PostTask(
129 BrowserThread::UI, FROM_HERE,
130 base::Bind(&BrowsingDataExtensionFunction::StartRemoving, this));
131 }
132
133 void BrowsingDataExtensionFunction::StartRemoving() {
102 // If we're good to go, add a ref (Balanced in OnBrowsingDataRemoverDone) 134 // If we're good to go, add a ref (Balanced in OnBrowsingDataRemoverDone)
103 AddRef(); 135 AddRef();
104 136
105 // Create a BrowsingDataRemover, set the current object as an observer (so 137 // Create a BrowsingDataRemover, set the current object as an observer (so
106 // that we're notified after removal) and call remove() with the arguments 138 // that we're notified after removal) and call remove() with the arguments
107 // we've generated above. We can use a raw pointer here, as the browsing data 139 // we've generated above. We can use a raw pointer here, as the browsing data
108 // remover is responsible for deleting itself once data removal is complete. 140 // remover is responsible for deleting itself once data removal is complete.
109 BrowsingDataRemover* remover = new BrowsingDataRemover( 141 BrowsingDataRemover* remover = new BrowsingDataRemover(
110 GetCurrentBrowser()->profile(), period, base::Time::Now()); 142 GetCurrentBrowser()->profile(), period_, base::Time::Now());
111 remover->AddObserver(this); 143 remover->AddObserver(this);
112 remover->Remove(GetRemovalMask()); 144 remover->Remove(removal_mask_);
113
114 // Will finish asynchronously.
115 return true;
116 } 145 }
117 146
118 int ClearBrowsingDataFunction::GetRemovalMask() const { 147 int ClearBrowsingDataFunction::GetRemovalMask() const {
119 // Parse the |dataToRemove| argument to generate the removal mask. 148 // Parse the |dataToRemove| argument to generate the removal mask.
120 base::DictionaryValue* data_to_remove; 149 base::DictionaryValue* data_to_remove;
121 if (args_->GetDictionary(1, &data_to_remove)) 150 if (args_->GetDictionary(1, &data_to_remove))
122 return ParseRemovalMask(data_to_remove); 151 return ParseRemovalMask(data_to_remove);
123 else 152 else
124 return 0; 153 return 0;
125 } 154 }
(...skipping 14 matching lines...) Expand all
140 return BrowsingDataRemover::REMOVE_FORM_DATA; 169 return BrowsingDataRemover::REMOVE_FORM_DATA;
141 } 170 }
142 171
143 int ClearHistoryFunction::GetRemovalMask() const { 172 int ClearHistoryFunction::GetRemovalMask() const {
144 return BrowsingDataRemover::REMOVE_HISTORY; 173 return BrowsingDataRemover::REMOVE_HISTORY;
145 } 174 }
146 175
147 int ClearPasswordsFunction::GetRemovalMask() const { 176 int ClearPasswordsFunction::GetRemovalMask() const {
148 return BrowsingDataRemover::REMOVE_CACHE; 177 return BrowsingDataRemover::REMOVE_CACHE;
149 } 178 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_clear_api.h ('k') | chrome/browser/ui/webui/options/clear_browser_data_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698