Index: chrome/browser/extensions/extension_clear_api.cc |
diff --git a/chrome/browser/extensions/extension_clear_api.cc b/chrome/browser/extensions/extension_clear_api.cc |
index 71a6bb1479d5e57c168bd4fc62494193f9406d5b..a5225096b7587a294c92f392b8c8cff69f91c917 100644 |
--- a/chrome/browser/extensions/extension_clear_api.cc |
+++ b/chrome/browser/extensions/extension_clear_api.cc |
@@ -12,7 +12,6 @@ |
#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" |
@@ -23,28 +22,31 @@ |
using content::BrowserThread; |
-namespace keys = extension_clear_api_constants; |
+namespace extension_clear_api_constants { |
-namespace { |
+// 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"; |
-// 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; |
+// Errors! |
+const char kOneAtATimeError[] = "Only one 'clear' API call can run at a time."; |
+} // 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; |
} |
@@ -62,21 +64,30 @@ bool DataRemovalRequested(base::DictionaryValue* dict, std::string key) { |
// appropriate removal mask for the BrowsingDataRemover object. |
int ParseRemovalMask(base::DictionaryValue* value) { |
int GetRemovalMask = 0; |
- if (DataRemovalRequested(value, keys::kCacheKey)) |
+ if (DataRemovalRequested(value, extension_clear_api_constants::kAppCacheKey)) |
+ GetRemovalMask |= BrowsingDataRemover::REMOVE_APPCACHE; |
+ if (DataRemovalRequested(value, extension_clear_api_constants::kCacheKey)) |
GetRemovalMask |= BrowsingDataRemover::REMOVE_CACHE; |
- if (DataRemovalRequested(value, keys::kDownloadsKey)) |
+ if (DataRemovalRequested(value, extension_clear_api_constants::kCookiesKey)) |
+ GetRemovalMask |= BrowsingDataRemover::REMOVE_COOKIES; |
+ if (DataRemovalRequested(value, extension_clear_api_constants::kDownloadsKey)) |
GetRemovalMask |= BrowsingDataRemover::REMOVE_DOWNLOADS; |
- if (DataRemovalRequested(value, keys::kFormDataKey)) |
+ if (DataRemovalRequested(value, extension_clear_api_constants::kPasswordsKey)) |
+ GetRemovalMask |= BrowsingDataRemover::REMOVE_FILE_SYSTEMS; |
+ if (DataRemovalRequested(value, extension_clear_api_constants::kFormDataKey)) |
GetRemovalMask |= BrowsingDataRemover::REMOVE_FORM_DATA; |
- if (DataRemovalRequested(value, keys::kHistoryKey)) |
+ if (DataRemovalRequested(value, extension_clear_api_constants::kHistoryKey)) |
GetRemovalMask |= BrowsingDataRemover::REMOVE_HISTORY; |
- if (DataRemovalRequested(value, keys::kPasswordsKey)) |
+ 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)) |
GetRemovalMask |= BrowsingDataRemover::REMOVE_PASSWORDS; |
- |
- // 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; |
+ if (DataRemovalRequested(value, extension_clear_api_constants::kPasswordsKey)) |
+ GetRemovalMask |= BrowsingDataRemover::REMOVE_WEBSQL; |
return GetRemovalMask; |
} |
@@ -92,14 +103,19 @@ void BrowsingDataExtensionFunction::OnBrowsingDataRemoverDone() { |
bool BrowsingDataExtensionFunction::RunImpl() { |
if (BrowsingDataRemover::is_removing()) { |
- error_ = keys::kOneAtATimeError; |
+ error_ = extension_clear_api_constants::kOneAtATimeError; |
return false; |
} |
- // Parse the |timeframe| argument to generate the TimePeriod. |
- std::string timeframe; |
- EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &timeframe)); |
- EXTENSION_FUNCTION_VALIDATE(ParseTimePeriod(timeframe, &period_)); |
+ 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); |
removal_mask_ = GetRemovalMask(); |
@@ -140,7 +156,7 @@ void BrowsingDataExtensionFunction::StartRemoving() { |
// 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(), period_, base::Time::Now()); |
+ GetCurrentBrowser()->profile(), remove_since_, base::Time::Now()); |
remover->AddObserver(this); |
remover->Remove(removal_mask_); |
} |
@@ -154,18 +170,26 @@ int ClearBrowsingDataFunction::GetRemovalMask() const { |
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_SITE_DATA; |
+ return BrowsingDataRemover::REMOVE_COOKIES; |
} |
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; |
} |
@@ -174,6 +198,22 @@ int ClearHistoryFunction::GetRemovalMask() const { |
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_CACHE; |
+ return BrowsingDataRemover::REMOVE_PASSWORDS; |
+} |
+ |
+int ClearWebSQLFunction::GetRemovalMask() const { |
+ return BrowsingDataRemover::REMOVE_WEBSQL; |
} |