| Index: chrome/browser/extensions/extension_clear_api.cc
|
| ===================================================================
|
| --- chrome/browser/extensions/extension_clear_api.cc (revision 114618)
|
| +++ chrome/browser/extensions/extension_clear_api.cc (working copy)
|
| @@ -12,6 +12,7 @@
|
|
|
| #include "base/values.h"
|
| #include "chrome/browser/browsing_data_remover.h"
|
| +#include "chrome/browser/extensions/extension_clear_api_constants.h"
|
| #include "chrome/browser/plugin_data_remover_helper.h"
|
| #include "chrome/browser/plugin_prefs.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| @@ -22,31 +23,28 @@
|
|
|
| using content::BrowserThread;
|
|
|
| -namespace extension_clear_api_constants {
|
| +namespace keys = extension_clear_api_constants;
|
|
|
| -// Keys.
|
| -const char kAppCacheKey[] = "appcache";
|
| -const char kCacheKey[] = "cache";
|
| -const char kCookiesKey[] = "cookies";
|
| -const char kDownloadsKey[] = "downloads";
|
| -const char kFileSystemsKey[] = "fileSystems";
|
| -const char kFormDataKey[] = "formData";
|
| -const char kHistoryKey[] = "history";
|
| -const char kIndexedDBKey[] = "indexedDB";
|
| -const char kPluginDataKey[] = "pluginData";
|
| -const char kLocalStorageKey[] = "localStorage";
|
| -const char kPasswordsKey[] = "passwords";
|
| -const char kWebSQLKey[] = "webSQL";
|
| +namespace {
|
|
|
| -// Errors!
|
| -const char kOneAtATimeError[] = "Only one 'clear' API call can run at a time.";
|
| +// Converts the JavaScript API's string input ("last_week") into the
|
| +// appropriate BrowsingDataRemover::TimePeriod (in this case,
|
| +// BrowsingDataRemover::LAST_WEEK).
|
| +bool ParseTimePeriod(const std::string& parse,
|
| + BrowsingDataRemover::TimePeriod* period) {
|
| + if (parse == keys::kHourEnum)
|
| + *period = BrowsingDataRemover::LAST_HOUR;
|
| + else if (parse == keys::kDayEnum)
|
| + *period = BrowsingDataRemover::LAST_DAY;
|
| + else if (parse == keys::kWeekEnum)
|
| + *period = BrowsingDataRemover::LAST_WEEK;
|
| + else if (parse == keys::kMonthEnum)
|
| + *period = BrowsingDataRemover::FOUR_WEEKS;
|
| + else if (parse == keys::kEverythingEnum)
|
| + *period = BrowsingDataRemover::EVERYTHING;
|
| + else
|
| + return false;
|
|
|
| -} // namespace extension_clear_api_constants
|
| -
|
| -namespace {
|
| -// Converts the JavaScript API's numeric input (miliseconds since epoch) into an
|
| -// appropriate base::Time that we can pass into the BrowsingDataRemove.
|
| -bool ParseTimeFromValue(const double& ms_since_epoch, base::Time* time) {
|
| return true;
|
| }
|
|
|
| @@ -64,31 +62,22 @@
|
| // appropriate removal mask for the BrowsingDataRemover object.
|
| int ParseRemovalMask(base::DictionaryValue* value) {
|
| int GetRemovalMask = 0;
|
| - if (DataRemovalRequested(value, extension_clear_api_constants::kAppCacheKey))
|
| - GetRemovalMask |= BrowsingDataRemover::REMOVE_APPCACHE;
|
| - if (DataRemovalRequested(value, extension_clear_api_constants::kCacheKey))
|
| + if (DataRemovalRequested(value, keys::kCacheKey))
|
| GetRemovalMask |= BrowsingDataRemover::REMOVE_CACHE;
|
| - if (DataRemovalRequested(value, extension_clear_api_constants::kCookiesKey))
|
| - GetRemovalMask |= BrowsingDataRemover::REMOVE_COOKIES;
|
| - if (DataRemovalRequested(value, extension_clear_api_constants::kDownloadsKey))
|
| + if (DataRemovalRequested(value, keys::kDownloadsKey))
|
| GetRemovalMask |= BrowsingDataRemover::REMOVE_DOWNLOADS;
|
| - if (DataRemovalRequested(value, extension_clear_api_constants::kPasswordsKey))
|
| - GetRemovalMask |= BrowsingDataRemover::REMOVE_FILE_SYSTEMS;
|
| - if (DataRemovalRequested(value, extension_clear_api_constants::kFormDataKey))
|
| + if (DataRemovalRequested(value, keys::kFormDataKey))
|
| GetRemovalMask |= BrowsingDataRemover::REMOVE_FORM_DATA;
|
| - if (DataRemovalRequested(value, extension_clear_api_constants::kHistoryKey))
|
| + if (DataRemovalRequested(value, keys::kHistoryKey))
|
| GetRemovalMask |= BrowsingDataRemover::REMOVE_HISTORY;
|
| - if (DataRemovalRequested(value, extension_clear_api_constants::kPasswordsKey))
|
| - GetRemovalMask |= BrowsingDataRemover::REMOVE_INDEXEDDB;
|
| - if (DataRemovalRequested(value, extension_clear_api_constants::kPasswordsKey))
|
| - GetRemovalMask |= BrowsingDataRemover::REMOVE_LOCAL_STORAGE;
|
| - if (DataRemovalRequested(value, extension_clear_api_constants::kPasswordsKey))
|
| - GetRemovalMask |= BrowsingDataRemover::REMOVE_PLUGIN_DATA;
|
| - if (DataRemovalRequested(value, extension_clear_api_constants::kPasswordsKey))
|
| + if (DataRemovalRequested(value, keys::kPasswordsKey))
|
| GetRemovalMask |= BrowsingDataRemover::REMOVE_PASSWORDS;
|
| - if (DataRemovalRequested(value, extension_clear_api_constants::kPasswordsKey))
|
| - GetRemovalMask |= BrowsingDataRemover::REMOVE_WEBSQL;
|
|
|
| + // When we talk users about "cookies", we mean not just cookies, but pretty
|
| + // much everything associated with an origin.
|
| + if (DataRemovalRequested(value, keys::kCookiesKey))
|
| + GetRemovalMask |= BrowsingDataRemover::REMOVE_SITE_DATA;
|
| +
|
| return GetRemovalMask;
|
| }
|
|
|
| @@ -103,19 +92,14 @@
|
|
|
| bool BrowsingDataExtensionFunction::RunImpl() {
|
| if (BrowsingDataRemover::is_removing()) {
|
| - error_ = extension_clear_api_constants::kOneAtATimeError;
|
| + error_ = keys::kOneAtATimeError;
|
| return false;
|
| }
|
|
|
| - double ms_since_epoch;
|
| - EXTENSION_FUNCTION_VALIDATE(args_->GetDouble(0, &ms_since_epoch));
|
| - // base::Time takes a double that represents seconds since epoch. JavaScript
|
| - // gives developers milliseconds, so do a quick conversion before populating
|
| - // the object. Also, Time::FromDoubleT converts double time 0 to empty Time
|
| - // object. So we need to do special handling here.
|
| - remove_since_ = (ms_since_epoch == 0) ?
|
| - base::Time::UnixEpoch() :
|
| - base::Time::FromDoubleT(ms_since_epoch / 1000.0);
|
| + // Parse the |timeframe| argument to generate the TimePeriod.
|
| + std::string timeframe;
|
| + EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &timeframe));
|
| + EXTENSION_FUNCTION_VALIDATE(ParseTimePeriod(timeframe, &period_));
|
|
|
| removal_mask_ = GetRemovalMask();
|
|
|
| @@ -156,7 +140,7 @@
|
| // we've generated above. We can use a raw pointer here, as the browsing data
|
| // remover is responsible for deleting itself once data removal is complete.
|
| BrowsingDataRemover* remover = new BrowsingDataRemover(
|
| - GetCurrentBrowser()->profile(), remove_since_, base::Time::Now());
|
| + GetCurrentBrowser()->profile(), period_, base::Time::Now());
|
| remover->AddObserver(this);
|
| remover->Remove(removal_mask_);
|
| }
|
| @@ -170,26 +154,18 @@
|
| return 0;
|
| }
|
|
|
| -int ClearAppCacheFunction::GetRemovalMask() const {
|
| - return BrowsingDataRemover::REMOVE_APPCACHE;
|
| -}
|
| -
|
| int ClearCacheFunction::GetRemovalMask() const {
|
| return BrowsingDataRemover::REMOVE_CACHE;
|
| }
|
|
|
| int ClearCookiesFunction::GetRemovalMask() const {
|
| - return BrowsingDataRemover::REMOVE_COOKIES;
|
| + return BrowsingDataRemover::REMOVE_SITE_DATA;
|
| }
|
|
|
| int ClearDownloadsFunction::GetRemovalMask() const {
|
| return BrowsingDataRemover::REMOVE_DOWNLOADS;
|
| }
|
|
|
| -int ClearFileSystemsFunction::GetRemovalMask() const {
|
| - return BrowsingDataRemover::REMOVE_FILE_SYSTEMS;
|
| -}
|
| -
|
| int ClearFormDataFunction::GetRemovalMask() const {
|
| return BrowsingDataRemover::REMOVE_FORM_DATA;
|
| }
|
| @@ -198,22 +174,6 @@
|
| return BrowsingDataRemover::REMOVE_HISTORY;
|
| }
|
|
|
| -int ClearIndexedDBFunction::GetRemovalMask() const {
|
| - return BrowsingDataRemover::REMOVE_INDEXEDDB;
|
| -}
|
| -
|
| -int ClearLocalStorageFunction::GetRemovalMask() const {
|
| - return BrowsingDataRemover::REMOVE_LOCAL_STORAGE;
|
| -}
|
| -
|
| -int ClearPluginDataFunction::GetRemovalMask() const {
|
| - return BrowsingDataRemover::REMOVE_PLUGIN_DATA;
|
| -}
|
| -
|
| int ClearPasswordsFunction::GetRemovalMask() const {
|
| - return BrowsingDataRemover::REMOVE_PASSWORDS;
|
| + return BrowsingDataRemover::REMOVE_CACHE;
|
| }
|
| -
|
| -int ClearWebSQLFunction::GetRemovalMask() const {
|
| - return BrowsingDataRemover::REMOVE_WEBSQL;
|
| -}
|
|
|