Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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) { | |
|
Mike West
2011/10/10 18:41:11
I think taking the one's complement here is backwa
Bernhard Bauer
2011/10/11 13:52:58
Indeed, that was a copy-and-paste from below :) Th
| |
| 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; | |
|
Mike West
2011/10/10 18:50:23
XOR might be clearer? I had to think about what th
Bernhard Bauer
2011/10/11 13:52:58
I think a bitwise "and" is the usual way to flip a
| |
| 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 Loading... | |
| 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 } |
| OLD | NEW |