diff options
author | dtu@chromium.org <dtu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-04 21:05:27 +0000 |
---|---|---|
committer | dtu@chromium.org <dtu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-04 21:05:27 +0000 |
commit | 7457cb3cfe3272ca84c854a8713a7ff1ca61025b (patch) | |
tree | 976d4b692249e06cd7aafe6b4bd6f8e02b25df25 /chrome/browser | |
parent | 14bb336e4be8a0e230950c068ce66db41105ba76 (diff) | |
download | chromium_src-7457cb3cfe3272ca84c854a8713a7ff1ca61025b.zip chromium_src-7457cb3cfe3272ca84c854a8713a7ff1ca61025b.tar.gz chromium_src-7457cb3cfe3272ca84c854a8713a7ff1ca61025b.tar.bz2 |
Refactor: Make PyAuto InstallExtension() take a string. Delete dead code.
BUG=chromium:86890
TEST=Run the modified PyAuto tests on all platforms.
Review URL: http://codereview.chromium.org/7548024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95490 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
4 files changed, 15 insertions, 122 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 1dfa293..6f9472e 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -325,13 +325,10 @@ bool AutomationProvider::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(AutomationMsg_ReloadAsync, ReloadAsync) IPC_MESSAGE_HANDLER(AutomationMsg_StopAsync, StopAsync) IPC_MESSAGE_HANDLER(AutomationMsg_SetPageFontSize, OnSetPageFontSize) - IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_InstallExtension, - InstallExtension) IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForExtensionTestResult, WaitForExtensionTestResult) - IPC_MESSAGE_HANDLER_DELAY_REPLY( - AutomationMsg_InstallExtensionAndGetHandle, - InstallExtensionAndGetHandle) + IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_InstallExtension, + InstallExtension) IPC_MESSAGE_HANDLER(AutomationMsg_UninstallExtension, UninstallExtension) IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_EnableExtension, @@ -763,26 +760,6 @@ RenderViewHost* AutomationProvider::GetViewForTab(int tab_handle) { return NULL; } -void AutomationProvider::InstallExtension(const FilePath& crx_path, - IPC::Message* reply_message) { - ExtensionService* service = profile_->GetExtensionService(); - if (service) { - // The observer will delete itself when done. - new ExtensionInstallNotificationObserver(this, - AutomationMsg_InstallExtension::ID, - reply_message); - - // Pass NULL for a silent install with no UI. - scoped_refptr<CrxInstaller> installer(service->MakeCrxInstaller(NULL)); - installer->set_install_cause(extension_misc::INSTALL_CAUSE_AUTOMATION); - installer->InstallCrx(crx_path); - } else { - AutomationMsg_InstallExtension::WriteReplyParams( - reply_message, AUTOMATION_MSG_EXTENSION_INSTALL_FAILED); - Send(reply_message); - } -} - void AutomationProvider::WaitForExtensionTestResult( IPC::Message* reply_message) { DCHECK(!reply_message_); @@ -792,8 +769,9 @@ void AutomationProvider::WaitForExtensionTestResult( extension_test_result_observer_->MaybeSendResult(); } -void AutomationProvider::InstallExtensionAndGetHandle( - const FilePath& crx_path, bool with_ui, IPC::Message* reply_message) { +void AutomationProvider::InstallExtension( + const FilePath& extension_path, bool with_ui, + IPC::Message* reply_message) { ExtensionService* service = profile_->GetExtensionService(); ExtensionProcessManager* manager = profile_->GetExtensionProcessManager(); if (service && manager) { @@ -801,23 +779,22 @@ void AutomationProvider::InstallExtensionAndGetHandle( new ExtensionReadyNotificationObserver( manager, this, - AutomationMsg_InstallExtensionAndGetHandle::ID, + AutomationMsg_InstallExtension::ID, reply_message); - if (crx_path.MatchesExtension(FILE_PATH_LITERAL(".crx"))) { + if (extension_path.MatchesExtension(FILE_PATH_LITERAL(".crx"))) { ExtensionInstallUI* client = (with_ui ? new ExtensionInstallUI(profile_) : NULL); scoped_refptr<CrxInstaller> installer(service->MakeCrxInstaller(client)); if (!with_ui) installer->set_allow_silent_install(true); installer->set_install_cause(extension_misc::INSTALL_CAUSE_AUTOMATION); - installer->InstallCrx(crx_path); + installer->InstallCrx(extension_path); } else { - service->LoadExtension(crx_path, with_ui); + service->LoadExtension(extension_path, with_ui); } } else { - AutomationMsg_InstallExtensionAndGetHandle::WriteReplyParams( - reply_message, 0); + AutomationMsg_InstallExtension::WriteReplyParams(reply_message, 0); Send(reply_message); } } diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h index e907150..b389b88 100644 --- a/chrome/browser/automation/automation_provider.h +++ b/chrome/browser/automation/automation_provider.h @@ -250,14 +250,11 @@ class AutomationProvider // for information on the arguments. void JavaScriptStressTestControl(int handle, int cmd, int param); - void InstallExtension(const FilePath& crx_path, - IPC::Message* reply_message); - void WaitForExtensionTestResult(IPC::Message* reply_message); - void InstallExtensionAndGetHandle(const FilePath& crx_path, - bool with_ui, - IPC::Message* reply_message); + void InstallExtension(const FilePath& extension_path, + bool with_ui, + IPC::Message* reply_message); void UninstallExtension(int extension_handle, bool* success); diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc index bb5f44a..61dfc6a 100644 --- a/chrome/browser/automation/automation_provider_observers.cc +++ b/chrome/browser/automation/automation_provider_observers.cc @@ -464,61 +464,6 @@ bool DidExtensionHostsStopLoading(ExtensionProcessManager* manager) { return true; } -ExtensionInstallNotificationObserver::ExtensionInstallNotificationObserver( - AutomationProvider* automation, int id, IPC::Message* reply_message) - : automation_(automation->AsWeakPtr()), - id_(id), - reply_message_(reply_message) { - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, - NotificationService::AllSources()); - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, - NotificationService::AllSources()); - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, - NotificationService::AllSources()); -} - -ExtensionInstallNotificationObserver::~ExtensionInstallNotificationObserver() { -} - -void ExtensionInstallNotificationObserver::Observe( - int type, const NotificationSource& source, - const NotificationDetails& details) { - switch (type) { - case chrome::NOTIFICATION_EXTENSION_LOADED: - SendResponse(AUTOMATION_MSG_EXTENSION_INSTALL_SUCCEEDED); - break; - case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR: - case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: - SendResponse(AUTOMATION_MSG_EXTENSION_INSTALL_FAILED); - break; - default: - NOTREACHED(); - break; - } - - delete this; -} - -void ExtensionInstallNotificationObserver::SendResponse( - AutomationMsg_ExtensionResponseValues response) { - if (!automation_ || !reply_message_.get()) { - delete this; - return; - } - - switch (id_) { - case AutomationMsg_InstallExtension::ID: - AutomationMsg_InstallExtension::WriteReplyParams(reply_message_.get(), - response); - break; - default: - NOTREACHED(); - break; - } - - automation_->Send(reply_message_.release()); -} - ExtensionUninstallObserver::ExtensionUninstallObserver( AutomationProvider* automation, IPC::Message* reply_message, @@ -626,12 +571,12 @@ void ExtensionReadyNotificationObserver::Observe( break; } - if (id_ == AutomationMsg_InstallExtensionAndGetHandle::ID) { + if (id_ == AutomationMsg_InstallExtension::ID) { // A handle of zero indicates an error. int extension_handle = 0; if (extension_) extension_handle = automation_->AddExtension(extension_); - AutomationMsg_InstallExtensionAndGetHandle::WriteReplyParams( + AutomationMsg_InstallExtension::WriteReplyParams( reply_message_.get(), extension_handle); } else if (id_ == AutomationMsg_EnableExtension::ID) { AutomationMsg_EnableExtension::WriteReplyParams(reply_message_.get(), true); diff --git a/chrome/browser/automation/automation_provider_observers.h b/chrome/browser/automation/automation_provider_observers.h index 1a8ca9c..d4d54a6 100644 --- a/chrome/browser/automation/automation_provider_observers.h +++ b/chrome/browser/automation/automation_provider_observers.h @@ -283,32 +283,6 @@ class TabCountChangeObserver : public TabStripModelObserver { DISALLOW_COPY_AND_ASSIGN(TabCountChangeObserver); }; -// Observes when an extension has finished installing or possible install -// errors. This does not guarantee that the extension is ready for use. -class ExtensionInstallNotificationObserver : public NotificationObserver { - public: - ExtensionInstallNotificationObserver(AutomationProvider* automation, - int id, - IPC::Message* reply_message); - virtual ~ExtensionInstallNotificationObserver(); - - // Implementation of NotificationObserver. - virtual void Observe(int type, - const NotificationSource& source, - const NotificationDetails& details); - - private: - // Send |response| back to the provider's client. - void SendResponse(AutomationMsg_ExtensionResponseValues response); - - NotificationRegistrar registrar_; - base::WeakPtr<AutomationProvider> automation_; - int id_; - scoped_ptr<IPC::Message> reply_message_; - - DISALLOW_COPY_AND_ASSIGN(ExtensionInstallNotificationObserver); -}; - // Observes when an extension has been uninstalled. class ExtensionUninstallObserver : public NotificationObserver { public: |