diff options
author | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-16 11:33:34 +0000 |
---|---|---|
committer | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-16 11:33:34 +0000 |
commit | 7c983cc803a9b4a9ada8a43c3091a0bf6be78418 (patch) | |
tree | f08bc4a1a7362ca10b5e7b09f9c6e0f0e3916d95 /chrome/browser/automation/automation_provider_observers.cc | |
parent | e530c20f8b745f9771559b04022d5e98039e3666 (diff) | |
download | chromium_src-7c983cc803a9b4a9ada8a43c3091a0bf6be78418.zip chromium_src-7c983cc803a9b4a9ada8a43c3091a0bf6be78418.tar.gz chromium_src-7c983cc803a9b4a9ada8a43c3091a0bf6be78418.tar.bz2 |
(Reland reverted r52628 after fix)
Refactor json automation interface for pyauto hooks.
Reduces the number of lines you need to add per new automation hook. Shaves
off several lines of code.
Refactor pyauto.py to obviate raising exception in case the json interfaces produces an error string.
Review URL: http://codereview.chromium.org/2898001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52649 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation/automation_provider_observers.cc')
-rw-r--r-- | chrome/browser/automation/automation_provider_observers.cc | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc index 0076047..0745a90 100644 --- a/chrome/browser/automation/automation_provider_observers.cc +++ b/chrome/browser/automation/automation_provider_observers.cc @@ -9,6 +9,7 @@ #include "base/string_util.h" #include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/automation/automation_provider.h" +#include "chrome/browser/automation/automation_provider_json.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/dom_operation_notification_details.h" #include "chrome/browser/download/save_package.h" @@ -974,9 +975,7 @@ void AutomationProviderDownloadItemObserver::OnDownloadFileCompleted( DownloadItem* download) { download->RemoveObserver(this); if (--downloads_ == 0) { - AutomationMsg_SendJSONRequest::WriteReplyParams( - reply_message_, std::string("{}"), true); - provider_->Send(reply_message_); + AutomationJSONReply(provider_, reply_message_).SendSuccess(NULL); delete this; } } @@ -984,8 +983,6 @@ void AutomationProviderDownloadItemObserver::OnDownloadFileCompleted( void AutomationProviderHistoryObserver::HistoryQueryComplete( HistoryService::Handle request_handle, history::QueryResults* results) { - std::string json_return; - bool reply_return = true; scoped_ptr<DictionaryValue> return_value(new DictionaryValue); ListValue* history_list = new ListValue; @@ -1005,26 +1002,20 @@ void AutomationProviderHistoryObserver::HistoryQueryComplete( return_value->Set(L"history", history_list); // Return history info. - base::JSONWriter::Write(return_value.get(), false, &json_return); - AutomationMsg_SendJSONRequest::WriteReplyParams( - reply_message_, json_return, reply_return); - provider_->Send(reply_message_); + AutomationJSONReply reply(provider_, reply_message_); + reply.SendSuccess(return_value.get()); delete this; } void AutomationProviderImportSettingsObserver::ImportEnded() { // Send back an empty success message. - AutomationMsg_SendJSONRequest::WriteReplyParams( - reply_message_, std::string("{}"), true); - provider_->Send(reply_message_); + AutomationJSONReply(provider_, reply_message_).SendSuccess(NULL); delete this; } void AutomationProviderBrowsingDataObserver::OnBrowsingDataRemoverDone() { // Send back an empty success message - AutomationMsg_SendJSONRequest::WriteReplyParams( - reply_message_, std::string("{}"), true); - provider_->Send(reply_message_); + AutomationJSONReply(provider_, reply_message_).SendSuccess(NULL); delete this; } @@ -1051,9 +1042,7 @@ void OmniboxAcceptNotificationObserver::Observe( const NotificationDetails& details) { if (type == NotificationType::LOAD_STOP || type == NotificationType::AUTH_NEEDED) { - AutomationMsg_SendJSONRequest::WriteReplyParams( - reply_message_, std::string("{}"), false); - automation_->Send(reply_message_); + AutomationJSONReply(automation_, reply_message_).SendSuccess(NULL); delete this; } else { NOTREACHED(); @@ -1075,9 +1064,7 @@ void SavePackageNotificationObserver::Observe( const NotificationSource& source, const NotificationDetails& details) { if (type == NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED) { - AutomationMsg_SendJSONRequest::WriteReplyParams( - reply_message_, std::string("{}"), true); - automation_->Send(reply_message_); + AutomationJSONReply(automation_, reply_message_).SendSuccess(NULL); delete this; } else { NOTREACHED(); |