Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 // base::Time takes a double that represents seconds since epoch. JavaScript | 137 // base::Time takes a double that represents seconds since epoch. JavaScript |
| 138 // gives developers milliseconds, so do a quick conversion before populating | 138 // gives developers milliseconds, so do a quick conversion before populating |
| 139 // the object. Also, Time::FromDoubleT converts double time 0 to empty Time | 139 // the object. Also, Time::FromDoubleT converts double time 0 to empty Time |
| 140 // object. So we need to do special handling here. | 140 // object. So we need to do special handling here. |
| 141 remove_since_ = (ms_since_epoch == 0) ? | 141 remove_since_ = (ms_since_epoch == 0) ? |
| 142 base::Time::UnixEpoch() : | 142 base::Time::UnixEpoch() : |
| 143 base::Time::FromDoubleT(ms_since_epoch / 1000.0); | 143 base::Time::FromDoubleT(ms_since_epoch / 1000.0); |
| 144 | 144 |
| 145 removal_mask_ = GetRemovalMask(); | 145 removal_mask_ = GetRemovalMask(); |
| 146 | 146 |
| 147 if (removal_mask_ & BrowsingDataRemover::REMOVE_PLUGIN_DATA) { | 147 if (removal_mask_ & BrowsingDataRemover::REMOVE_PLUGIN_DATA && profile()) { |
|
Bernhard Bauer
2012/08/08 11:46:51
I think we do have a profile at this point. I woul
| |
| 148 // If we're being asked to remove plugin data, check whether it's actually | 148 // If we're being asked to remove plugin data, check whether it's actually |
| 149 // supported. | 149 // supported. |
| 150 Profile* profile = GetCurrentBrowser()->profile(); | |
| 151 BrowserThread::PostTask( | 150 BrowserThread::PostTask( |
| 152 BrowserThread::FILE, FROM_HERE, | 151 BrowserThread::FILE, FROM_HERE, |
| 153 base::Bind( | 152 base::Bind( |
| 154 &BrowsingDataExtensionFunction::CheckRemovingPluginDataSupported, | 153 &BrowsingDataExtensionFunction::CheckRemovingPluginDataSupported, |
| 155 this, | 154 this, |
| 156 PluginPrefs::GetForProfile(profile))); | 155 PluginPrefs::GetForProfile(profile()))); |
| 157 } else { | 156 } else { |
| 158 StartRemoving(); | 157 StartRemoving(); |
| 159 } | 158 } |
| 160 | 159 |
| 161 // Will finish asynchronously. | 160 // Will finish asynchronously. |
| 162 return true; | 161 return true; |
| 163 } | 162 } |
| 164 | 163 |
| 165 void BrowsingDataExtensionFunction::CheckRemovingPluginDataSupported( | 164 void BrowsingDataExtensionFunction::CheckRemovingPluginDataSupported( |
| 166 scoped_refptr<PluginPrefs> plugin_prefs) { | 165 scoped_refptr<PluginPrefs> plugin_prefs) { |
| 167 if (!PluginDataRemoverHelper::IsSupported(plugin_prefs)) | 166 if (!PluginDataRemoverHelper::IsSupported(plugin_prefs)) |
| 168 removal_mask_ &= ~BrowsingDataRemover::REMOVE_PLUGIN_DATA; | 167 removal_mask_ &= ~BrowsingDataRemover::REMOVE_PLUGIN_DATA; |
| 169 | 168 |
| 170 BrowserThread::PostTask( | 169 BrowserThread::PostTask( |
| 171 BrowserThread::UI, FROM_HERE, | 170 BrowserThread::UI, FROM_HERE, |
| 172 base::Bind(&BrowsingDataExtensionFunction::StartRemoving, this)); | 171 base::Bind(&BrowsingDataExtensionFunction::StartRemoving, this)); |
| 173 } | 172 } |
| 174 | 173 |
| 175 void BrowsingDataExtensionFunction::StartRemoving() { | 174 void BrowsingDataExtensionFunction::StartRemoving() { |
| 176 // If we're good to go, add a ref (Balanced in OnBrowsingDataRemoverDone) | 175 // If we're good to go, add a ref (Balanced in OnBrowsingDataRemoverDone) |
| 177 AddRef(); | 176 AddRef(); |
| 178 | 177 |
| 178 // If we've got no profile, exit early. | |
| 179 if (!profile()) { | |
| 180 OnBrowsingDataRemoverDone(); | |
| 181 return; | |
| 182 } | |
| 183 | |
| 179 // Create a BrowsingDataRemover, set the current object as an observer (so | 184 // Create a BrowsingDataRemover, set the current object as an observer (so |
| 180 // that we're notified after removal) and call remove() with the arguments | 185 // 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 | 186 // 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. | 187 // remover is responsible for deleting itself once data removal is complete. |
| 183 BrowsingDataRemover* remover = new BrowsingDataRemover( | 188 BrowsingDataRemover* remover = new BrowsingDataRemover(profile(), |
| 184 GetCurrentBrowser()->profile(), remove_since_, base::Time::Now()); | 189 remove_since_, base::Time::Now()); |
| 185 remover->AddObserver(this); | 190 remover->AddObserver(this); |
| 186 remover->Remove(removal_mask_, origin_set_mask_); | 191 remover->Remove(removal_mask_, origin_set_mask_); |
| 187 } | 192 } |
| 188 | 193 |
| 189 int BrowsingDataExtensionFunction::ParseOriginSetMask( | 194 int BrowsingDataExtensionFunction::ParseOriginSetMask( |
| 190 const base::DictionaryValue& options) { | 195 const base::DictionaryValue& options) { |
| 191 // Parse the |options| dictionary to generate the origin set mask. Default to | 196 // Parse the |options| dictionary to generate the origin set mask. Default to |
| 192 // UNPROTECTED_WEB if the developer doesn't specify anything. | 197 // UNPROTECTED_WEB if the developer doesn't specify anything. |
| 193 int mask = BrowsingDataHelper::UNPROTECTED_WEB; | 198 int mask = BrowsingDataHelper::UNPROTECTED_WEB; |
| 194 | 199 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 return BrowsingDataRemover::REMOVE_PLUGIN_DATA; | 284 return BrowsingDataRemover::REMOVE_PLUGIN_DATA; |
| 280 } | 285 } |
| 281 | 286 |
| 282 int RemovePasswordsFunction::GetRemovalMask() const { | 287 int RemovePasswordsFunction::GetRemovalMask() const { |
| 283 return BrowsingDataRemover::REMOVE_PASSWORDS; | 288 return BrowsingDataRemover::REMOVE_PASSWORDS; |
| 284 } | 289 } |
| 285 | 290 |
| 286 int RemoveWebSQLFunction::GetRemovalMask() const { | 291 int RemoveWebSQLFunction::GetRemovalMask() const { |
| 287 return BrowsingDataRemover::REMOVE_WEBSQL; | 292 return BrowsingDataRemover::REMOVE_WEBSQL; |
| 288 } | 293 } |
| OLD | NEW |