summaryrefslogtreecommitdiffstats
path: root/chrome/browser/automation
diff options
context:
space:
mode:
authoralyssad@chromium.org <alyssad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-14 21:14:19 +0000
committeralyssad@chromium.org <alyssad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-14 21:14:19 +0000
commita0fc50d70d4f98debbc99c312cec44c3eff5bed5 (patch)
tree6401bbf0c6745dc2beaae8173e381012d3125c70 /chrome/browser/automation
parentf0d47ac8879f6f26df2c35a3e78528f0ee4dce05 (diff)
downloadchromium_src-a0fc50d70d4f98debbc99c312cec44c3eff5bed5.zip
chromium_src-a0fc50d70d4f98debbc99c312cec44c3eff5bed5.tar.gz
chromium_src-a0fc50d70d4f98debbc99c312cec44c3eff5bed5.tar.bz2
Clear Browsing Data hook added and some small tests. BUG=36176
Review URL: http://codereview.chromium.org/2909005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52402 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation')
-rw-r--r--chrome/browser/automation/automation_provider.cc74
-rw-r--r--chrome/browser/automation/automation_provider.h7
-rw-r--r--chrome/browser/automation/automation_provider_observers.cc8
-rw-r--r--chrome/browser/automation/automation_provider_observers.h17
4 files changed, 106 insertions, 0 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index efca124..95b524f 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -2349,6 +2349,78 @@ void AutomationProvider::SaveTabContents(Browser* browser,
Send(reply_message);
}
+// Refer to ClearBrowsingData() in chrome/test/pyautolib/pyauto.py for sample
+// json input.
+// Sample json output: {}
+void AutomationProvider::ClearBrowsingData(Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ std::string json_return = "{}";
+
+ std::map<std::string, BrowsingDataRemover::TimePeriod> string_to_time_period;
+ string_to_time_period["LAST_HOUR"] = BrowsingDataRemover::LAST_HOUR;
+ string_to_time_period["LAST_DAY"] = BrowsingDataRemover::LAST_DAY;
+ string_to_time_period["LAST_WEEK"] = BrowsingDataRemover::LAST_WEEK;
+ string_to_time_period["FOUR_WEEKS"] = BrowsingDataRemover::FOUR_WEEKS;
+ string_to_time_period["EVERYTHING"] = BrowsingDataRemover::EVERYTHING;
+
+ std::map<std::string, int> string_to_mask_value;
+ string_to_mask_value["HISTORY"] = BrowsingDataRemover::REMOVE_HISTORY;
+ string_to_mask_value["DOWNLOADS"] = BrowsingDataRemover::REMOVE_DOWNLOADS;
+ string_to_mask_value["COOKIES"] = BrowsingDataRemover::REMOVE_COOKIES;
+ string_to_mask_value["PASSWORDS"] = BrowsingDataRemover::REMOVE_PASSWORDS;
+ string_to_mask_value["FORM_DATA"] = BrowsingDataRemover::REMOVE_FORM_DATA;
+ string_to_mask_value["CACHE"] = BrowsingDataRemover::REMOVE_CACHE;
+
+ std::string time_period;
+ ListValue* to_remove;
+ if (!args->GetString(L"time_period", &time_period) ||
+ !args->GetList(L"to_remove", &to_remove)) {
+ // TODO(nirnimesh): Here and below refactor returns with pending CL.
+ std::string json_return =
+ JSONErrorString("time_period must be a string and to_remove a list.");
+ AutomationMsg_SendJSONRequest::WriteReplyParams(
+ reply_message, json_return, false);
+ Send(reply_message);
+ return;
+ }
+
+ int remove_mask = 0;
+ int num_removals = to_remove->GetSize();
+ for (int i = 0; i < num_removals; i++) {
+ std::string removal;
+ to_remove->GetString(i, &removal);
+ // If the provided string is not part of the map, then error out.
+ if (!ContainsKey(string_to_mask_value, removal)) {
+ std::string json_return =
+ JSONErrorString("Invalid browsing data string found in to_remove.");
+ AutomationMsg_SendJSONRequest::WriteReplyParams(
+ reply_message, json_return, false);
+ Send(reply_message);
+ return;
+ }
+ remove_mask |= string_to_mask_value[removal];
+ }
+
+ if (!ContainsKey(string_to_time_period, time_period)) {
+ std::string json_return =
+ JSONErrorString("Invalid string for time_period.");
+ AutomationMsg_SendJSONRequest::WriteReplyParams(
+ reply_message, json_return, false);
+ Send(reply_message);
+ return;
+ }
+
+ BrowsingDataRemover* remover = new BrowsingDataRemover(
+ profile(), string_to_time_period[time_period], base::Time());
+
+ remover->AddObserver(
+ new AutomationProviderBrowsingDataObserver(this, reply_message));
+ remover->Remove(remove_mask);
+ // BrowsingDataRemover deletes itself using DeleteTask.
+ // The observer also deletes itself after sending the reply.
+}
+
// Sample json input: { "command": "GetThemeInfo" }
// Refer GetThemeInfo() in chrome/test/pyautolib/pyauto.py for sample output.
void AutomationProvider::GetThemeInfo(Browser* browser,
@@ -2700,6 +2772,8 @@ void AutomationProvider::SendJSONRequest(int handle,
handler_map["SaveTabContents"] = &AutomationProvider::SaveTabContents;
+ handler_map["ClearBrowsingData"] = &AutomationProvider::ClearBrowsingData;
+
// SetTheme() implemented using InstallExtension().
handler_map["GetThemeInfo"] = &AutomationProvider::GetThemeInfo;
diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h
index c55e04c..b4782c3 100644
--- a/chrome/browser/automation/automation_provider.h
+++ b/chrome/browser/automation/automation_provider.h
@@ -441,6 +441,13 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
DictionaryValue* args,
IPC::Message* reply_message);
+ // Clear the specified browsing data. This call provides similar
+ // functionality to RemoveBrowsingData but is synchronous.
+ // Uses the JSON interface for input/output.
+ void ClearBrowsingData(Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message);
+
// Get info about theme.
// Uses the JSON interface for input/output.
void GetThemeInfo(Browser* browser,
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc
index 0b7f0af..a8c441d 100644
--- a/chrome/browser/automation/automation_provider_observers.cc
+++ b/chrome/browser/automation/automation_provider_observers.cc
@@ -1012,6 +1012,14 @@ void AutomationProviderHistoryObserver::HistoryQueryComplete(
delete this;
}
+void AutomationProviderBrowsingDataObserver::OnBrowsingDataRemoverDone() {
+ // Send back an empty success message
+ AutomationMsg_SendJSONRequest::WriteReplyParams(
+ reply_message_, std::string("{}"), true);
+ provider_->Send(reply_message_);
+ delete this;
+}
+
OmniboxAcceptNotificationObserver::OmniboxAcceptNotificationObserver(
NavigationController* controller,
AutomationProvider* automation,
diff --git a/chrome/browser/automation/automation_provider_observers.h b/chrome/browser/automation/automation_provider_observers.h
index fbe8c15..72147c6 100644
--- a/chrome/browser/automation/automation_provider_observers.h
+++ b/chrome/browser/automation/automation_provider_observers.h
@@ -10,6 +10,7 @@
#include <set>
#include "chrome/browser/bookmarks/bookmark_model_observer.h"
+#include "chrome/browser/browsing_data_remover.h"
#include "chrome/browser/download/download_manager.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
@@ -611,6 +612,22 @@ class AutomationProviderHistoryObserver {
IPC::Message* reply_message_;
};
+// Allows the automation provider to wait for clearing browser data to finish.
+class AutomationProviderBrowsingDataObserver :
+ public BrowsingDataRemover::Observer {
+ public:
+ AutomationProviderBrowsingDataObserver(
+ AutomationProvider* provider,
+ IPC::Message* reply_message)
+ : provider_(provider),
+ reply_message_(reply_message) {}
+ void OnBrowsingDataRemoverDone();
+
+ private:
+ AutomationProvider* provider_;
+ IPC::Message* reply_message_;
+};
+
// Allows automation provider to wait until page load after selecting an item
// in the omnibox popup.
class OmniboxAcceptNotificationObserver : public NotificationObserver {