diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-09 11:58:03 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-09 11:58:03 +0000 |
commit | 7d9aecf52b91b49a563b240dbf789208f713300d (patch) | |
tree | e4125387cbbce03823955642a1535b4dfb144681 /chrome/browser/automation | |
parent | 03247c83b9dc4513a3192b956ace3be2ebe5868d (diff) | |
download | chromium_src-7d9aecf52b91b49a563b240dbf789208f713300d.zip chromium_src-7d9aecf52b91b49a563b240dbf789208f713300d.tar.gz chromium_src-7d9aecf52b91b49a563b240dbf789208f713300d.tar.bz2 |
GTTF: Convert automation observers to reference AutomationProvider
via weak pointers.
This change has two objectives:
1) Avoid referencing AutomationProvider after it's destroyed.
2) Avoid extending the lifetime of AutomationProvider
if an observer is hung.
BUG=56750
TEST=none
Review URL: http://codereview.chromium.org/6410091
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74275 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation')
5 files changed, 522 insertions, 381 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index f2fe8df..461e43d 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -138,15 +138,9 @@ AutomationProvider::~AutomationProvider() { port_containers_.end()); port_containers_.clear(); - // Make sure that any outstanding NotificationObservers also get destroyed. - ObserverList<NotificationObserver>::Iterator it(notification_observer_list_); - NotificationObserver* observer; - while ((observer = it.GetNext()) != NULL) - delete observer; - - if (channel_.get()) { + if (channel_.get()) channel_->Close(); - } + g_browser_process->ReleaseModule(); } @@ -202,37 +196,6 @@ void AutomationProvider::OnInitialLoadsComplete() { Send(new AutomationMsg_InitialLoadsComplete()); } -NotificationObserver* AutomationProvider::AddNavigationStatusListener( - NavigationController* tab, IPC::Message* reply_message, - int number_of_navigations, bool include_current_navigation) { - NotificationObserver* observer = - new NavigationNotificationObserver(tab, this, reply_message, - number_of_navigations, - include_current_navigation); - - notification_observer_list_.AddObserver(observer); - return observer; -} - -void AutomationProvider::RemoveNavigationStatusListener( - NotificationObserver* obs) { - notification_observer_list_.RemoveObserver(obs); -} - -NotificationObserver* AutomationProvider::AddTabStripObserver( - Browser* parent, - IPC::Message* reply_message) { - NotificationObserver* observer = - new TabAppendedNotificationObserver(parent, this, reply_message); - notification_observer_list_.AddObserver(observer); - - return observer; -} - -void AutomationProvider::RemoveTabStripObserver(NotificationObserver* obs) { - notification_observer_list_.RemoveObserver(obs); -} - void AutomationProvider::AddLoginHandler(NavigationController* tab, LoginHandler* handler) { login_handler_map_[tab] = handler; diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h index f92eb52..3d4791d 100644 --- a/chrome/browser/automation/automation_provider.h +++ b/chrome/browser/automation/automation_provider.h @@ -21,6 +21,7 @@ #include "base/observer_list.h" #include "base/scoped_ptr.h" #include "base/string16.h" +#include "base/weak_ptr.h" #include "chrome/browser/autofill/field_types.h" #include "chrome/browser/browser_thread.h" #include "chrome/browser/cancelable_request.h" @@ -80,6 +81,7 @@ class Point; class AutomationProvider : public IPC::Channel::Listener, public IPC::Message::Sender, + public base::SupportsWeakPtr<AutomationProvider>, public base::RefCountedThreadSafe<AutomationProvider, BrowserThread::DeleteOnUIThread> { public: @@ -104,28 +106,6 @@ class AutomationProvider // Call SetExpectedTabCount(0) to set this to true immediately. void OnInitialLoadsComplete(); - // Add a listener for navigation status notification. Currently only - // navigation completion is observed; when the |number_of_navigations| - // complete, the completed_response object is sent; if the server requires - // authentication, we instead send the auth_needed_response object. A pointer - // to the added navigation observer is returned. This object should NOT be - // deleted and should be released by calling the corresponding - // RemoveNavigationStatusListener method. - NotificationObserver* AddNavigationStatusListener( - NavigationController* tab, IPC::Message* reply_message, - int number_of_navigations, bool include_current_navigation); - - void RemoveNavigationStatusListener(NotificationObserver* obs); - - // Add an observer for the TabStrip. Currently only Tab append is observed. A - // navigation listener is created on successful notification of tab append. A - // pointer to the added navigation observer is returned. This object should - // NOT be deleted and should be released by calling the corresponding - // RemoveTabStripObserver method. - NotificationObserver* AddTabStripObserver(Browser* parent, - IPC::Message* reply_message); - void RemoveTabStripObserver(NotificationObserver* obs); - // Get the index of a particular NavigationController object // in the given parent window. This method uses // TabStrip::GetIndexForNavigationController to get the index. @@ -205,9 +185,6 @@ class AutomationProvider scoped_ptr<AutomationTabTracker> tab_tracker_; scoped_ptr<AutomationWindowTracker> window_tracker_; - typedef ObserverList<NotificationObserver> NotificationObserverList; - NotificationObserverList notification_observer_list_; - typedef std::map<NavigationController*, LoginHandler*> LoginHandlerMap; LoginHandlerMap login_handler_map_; @@ -408,7 +385,6 @@ class AutomationProvider scoped_ptr<NotificationObserver> new_tab_ui_load_observer_; scoped_ptr<NotificationObserver> find_in_page_observer_; scoped_ptr<NotificationObserver> dom_operation_observer_; - scoped_ptr<NotificationObserver> dom_inspector_observer_; scoped_ptr<ExtensionTestResultNotificationObserver> extension_test_result_observer_; scoped_ptr<AutomationExtensionTracker> extension_tracker_; diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc index bd0c3ff..7855a21 100644 --- a/chrome/browser/automation/automation_provider_observers.cc +++ b/chrome/browser/automation/automation_provider_observers.cc @@ -86,7 +86,7 @@ class InitialLoadObserver::TabTime { InitialLoadObserver::InitialLoadObserver(size_t tab_count, AutomationProvider* automation) - : automation_(automation), + : automation_(automation->AsWeakPtr()), outstanding_tab_count_(tab_count), init_time_(base::TimeTicks::Now()) { if (outstanding_tab_count_ > 0) { @@ -147,11 +147,12 @@ DictionaryValue* InitialLoadObserver::GetTimingInformation() const { void InitialLoadObserver::ConditionMet() { registrar_.RemoveAll(); - automation_->OnInitialLoadsComplete(); + if (automation_) + automation_->OnInitialLoadsComplete(); } NewTabUILoadObserver::NewTabUILoadObserver(AutomationProvider* automation) - : automation_(automation) { + : automation_(automation->AsWeakPtr()) { registrar_.Add(this, NotificationType::INITIAL_NEW_TAB_UI_LOAD, NotificationService::AllSources()); } @@ -164,8 +165,10 @@ void NewTabUILoadObserver::Observe(NotificationType type, const NotificationDetails& details) { if (type == NotificationType::INITIAL_NEW_TAB_UI_LOAD) { Details<int> load_time(details); - automation_->Send( - new AutomationMsg_InitialNewTabUILoadComplete(*load_time.ptr())); + if (automation_) { + automation_->Send( + new AutomationMsg_InitialNewTabUILoadComplete(*load_time.ptr())); + } } else { NOTREACHED(); } @@ -175,7 +178,7 @@ NavigationControllerRestoredObserver::NavigationControllerRestoredObserver( AutomationProvider* automation, NavigationController* controller, IPC::Message* reply_message) - : automation_(automation), + : automation_(automation->AsWeakPtr()), controller_(controller), reply_message_(reply_message) { if (FinishedRestoring()) { @@ -204,9 +207,12 @@ bool NavigationControllerRestoredObserver::FinishedRestoring() { } void NavigationControllerRestoredObserver::SendDone() { - DCHECK(reply_message_ != NULL); - AutomationMsg_WaitForTabToBeRestored::WriteReplyParams(reply_message_, true); - automation_->Send(reply_message_); + if (!automation_) + return; + + AutomationMsg_WaitForTabToBeRestored::WriteReplyParams(reply_message_.get(), + true); + automation_->Send(reply_message_.release()); } NavigationNotificationObserver::NavigationNotificationObserver( @@ -215,11 +221,11 @@ NavigationNotificationObserver::NavigationNotificationObserver( IPC::Message* reply_message, int number_of_navigations, bool include_current_navigation) - : automation_(automation), - reply_message_(reply_message), - controller_(controller), - navigations_remaining_(number_of_navigations), - navigation_started_(false) { + : automation_(automation->AsWeakPtr()), + reply_message_(reply_message), + controller_(controller), + navigations_remaining_(number_of_navigations), + navigation_started_(false) { DCHECK_LT(0, navigations_remaining_); Source<NavigationController> source(controller_); registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, source); @@ -234,22 +240,16 @@ NavigationNotificationObserver::NavigationNotificationObserver( } NavigationNotificationObserver::~NavigationNotificationObserver() { - if (reply_message_) { - // This means we did not receive a notification for this navigation. - // Send over a failed navigation status back to the caller to ensure that - // the caller does not hang waiting for the response. - IPC::ParamTraits<AutomationMsg_NavigationResponseValues>::Write( - reply_message_, AUTOMATION_MSG_NAVIGATION_ERROR); - automation_->Send(reply_message_); - reply_message_ = NULL; - } - - automation_->RemoveNavigationStatusListener(this); } void NavigationNotificationObserver::Observe( NotificationType type, const NotificationSource& source, const NotificationDetails& details) { + if (!automation_) { + delete this; + return; + } + // We listen for 2 events to determine when the navigation started because: // - when this is used by the WaitForNavigation method, we might be invoked // afer the load has started (but not after the entry was committed, as @@ -292,19 +292,18 @@ void NavigationNotificationObserver::Observe( void NavigationNotificationObserver::ConditionMet( AutomationMsg_NavigationResponseValues navigation_result) { - DCHECK(reply_message_ != NULL); - - IPC::ParamTraits<AutomationMsg_NavigationResponseValues>::Write( - reply_message_, navigation_result); - automation_->Send(reply_message_); - reply_message_ = NULL; + if (automation_) { + IPC::ParamTraits<AutomationMsg_NavigationResponseValues>::Write( + reply_message_.get(), navigation_result); + automation_->Send(reply_message_.release()); + } delete this; } TabStripNotificationObserver::TabStripNotificationObserver( NotificationType notification, AutomationProvider* automation) - : automation_(automation), + : automation_(automation->AsWeakPtr()), notification_(notification) { registrar_.Add(this, notification_, NotificationService::AllSources()); } @@ -317,9 +316,6 @@ void TabStripNotificationObserver::Observe(NotificationType type, const NotificationDetails& details) { if (type == notification_) { ObserveTab(Source<NavigationController>(source).ptr()); - - // If verified, no need to observe anymore - automation_->RemoveTabStripObserver(this); delete this; } else { NOTREACHED(); @@ -336,14 +332,18 @@ TabAppendedNotificationObserver::TabAppendedNotificationObserver( void TabAppendedNotificationObserver::ObserveTab( NavigationController* controller) { + if (!automation_) + return; + if (automation_->GetIndexForNavigationController(controller, parent_) == TabStripModel::kNoTab) { // This tab notification doesn't belong to the parent_. return; } - automation_->AddNavigationStatusListener(controller, reply_message_, 1, - false); + new NavigationNotificationObserver(controller, automation_, + reply_message_.release(), + 1, false); } TabClosedNotificationObserver::TabClosedNotificationObserver( @@ -358,13 +358,16 @@ TabClosedNotificationObserver::TabClosedNotificationObserver( void TabClosedNotificationObserver::ObserveTab( NavigationController* controller) { + if (!automation_) + return; + if (for_browser_command_) { - AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_, + AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_.get(), true); } else { - AutomationMsg_CloseTab::WriteReplyParams(reply_message_, true); + AutomationMsg_CloseTab::WriteReplyParams(reply_message_.get(), true); } - automation_->Send(reply_message_); + automation_->Send(reply_message_.release()); } void TabClosedNotificationObserver::set_for_browser_command( @@ -376,7 +379,7 @@ TabCountChangeObserver::TabCountChangeObserver(AutomationProvider* automation, Browser* browser, IPC::Message* reply_message, int target_tab_count) - : automation_(automation), + : automation_(automation->AsWeakPtr()), reply_message_(reply_message), tab_strip_model_(browser->tabstrip_model()), target_tab_count_(target_tab_count) { @@ -400,9 +403,12 @@ void TabCountChangeObserver::TabDetachedAt(TabContentsWrapper* contents, } void TabCountChangeObserver::TabStripModelDeleted() { - AutomationMsg_WaitForTabCountToBecome::WriteReplyParams(reply_message_, - false); - automation_->Send(reply_message_); + if (automation_) { + AutomationMsg_WaitForTabCountToBecome::WriteReplyParams( + reply_message_.get(), false); + automation_->Send(reply_message_.release()); + } + delete this; } @@ -410,9 +416,12 @@ void TabCountChangeObserver::CheckTabCount() { if (tab_strip_model_->count() != target_tab_count_) return; - AutomationMsg_WaitForTabCountToBecome::WriteReplyParams(reply_message_, - true); - automation_->Send(reply_message_); + if (automation_) { + AutomationMsg_WaitForTabCountToBecome::WriteReplyParams( + reply_message_.get(), true); + automation_->Send(reply_message_.release()); + } + delete this; } @@ -427,7 +436,7 @@ bool DidExtensionHostsStopLoading(ExtensionProcessManager* manager) { ExtensionInstallNotificationObserver::ExtensionInstallNotificationObserver( AutomationProvider* automation, int id, IPC::Message* reply_message) - : automation_(automation), + : automation_(automation->AsWeakPtr()), id_(id), reply_message_(reply_message) { registrar_.Add(this, NotificationType::EXTENSION_LOADED, @@ -462,31 +471,33 @@ void ExtensionInstallNotificationObserver::Observe( void ExtensionInstallNotificationObserver::SendResponse( AutomationMsg_ExtensionResponseValues response) { - if (reply_message_ != NULL) { - switch (id_) { - case AutomationMsg_InstallExtension::ID: - AutomationMsg_InstallExtension::WriteReplyParams(reply_message_, - response); - break; - case AutomationMsg_LoadExpandedExtension::ID: - AutomationMsg_LoadExpandedExtension::WriteReplyParams(reply_message_, - response); - break; - default: - NOTREACHED(); - break; - } + if (!automation_ || !reply_message_.get()) { + delete this; + return; + } - automation_->Send(reply_message_); - reply_message_ = NULL; + switch (id_) { + case AutomationMsg_InstallExtension::ID: + AutomationMsg_InstallExtension::WriteReplyParams(reply_message_.get(), + response); + break; + case AutomationMsg_LoadExpandedExtension::ID: + AutomationMsg_LoadExpandedExtension::WriteReplyParams( + reply_message_.get(), response); + break; + default: + NOTREACHED(); + break; } + + automation_->Send(reply_message_.release()); } ExtensionReadyNotificationObserver::ExtensionReadyNotificationObserver( ExtensionProcessManager* manager, AutomationProvider* automation, int id, IPC::Message* reply_message) : manager_(manager), - automation_(automation), + automation_(automation->AsWeakPtr()), id_(id), reply_message_(reply_message), extension_(NULL) { @@ -506,6 +517,11 @@ ExtensionReadyNotificationObserver::~ExtensionReadyNotificationObserver() { void ExtensionReadyNotificationObserver::Observe( NotificationType type, const NotificationSource& source, const NotificationDetails& details) { + if (!automation_) { + delete this; + return; + } + bool success = false; switch (type.value) { case NotificationType::EXTENSION_HOST_DID_STOP_LOADING: @@ -536,15 +552,15 @@ void ExtensionReadyNotificationObserver::Observe( if (extension_) extension_handle = automation_->AddExtension(extension_); AutomationMsg_InstallExtensionAndGetHandle::WriteReplyParams( - reply_message_, extension_handle); + reply_message_.get(), extension_handle); } else if (id_ == AutomationMsg_EnableExtension::ID) { - AutomationMsg_EnableExtension::WriteReplyParams(reply_message_, true); + AutomationMsg_EnableExtension::WriteReplyParams(reply_message_.get(), true); } else { NOTREACHED(); LOG(ERROR) << "Cannot write reply params for unknown message id."; } - automation_->Send(reply_message_); + automation_->Send(reply_message_.release()); delete this; } @@ -569,7 +585,7 @@ void ExtensionUnloadNotificationObserver::Observe( ExtensionTestResultNotificationObserver:: ExtensionTestResultNotificationObserver(AutomationProvider* automation) - : automation_(automation) { + : automation_(automation->AsWeakPtr()) { registrar_.Add(this, NotificationType::EXTENSION_TEST_PASSED, NotificationService::AllSources()); registrar_.Add(this, NotificationType::EXTENSION_TEST_FAILED, @@ -602,6 +618,9 @@ void ExtensionTestResultNotificationObserver::Observe( } void ExtensionTestResultNotificationObserver::MaybeSendResult() { + if (!automation_) + return; + if (results_.size() > 0) { // This release method should return the automation's current // reply message, or NULL if there is no current one. If it is not @@ -620,7 +639,7 @@ void ExtensionTestResultNotificationObserver::MaybeSendResult() { BrowserOpenedNotificationObserver::BrowserOpenedNotificationObserver( AutomationProvider* automation, IPC::Message* reply_message) - : automation_(automation), + : automation_(automation->AsWeakPtr()), reply_message_(reply_message), for_browser_command_(false) { registrar_.Add(this, NotificationType::BROWSER_OPENED, @@ -633,12 +652,17 @@ BrowserOpenedNotificationObserver::~BrowserOpenedNotificationObserver() { void BrowserOpenedNotificationObserver::Observe( NotificationType type, const NotificationSource& source, const NotificationDetails& details) { + if (!automation_) { + delete this; + return; + } + if (type == NotificationType::BROWSER_OPENED) { if (for_browser_command_) { - AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_, + AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_.get(), true); } - automation_->Send(reply_message_); + automation_->Send(reply_message_.release()); delete this; } else { NOTREACHED(); @@ -654,7 +678,7 @@ BrowserClosedNotificationObserver::BrowserClosedNotificationObserver( Browser* browser, AutomationProvider* automation, IPC::Message* reply_message) - : automation_(automation), + : automation_(automation->AsWeakPtr()), reply_message_(reply_message), for_browser_command_(false) { registrar_.Add(this, NotificationType::BROWSER_CLOSED, @@ -665,17 +689,22 @@ void BrowserClosedNotificationObserver::Observe( NotificationType type, const NotificationSource& source, const NotificationDetails& details) { DCHECK(type == NotificationType::BROWSER_CLOSED); + + if (!automation_) { + delete this; + return; + } + Details<bool> close_app(details); - DCHECK(reply_message_ != NULL); + if (for_browser_command_) { - AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_, + AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_.get(), true); } else { - AutomationMsg_CloseBrowser::WriteReplyParams(reply_message_, true, + AutomationMsg_CloseBrowser::WriteReplyParams(reply_message_.get(), true, *(close_app.ptr())); } - automation_->Send(reply_message_); - reply_message_ = NULL; + automation_->Send(reply_message_.release()); delete this; } @@ -689,7 +718,7 @@ BrowserCountChangeNotificationObserver::BrowserCountChangeNotificationObserver( AutomationProvider* automation, IPC::Message* reply_message) : target_count_(target_count), - automation_(automation), + automation_(automation->AsWeakPtr()), reply_message_(reply_message) { registrar_.Add(this, NotificationType::BROWSER_OPENED, NotificationService::AllSources()); @@ -710,18 +739,23 @@ void BrowserCountChangeNotificationObserver::Observe( DCHECK_LT(0, current_count); current_count--; } + + if (!automation_) { + delete this; + return; + } + if (current_count == target_count_) { AutomationMsg_WaitForBrowserWindowCountToBecome::WriteReplyParams( - reply_message_, true); - automation_->Send(reply_message_); - reply_message_ = NULL; + reply_message_.get(), true); + automation_->Send(reply_message_.release()); delete this; } } AppModalDialogShownObserver::AppModalDialogShownObserver( AutomationProvider* automation, IPC::Message* reply_message) - : automation_(automation), + : automation_(automation->AsWeakPtr()), reply_message_(reply_message) { registrar_.Add(this, NotificationType::APP_MODAL_DIALOG_SHOWN, NotificationService::AllSources()); @@ -735,10 +769,11 @@ void AppModalDialogShownObserver::Observe( const NotificationDetails& details) { DCHECK(type == NotificationType::APP_MODAL_DIALOG_SHOWN); - AutomationMsg_WaitForAppModalDialogToBeShown::WriteReplyParams( - reply_message_, true); - automation_->Send(reply_message_); - reply_message_ = NULL; + if (automation_) { + AutomationMsg_WaitForAppModalDialogToBeShown::WriteReplyParams( + reply_message_.get(), true); + automation_->Send(reply_message_.release()); + } delete this; } @@ -804,9 +839,9 @@ bool ExecuteBrowserCommandObserver::CreateAndRegisterObserver( case IDC_BACK: case IDC_FORWARD: case IDC_RELOAD: { - automation->AddNavigationStatusListener( + new NavigationNotificationObserver( &browser->GetSelectedTabContents()->controller(), - reply_message, 1, false); + automation, reply_message, 1, false); break; } default: { @@ -826,10 +861,11 @@ void ExecuteBrowserCommandObserver::Observe( NotificationType type, const NotificationSource& source, const NotificationDetails& details) { if (type == notification_type_) { - AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_, - true); - automation_->Send(reply_message_); - reply_message_ = NULL; + if (automation_) { + AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_.get(), + true); + automation_->Send(reply_message_.release()); + } delete this; } else { NOTREACHED(); @@ -838,7 +874,7 @@ void ExecuteBrowserCommandObserver::Observe( ExecuteBrowserCommandObserver::ExecuteBrowserCommandObserver( AutomationProvider* automation, IPC::Message* reply_message) - : automation_(automation), + : automation_(automation->AsWeakPtr()), notification_type_(NotificationType::ALL), reply_message_(reply_message) { } @@ -868,7 +904,7 @@ bool ExecuteBrowserCommandObserver::GetNotificationType( FindInPageNotificationObserver::FindInPageNotificationObserver( AutomationProvider* automation, TabContents* parent_tab, bool reply_with_json, IPC::Message* reply_message) - : automation_(automation), + : automation_(automation->AsWeakPtr()), active_match_ordinal_(-1), reply_with_json_(reply_with_json), reply_message_(reply_message) { @@ -887,6 +923,12 @@ void FindInPageNotificationObserver::Observe( DVLOG(1) << "Ignoring, since we only care about the final message"; return; } + + if (!automation_) { + delete this; + return; + } + // We get multiple responses and one of those will contain the ordinal. // This message comes to us before the final update is sent. if (find_details->request_id() == kFindInPageRequestId) { @@ -904,16 +946,15 @@ void FindInPageNotificationObserver::Observe( return_value->SetInteger("match_right", rect.right()); return_value->SetInteger("match_bottom", rect.bottom()); } - AutomationJSONReply(automation_, reply_message_) + AutomationJSONReply(automation_, reply_message_.release()) .SendSuccess(return_value.get()); delete this; } else { if (find_details->active_match_ordinal() > -1) { active_match_ordinal_ = find_details->active_match_ordinal(); - AutomationMsg_Find::WriteReplyParams(reply_message_, + AutomationMsg_Find::WriteReplyParams(reply_message_.get(), active_match_ordinal_, find_details->number_of_matches()); - automation_->Send(reply_message_); - reply_message_ = NULL; + automation_->Send(reply_message_.release()); } } } @@ -936,8 +977,16 @@ void DomOperationObserver::Observe( } } +DomOperationMessageSender::DomOperationMessageSender( + AutomationProvider* automation) + : automation_(automation->AsWeakPtr()) { +} + void DomOperationMessageSender::OnDomOperationCompleted( const std::string& json) { + if (!automation_) + return; + IPC::Message* reply_message = automation_->reply_message_release(); if (reply_message) { AutomationMsg_DomOperation::WriteReplyParams(reply_message, json); @@ -949,7 +998,7 @@ void DomOperationMessageSender::OnDomOperationCompleted( DocumentPrintedNotificationObserver::DocumentPrintedNotificationObserver( AutomationProvider* automation, IPC::Message* reply_message) - : automation_(automation), + : automation_(automation->AsWeakPtr()), success_(false), reply_message_(reply_message) { registrar_.Add(this, NotificationType::PRINT_JOB_EVENT, @@ -957,10 +1006,10 @@ DocumentPrintedNotificationObserver::DocumentPrintedNotificationObserver( } DocumentPrintedNotificationObserver::~DocumentPrintedNotificationObserver() { - DCHECK(reply_message_ != NULL); - AutomationMsg_PrintNow::WriteReplyParams(reply_message_, success_); - automation_->Send(reply_message_); - automation_->RemoveNavigationStatusListener(this); + if (automation_) { + AutomationMsg_PrintNow::WriteReplyParams(reply_message_.get(), success_); + automation_->Send(reply_message_.release()); + } } void DocumentPrintedNotificationObserver::Observe( @@ -1028,7 +1077,7 @@ void MetricEventDurationObserver::Observe(NotificationType type, PageTranslatedObserver::PageTranslatedObserver(AutomationProvider* automation, IPC::Message* reply_message, TabContents* tab_contents) - : automation_(automation), + : automation_(automation->AsWeakPtr()), reply_message_(reply_message) { registrar_.Add(this, NotificationType::PAGE_TRANSLATED, Source<TabContents>(tab_contents)); @@ -1039,8 +1088,13 @@ PageTranslatedObserver::~PageTranslatedObserver() {} void PageTranslatedObserver::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { + if (!automation_) { + delete this; + return; + } + DCHECK(type == NotificationType::PAGE_TRANSLATED); - AutomationJSONReply reply(automation_, reply_message_); + AutomationJSONReply reply(automation_, reply_message_.release()); PageTranslatedDetails* translated_details = Details<PageTranslatedDetails>(details).ptr(); @@ -1055,10 +1109,10 @@ void PageTranslatedObserver::Observe(NotificationType type, TabLanguageDeterminedObserver::TabLanguageDeterminedObserver( AutomationProvider* automation, IPC::Message* reply_message, TabContents* tab_contents, TranslateInfoBarDelegate* translate_bar) - : automation_(automation), - reply_message_(reply_message), - tab_contents_(tab_contents), - translate_bar_(translate_bar) { + : automation_(automation->AsWeakPtr()), + reply_message_(reply_message), + tab_contents_(tab_contents), + translate_bar_(translate_bar) { registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED, Source<TabContents>(tab_contents)); } @@ -1068,6 +1122,11 @@ void TabLanguageDeterminedObserver::Observe( const NotificationDetails& details) { DCHECK(type == NotificationType::TAB_LANGUAGE_DETERMINED); + if (!automation_) { + delete this; + return; + } + scoped_ptr<DictionaryValue> return_value(new DictionaryValue); return_value->SetBoolean("page_translated", tab_contents_->language_state().IsPageTranslated()); @@ -1102,7 +1161,7 @@ void TabLanguageDeterminedObserver::Observe( translate_bar_->GetOriginalLanguageCode()); return_value->Set("translate_bar", bar_info); } - AutomationJSONReply(automation_, reply_message_) + AutomationJSONReply(automation_, reply_message_.release()) .SendSuccess(return_value.get()); delete this; } @@ -1111,7 +1170,7 @@ InfoBarCountObserver::InfoBarCountObserver(AutomationProvider* automation, IPC::Message* reply_message, TabContents* tab_contents, size_t target_count) - : automation_(automation), + : automation_(automation->AsWeakPtr()), reply_message_(reply_message), tab_contents_(tab_contents), target_count_(target_count) { @@ -1133,8 +1192,11 @@ void InfoBarCountObserver::CheckCount() { if (tab_contents_->infobar_count() != target_count_) return; - AutomationMsg_WaitForInfoBarCount::WriteReplyParams(reply_message_, true); - automation_->Send(reply_message_); + if (automation_) { + AutomationMsg_WaitForInfoBarCount::WriteReplyParams(reply_message_.get(), + true); + automation_->Send(reply_message_.release()); + } delete this; } @@ -1142,7 +1204,7 @@ void InfoBarCountObserver::CheckCount() { LoginManagerObserver::LoginManagerObserver( AutomationProvider* automation, IPC::Message* reply_message) - : automation_(automation), + : automation_(automation->AsWeakPtr()), reply_message_(reply_message) { registrar_.Add(this, NotificationType::LOGIN_USER_CHANGED, @@ -1153,7 +1215,13 @@ void LoginManagerObserver::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { DCHECK(type == NotificationType::LOGIN_USER_CHANGED); - AutomationJSONReply reply(automation_, reply_message_); + + if (!automation_) { + delete this; + return; + } + + AutomationJSONReply reply(automation_, reply_message_.release()); Details<AuthenticationNotificationDetails> auth_details(details); if (auth_details->success()) reply.SendSuccess(NULL); @@ -1192,10 +1260,10 @@ AutomationProviderBookmarkModelObserver:: AutomationProviderBookmarkModelObserver( AutomationProvider* provider, IPC::Message* reply_message, - BookmarkModel* model) { - automation_provider_ = provider; - reply_message_ = reply_message; - model_ = model; + BookmarkModel* model) + : automation_provider_(provider->AsWeakPtr()), + reply_message_(reply_message), + model_(model) { model_->AddObserver(this); } @@ -1214,21 +1282,53 @@ void AutomationProviderBookmarkModelObserver::BookmarkModelBeingDeleted( } void AutomationProviderBookmarkModelObserver::ReplyAndDelete(bool success) { - AutomationMsg_WaitForBookmarkModelToLoad::WriteReplyParams( - reply_message_, success); - automation_provider_->Send(reply_message_); + if (automation_provider_) { + AutomationMsg_WaitForBookmarkModelToLoad::WriteReplyParams( + reply_message_.get(), success); + automation_provider_->Send(reply_message_.release()); + } delete this; } +AutomationProviderDownloadItemObserver::AutomationProviderDownloadItemObserver( + AutomationProvider* provider, + IPC::Message* reply_message, + int downloads) + : provider_(provider->AsWeakPtr()), + reply_message_(reply_message), + downloads_(downloads) { +} + +void AutomationProviderDownloadItemObserver::OnDownloadUpdated( + DownloadItem* download) { +} + void AutomationProviderDownloadItemObserver::OnDownloadFileCompleted( DownloadItem* download) { download->RemoveObserver(this); if (--downloads_ == 0) { - AutomationJSONReply(provider_, reply_message_).SendSuccess(NULL); + if (provider_) { + AutomationJSONReply(provider_, + reply_message_.release()).SendSuccess(NULL); + } delete this; } } +void AutomationProviderDownloadItemObserver::OnDownloadOpened( + DownloadItem* download) { +} + +AutomationProviderDownloadUpdatedObserver:: +AutomationProviderDownloadUpdatedObserver( + AutomationProvider* provider, + IPC::Message* reply_message, + bool wait_for_open) + : provider_(provider->AsWeakPtr()), + reply_message_(reply_message), + wait_for_open_(wait_for_open) { +} + void AutomationProviderDownloadUpdatedObserver::OnDownloadUpdated( DownloadItem* download) { // If this observer is watching for open, only send the reply if the download @@ -1239,8 +1339,11 @@ void AutomationProviderDownloadUpdatedObserver::OnDownloadUpdated( download->RemoveObserver(this); scoped_ptr<DictionaryValue> return_value( provider_->GetDictionaryFromDownloadItem(download)); - AutomationJSONReply(provider_, reply_message_).SendSuccess( - return_value.get()); + + if (provider_) { + AutomationJSONReply(provider_, reply_message_.release()).SendSuccess( + return_value.get()); + } delete this; } @@ -1249,27 +1352,67 @@ void AutomationProviderDownloadUpdatedObserver::OnDownloadOpened( download->RemoveObserver(this); scoped_ptr<DictionaryValue> return_value( provider_->GetDictionaryFromDownloadItem(download)); - AutomationJSONReply(provider_, reply_message_).SendSuccess( - return_value.get()); + + if (provider_) { + AutomationJSONReply(provider_, reply_message_.release()).SendSuccess( + return_value.get()); + } delete this; } +void AutomationProviderDownloadUpdatedObserver::OnDownloadFileCompleted( + DownloadItem* download) { +} + +AutomationProviderDownloadModelChangedObserver:: +AutomationProviderDownloadModelChangedObserver( + AutomationProvider* provider, + IPC::Message* reply_message, + DownloadManager* download_manager) + : provider_(provider->AsWeakPtr()), + reply_message_(reply_message), + download_manager_(download_manager) { +} + void AutomationProviderDownloadModelChangedObserver::ModelChanged() { - AutomationJSONReply(provider_, reply_message_).SendSuccess(NULL); download_manager_->RemoveObserver(this); + + if (provider_) + AutomationJSONReply(provider_, reply_message_.release()).SendSuccess(NULL); delete this; } +AutomationProviderSearchEngineObserver::AutomationProviderSearchEngineObserver( + AutomationProvider* provider, + IPC::Message* reply_message) + : provider_(provider->AsWeakPtr()), + reply_message_(reply_message) { +} + void AutomationProviderSearchEngineObserver::OnTemplateURLModelChanged() { TemplateURLModel* url_model = provider_->profile()->GetTemplateURLModel(); url_model->RemoveObserver(this); - AutomationJSONReply(provider_, reply_message_).SendSuccess(NULL); + + if (provider_) + AutomationJSONReply(provider_, reply_message_.release()).SendSuccess(NULL); delete this; } +AutomationProviderHistoryObserver::AutomationProviderHistoryObserver( + AutomationProvider* provider, + IPC::Message* reply_message) + : provider_(provider->AsWeakPtr()), + reply_message_(reply_message) { +} + void AutomationProviderHistoryObserver::HistoryQueryComplete( HistoryService::Handle request_handle, history::QueryResults* results) { + if (!provider_) { + delete this; + return; + } + scoped_ptr<DictionaryValue> return_value(new DictionaryValue); ListValue* history_list = new ListValue; @@ -1289,19 +1432,50 @@ void AutomationProviderHistoryObserver::HistoryQueryComplete( return_value->Set("history", history_list); // Return history info. - AutomationJSONReply reply(provider_, reply_message_); + AutomationJSONReply reply(provider_, reply_message_.release()); reply.SendSuccess(return_value.get()); delete this; } +AutomationProviderImportSettingsObserver:: +AutomationProviderImportSettingsObserver( + AutomationProvider* provider, + IPC::Message* reply_message) + : provider_(provider->AsWeakPtr()), + reply_message_(reply_message) { +} + +void AutomationProviderImportSettingsObserver::ImportStarted() { +} + +void AutomationProviderImportSettingsObserver::ImportItemStarted( + importer::ImportItem item) { +} + +void AutomationProviderImportSettingsObserver::ImportItemEnded( + importer::ImportItem item) { +} + void AutomationProviderImportSettingsObserver::ImportEnded() { - // Send back an empty success message. - AutomationJSONReply(provider_, reply_message_).SendSuccess(NULL); + if (provider_) + AutomationJSONReply(provider_, reply_message_.release()).SendSuccess(NULL); delete this; } +AutomationProviderGetPasswordsObserver::AutomationProviderGetPasswordsObserver( + AutomationProvider* provider, + IPC::Message* reply_message) + : provider_(provider->AsWeakPtr()), + reply_message_(reply_message) { +} + void AutomationProviderGetPasswordsObserver::OnPasswordStoreRequestDone( int handle, const std::vector<webkit_glue::PasswordForm*>& result) { + if (!provider_) { + delete this; + return; + } + scoped_ptr<DictionaryValue> return_value(new DictionaryValue); ListValue* passwords = new ListValue; @@ -1327,14 +1501,21 @@ void AutomationProviderGetPasswordsObserver::OnPasswordStoreRequestDone( } return_value->Set("passwords", passwords); - AutomationJSONReply(provider_, reply_message_).SendSuccess( + AutomationJSONReply(provider_, reply_message_.release()).SendSuccess( return_value.get()); delete this; } +AutomationProviderBrowsingDataObserver::AutomationProviderBrowsingDataObserver( + AutomationProvider* provider, + IPC::Message* reply_message) + : provider_(provider->AsWeakPtr()), + reply_message_(reply_message) { +} + void AutomationProviderBrowsingDataObserver::OnBrowsingDataRemoverDone() { - // Send back an empty success message - AutomationJSONReply(provider_, reply_message_).SendSuccess(NULL); + if (provider_) + AutomationJSONReply(provider_, reply_message_.release()).SendSuccess(NULL); delete this; } @@ -1342,9 +1523,9 @@ OmniboxAcceptNotificationObserver::OmniboxAcceptNotificationObserver( NavigationController* controller, AutomationProvider* automation, IPC::Message* reply_message) - : automation_(automation), - reply_message_(reply_message), - controller_(controller) { + : automation_(automation->AsWeakPtr()), + reply_message_(reply_message), + controller_(controller) { Source<NavigationController> source(controller_); registrar_.Add(this, NotificationType::LOAD_STOP, source); // Pages requiring auth don't send LOAD_STOP. @@ -1352,7 +1533,6 @@ OmniboxAcceptNotificationObserver::OmniboxAcceptNotificationObserver( } OmniboxAcceptNotificationObserver::~OmniboxAcceptNotificationObserver() { - automation_->RemoveNavigationStatusListener(this); } void OmniboxAcceptNotificationObserver::Observe( @@ -1361,7 +1541,10 @@ void OmniboxAcceptNotificationObserver::Observe( const NotificationDetails& details) { if (type == NotificationType::LOAD_STOP || type == NotificationType::AUTH_NEEDED) { - AutomationJSONReply(automation_, reply_message_).SendSuccess(NULL); + if (automation_) { + AutomationJSONReply(automation_, + reply_message_.release()).SendSuccess(NULL); + } delete this; } else { NOTREACHED(); @@ -1371,8 +1554,9 @@ void OmniboxAcceptNotificationObserver::Observe( SavePackageNotificationObserver::SavePackageNotificationObserver( SavePackage* save_package, AutomationProvider* automation, - IPC::Message* reply_message) : automation_(automation), - reply_message_(reply_message) { + IPC::Message* reply_message) + : automation_(automation->AsWeakPtr()), + reply_message_(reply_message) { Source<SavePackage> source(save_package); registrar_.Add(this, NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED, source); @@ -1383,7 +1567,10 @@ void SavePackageNotificationObserver::Observe( const NotificationSource& source, const NotificationDetails& details) { if (type == NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED) { - AutomationJSONReply(automation_, reply_message_).SendSuccess(NULL); + if (automation_) { + AutomationJSONReply(automation_, + reply_message_.release()).SendSuccess(NULL); + } delete this; } else { NOTREACHED(); @@ -1394,7 +1581,7 @@ PageSnapshotTaker::PageSnapshotTaker(AutomationProvider* automation, IPC::Message* reply_message, RenderViewHost* render_view, const FilePath& path) - : automation_(automation), + : automation_(automation->AsWeakPtr()), reply_message_(reply_message), render_view_(render_view), image_path_(path), @@ -1452,9 +1639,11 @@ void PageSnapshotTaker::ExecuteScript(const std::wstring& javascript) { } void PageSnapshotTaker::SendMessage(bool success) { - AutomationMsg_CaptureEntirePageAsPNG::WriteReplyParams(reply_message_, - success); - automation_->Send(reply_message_); + if (automation_) { + AutomationMsg_CaptureEntirePageAsPNG::WriteReplyParams(reply_message_.get(), + success); + automation_->Send(reply_message_.release()); + } delete this; } @@ -1462,20 +1651,20 @@ NTPInfoObserver::NTPInfoObserver( AutomationProvider* automation, IPC::Message* reply_message, CancelableRequestConsumer* consumer) - : automation_(automation), - reply_message_(reply_message), - consumer_(consumer), - request_(0), - ntp_info_(new DictionaryValue) { + : automation_(automation->AsWeakPtr()), + reply_message_(reply_message), + consumer_(consumer), + request_(0), + ntp_info_(new DictionaryValue) { top_sites_ = automation_->profile()->GetTopSites(); if (!top_sites_) { - AutomationJSONReply(automation_, reply_message_) + AutomationJSONReply(automation_, reply_message_.release()) .SendError("Profile does not have service for querying the top sites."); return; } TabRestoreService* service = automation_->profile()->GetTabRestoreService(); if (!service) { - AutomationJSONReply(automation_, reply_message_) + AutomationJSONReply(automation_, reply_message_.release()) .SendError("No TabRestoreService."); return; } @@ -1528,6 +1717,11 @@ void NTPInfoObserver::OnTopSitesLoaded() { void NTPInfoObserver::OnTopSitesReceived( const history::MostVisitedURLList& visited_list) { + if (!automation_) { + delete this; + return; + } + ListValue* list_value = new ListValue; for (size_t i = 0; i < visited_list.size(); ++i) { const history::MostVisitedURL& visited = visited_list[i]; @@ -1540,7 +1734,8 @@ void NTPInfoObserver::OnTopSitesReceived( list_value->Append(dict); } ntp_info_->Set("most_visited", list_value); - AutomationJSONReply(automation_, reply_message_).SendSuccess(ntp_info_.get()); + AutomationJSONReply(automation_, + reply_message_.release()).SendSuccess(ntp_info_.get()); delete this; } @@ -1548,7 +1743,7 @@ AutocompleteEditFocusedObserver::AutocompleteEditFocusedObserver( AutomationProvider* automation, AutocompleteEditModel* autocomplete_edit, IPC::Message* reply_message) - : automation_(automation), + : automation_(automation->AsWeakPtr()), reply_message_(reply_message), autocomplete_edit_model_(autocomplete_edit) { Source<AutocompleteEditModel> source(autocomplete_edit); @@ -1560,9 +1755,11 @@ void AutocompleteEditFocusedObserver::Observe( const NotificationSource& source, const NotificationDetails& details) { DCHECK(type == NotificationType::AUTOCOMPLETE_EDIT_FOCUSED); - AutomationMsg_WaitForAutocompleteEditFocus::WriteReplyParams( - reply_message_, true); - automation_->Send(reply_message_); + if (automation_) { + AutomationMsg_WaitForAutocompleteEditFocus::WriteReplyParams( + reply_message_.get(), true); + automation_->Send(reply_message_.release()); + } delete this; } @@ -1658,7 +1855,7 @@ void OnNotificationBalloonCountObserver::OnBalloonCollectionChanged() { RendererProcessClosedObserver::RendererProcessClosedObserver( AutomationProvider* automation, IPC::Message* reply_message) - : automation_(automation), + : automation_(automation->AsWeakPtr()), reply_message_(reply_message) { registrar_.Add(this, NotificationType::RENDERER_PROCESS_CLOSED, NotificationService::AllSources()); @@ -1668,7 +1865,10 @@ void RendererProcessClosedObserver::Observe( NotificationType type, const NotificationSource& source, const NotificationDetails& details) { - AutomationJSONReply(automation_, reply_message_).SendSuccess(NULL); + if (automation_) { + AutomationJSONReply(automation_, + reply_message_.release()).SendSuccess(NULL); + } delete this; } @@ -1676,7 +1876,7 @@ InputEventAckNotificationObserver::InputEventAckNotificationObserver( AutomationProvider* automation, IPC::Message* reply_message, int event_type) - : automation_(automation), + : automation_(automation->AsWeakPtr()), reply_message_(reply_message), event_type_(event_type) { registrar_.Add( @@ -1690,7 +1890,10 @@ void InputEventAckNotificationObserver::Observe( const NotificationDetails& details) { Details<int> request_details(details); if (event_type_ == *request_details.ptr()) { - AutomationJSONReply(automation_, reply_message_).SendSuccess(NULL); + if (automation_) { + AutomationJSONReply(automation_, + reply_message_.release()).SendSuccess(NULL); + } delete this; } else { LOG(WARNING) << "Ignoring unexpected event types."; @@ -1699,7 +1902,7 @@ void InputEventAckNotificationObserver::Observe( NewTabObserver::NewTabObserver(AutomationProvider* automation, IPC::Message* reply_message) - : automation_(automation), + : automation_(automation->AsWeakPtr()), reply_message_(reply_message) { // Use TAB_PARENTED to detect the new tab. registrar_.Add(this, @@ -1711,11 +1914,18 @@ void NewTabObserver::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { DCHECK_EQ(NotificationType::TAB_PARENTED, type.value); - // We found the new tab. Now wait for it to load. NavigationController* controller = Source<NavigationController>(source).ptr(); - AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_, true); - automation_->AddNavigationStatusListener( - controller, reply_message_, 1, false); + if (automation_) { + // TODO(phajdan.jr): Clean up this hack. We write the correct return type + // here, but don't send the message. NavigationNotificationObserver + // will wait properly for the load to finish, and send the message, + // but it will also append its own return value at the end of the reply. + AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_.get(), + true); + new NavigationNotificationObserver(controller, automation_, + reply_message_.release(), + 1, false); + } delete this; } @@ -1725,7 +1935,7 @@ NewTabObserver::~NewTabObserver() { WaitForProcessLauncherThreadToGoIdleObserver:: WaitForProcessLauncherThreadToGoIdleObserver( AutomationProvider* automation, IPC::Message* reply_message) - : automation_(automation), + : automation_(automation->AsWeakPtr()), reply_message_(reply_message) { // Balanced in RunOnUIThread. AddRef(); @@ -1751,6 +1961,7 @@ RunOnProcessLauncherThread() { } void WaitForProcessLauncherThreadToGoIdleObserver::RunOnUIThread() { - automation_->Send(reply_message_); + if (automation_) + automation_->Send(reply_message_.release()); Release(); } diff --git a/chrome/browser/automation/automation_provider_observers.h b/chrome/browser/automation/automation_provider_observers.h index 4e0f7c5..a64bf29 100644 --- a/chrome/browser/automation/automation_provider_observers.h +++ b/chrome/browser/automation/automation_provider_observers.h @@ -11,6 +11,7 @@ #include <set> #include "base/scoped_ptr.h" +#include "base/weak_ptr.h" #include "chrome/browser/automation/automation_provider_json.h" #include "chrome/browser/bookmarks/bookmark_model_observer.h" #include "chrome/browser/browsing_data_remover.h" @@ -77,7 +78,7 @@ class InitialLoadObserver : public NotificationObserver { NotificationRegistrar registrar_; - AutomationProvider* automation_; + base::WeakPtr<AutomationProvider> automation_; size_t outstanding_tab_count_; base::TimeTicks init_time_; TabTimeMap loading_tabs_; @@ -98,7 +99,7 @@ class NewTabUILoadObserver : public NotificationObserver { private: NotificationRegistrar registrar_; - AutomationProvider* automation_; + base::WeakPtr<AutomationProvider> automation_; DISALLOW_COPY_AND_ASSIGN(NewTabUILoadObserver); }; @@ -119,9 +120,9 @@ class NavigationControllerRestoredObserver : public NotificationObserver { void SendDone(); NotificationRegistrar registrar_; - AutomationProvider* automation_; + base::WeakPtr<AutomationProvider> automation_; NavigationController* controller_; - IPC::Message* reply_message_; + scoped_ptr<IPC::Message> reply_message_; DISALLOW_COPY_AND_ASSIGN(NavigationControllerRestoredObserver); }; @@ -143,8 +144,8 @@ class NavigationNotificationObserver : public NotificationObserver { void ConditionMet(AutomationMsg_NavigationResponseValues navigation_result); NotificationRegistrar registrar_; - AutomationProvider* automation_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> automation_; + scoped_ptr<IPC::Message> reply_message_; NavigationController* controller_; int navigations_remaining_; bool navigation_started_; @@ -166,7 +167,7 @@ class TabStripNotificationObserver : public NotificationObserver { protected: NotificationRegistrar registrar_; - AutomationProvider* automation_; + base::WeakPtr<AutomationProvider> automation_; NotificationType notification_; }; @@ -180,7 +181,7 @@ class TabAppendedNotificationObserver : public TabStripNotificationObserver { protected: Browser* parent_; - IPC::Message* reply_message_; + scoped_ptr<IPC::Message> reply_message_; private: DISALLOW_COPY_AND_ASSIGN(TabAppendedNotificationObserver); @@ -197,7 +198,7 @@ class TabClosedNotificationObserver : public TabStripNotificationObserver { void set_for_browser_command(bool for_browser_command); protected: - IPC::Message* reply_message_; + scoped_ptr<IPC::Message> reply_message_; bool for_browser_command_; private: @@ -225,8 +226,8 @@ class TabCountChangeObserver : public TabStripModelObserver { // sends the reply message and deletes self. void CheckTabCount(); - AutomationProvider* automation_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> automation_; + scoped_ptr<IPC::Message> reply_message_; TabStripModel* tab_strip_model_; @@ -254,9 +255,9 @@ class ExtensionInstallNotificationObserver : public NotificationObserver { void SendResponse(AutomationMsg_ExtensionResponseValues response); NotificationRegistrar registrar_; - scoped_refptr<AutomationProvider> automation_; + base::WeakPtr<AutomationProvider> automation_; int id_; - IPC::Message* reply_message_; + scoped_ptr<IPC::Message> reply_message_; DISALLOW_COPY_AND_ASSIGN(ExtensionInstallNotificationObserver); }; @@ -279,9 +280,9 @@ class ExtensionReadyNotificationObserver : public NotificationObserver { private: NotificationRegistrar registrar_; ExtensionProcessManager* manager_; - scoped_refptr<AutomationProvider> automation_; + base::WeakPtr<AutomationProvider> automation_; int id_; - IPC::Message* reply_message_; + scoped_ptr<IPC::Message> reply_message_; const Extension* extension_; DISALLOW_COPY_AND_ASSIGN(ExtensionReadyNotificationObserver); @@ -325,7 +326,7 @@ class ExtensionTestResultNotificationObserver : public NotificationObserver { private: NotificationRegistrar registrar_; - AutomationProvider* automation_; + base::WeakPtr<AutomationProvider> automation_; // Two queues containing the test results. Although typically only // one result will be in each queue, there are cases where a queue is // needed. @@ -353,8 +354,8 @@ class BrowserOpenedNotificationObserver : public NotificationObserver { private: NotificationRegistrar registrar_; - AutomationProvider* automation_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> automation_; + scoped_ptr<IPC::Message> reply_message_; bool for_browser_command_; DISALLOW_COPY_AND_ASSIGN(BrowserOpenedNotificationObserver); @@ -374,8 +375,8 @@ class BrowserClosedNotificationObserver : public NotificationObserver { private: NotificationRegistrar registrar_; - AutomationProvider* automation_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> automation_; + scoped_ptr<IPC::Message> reply_message_; bool for_browser_command_; DISALLOW_COPY_AND_ASSIGN(BrowserClosedNotificationObserver); @@ -394,8 +395,8 @@ class BrowserCountChangeNotificationObserver : public NotificationObserver { private: int target_count_; NotificationRegistrar registrar_; - AutomationProvider* automation_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> automation_; + scoped_ptr<IPC::Message> reply_message_; DISALLOW_COPY_AND_ASSIGN(BrowserCountChangeNotificationObserver); }; @@ -412,8 +413,8 @@ class AppModalDialogShownObserver : public NotificationObserver { private: NotificationRegistrar registrar_; - AutomationProvider* automation_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> automation_; + scoped_ptr<IPC::Message> reply_message_; DISALLOW_COPY_AND_ASSIGN(AppModalDialogShownObserver); }; @@ -440,9 +441,9 @@ class ExecuteBrowserCommandObserver : public NotificationObserver { bool GetNotificationType(int command, NotificationType::Type* type); NotificationRegistrar registrar_; - scoped_refptr<AutomationProvider> automation_; + base::WeakPtr<AutomationProvider> automation_; NotificationType::Type notification_type_; - IPC::Message* reply_message_; + scoped_ptr<IPC::Message> reply_message_; DISALLOW_COPY_AND_ASSIGN(ExecuteBrowserCommandObserver); }; @@ -470,13 +471,13 @@ class FindInPageNotificationObserver : public NotificationObserver { private: NotificationRegistrar registrar_; - AutomationProvider* automation_; + base::WeakPtr<AutomationProvider> automation_; // We will at some point (before final update) be notified of the ordinal and // we need to preserve it so we can send it later. int active_match_ordinal_; // Send reply using json automation interface. bool reply_with_json_; - IPC::Message* reply_message_; + scoped_ptr<IPC::Message> reply_message_; DISALLOW_COPY_AND_ASSIGN(FindInPageNotificationObserver); }; @@ -500,13 +501,12 @@ class DomOperationObserver : public NotificationObserver { class DomOperationMessageSender : public DomOperationObserver { public: - explicit DomOperationMessageSender(AutomationProvider* automation) - : automation_(automation) {} + explicit DomOperationMessageSender(AutomationProvider* automation); virtual void OnDomOperationCompleted(const std::string& json); private: - AutomationProvider* automation_; + base::WeakPtr<AutomationProvider> automation_; DISALLOW_COPY_AND_ASSIGN(DomOperationMessageSender); }; @@ -522,9 +522,9 @@ class DocumentPrintedNotificationObserver : public NotificationObserver { private: NotificationRegistrar registrar_; - scoped_refptr<AutomationProvider> automation_; + base::WeakPtr<AutomationProvider> automation_; bool success_; - IPC::Message* reply_message_; + scoped_ptr<IPC::Message> reply_message_; DISALLOW_COPY_AND_ASSIGN(DocumentPrintedNotificationObserver); }; @@ -565,8 +565,8 @@ class PageTranslatedObserver : public NotificationObserver { private: NotificationRegistrar registrar_; - scoped_refptr<AutomationProvider> automation_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> automation_; + scoped_ptr<IPC::Message> reply_message_; DISALLOW_COPY_AND_ASSIGN(PageTranslatedObserver); }; @@ -585,8 +585,8 @@ class TabLanguageDeterminedObserver : public NotificationObserver { private: NotificationRegistrar registrar_; - AutomationProvider* automation_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> automation_; + scoped_ptr<IPC::Message> reply_message_; TabContents* tab_contents_; TranslateInfoBarDelegate* translate_bar_; @@ -611,8 +611,8 @@ class InfoBarCountObserver : public NotificationObserver { void CheckCount(); NotificationRegistrar registrar_; - AutomationProvider* automation_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> automation_; + scoped_ptr<IPC::Message> reply_message_; TabContents* tab_contents_; const size_t target_count_; @@ -634,8 +634,8 @@ class LoginManagerObserver : public NotificationObserver { private: NotificationRegistrar registrar_; - AutomationProvider* automation_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> automation_; + scoped_ptr<IPC::Message> reply_message_; DISALLOW_COPY_AND_ASSIGN(LoginManagerObserver); }; @@ -699,8 +699,8 @@ class AutomationProviderBookmarkModelObserver : BookmarkModelObserver { // observer list). void ReplyAndDelete(bool success); - scoped_refptr<AutomationProvider> automation_provider_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> automation_provider_; + scoped_ptr<IPC::Message> reply_message_; BookmarkModel* model_; DISALLOW_COPY_AND_ASSIGN(AutomationProviderBookmarkModelObserver); @@ -712,20 +712,15 @@ class AutomationProviderDownloadItemObserver : public DownloadItem::Observer { AutomationProviderDownloadItemObserver( AutomationProvider* provider, IPC::Message* reply_message, - int downloads) { - provider_ = provider; - reply_message_ = reply_message; - downloads_ = downloads; - } - virtual ~AutomationProviderDownloadItemObserver() {} + int downloads); - virtual void OnDownloadUpdated(DownloadItem* download) { } + virtual void OnDownloadUpdated(DownloadItem* download); virtual void OnDownloadFileCompleted(DownloadItem* download); - virtual void OnDownloadOpened(DownloadItem* download) { } + virtual void OnDownloadOpened(DownloadItem* download); private: - AutomationProvider* provider_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> provider_; + scoped_ptr<IPC::Message> reply_message_; int downloads_; DISALLOW_COPY_AND_ASSIGN(AutomationProviderDownloadItemObserver); @@ -739,18 +734,15 @@ class AutomationProviderDownloadUpdatedObserver AutomationProviderDownloadUpdatedObserver( AutomationProvider* provider, IPC::Message* reply_message, - bool wait_for_open) - : provider_(provider), - reply_message_(reply_message), - wait_for_open_(wait_for_open) {} + bool wait_for_open); virtual void OnDownloadUpdated(DownloadItem* download); virtual void OnDownloadOpened(DownloadItem* download); - virtual void OnDownloadFileCompleted(DownloadItem* download) { } + virtual void OnDownloadFileCompleted(DownloadItem* download); private: - AutomationProvider* provider_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> provider_; + scoped_ptr<IPC::Message> reply_message_; bool wait_for_open_; DISALLOW_COPY_AND_ASSIGN(AutomationProviderDownloadUpdatedObserver); @@ -764,16 +756,13 @@ class AutomationProviderDownloadModelChangedObserver AutomationProviderDownloadModelChangedObserver( AutomationProvider* provider, IPC::Message* reply_message, - DownloadManager* download_manager) - : provider_(provider), - reply_message_(reply_message), - download_manager_(download_manager) {} + DownloadManager* download_manager); virtual void ModelChanged(); private: - AutomationProvider* provider_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> provider_; + scoped_ptr<IPC::Message> reply_message_; DownloadManager* download_manager_; DISALLOW_COPY_AND_ASSIGN(AutomationProviderDownloadModelChangedObserver); @@ -786,15 +775,13 @@ class AutomationProviderSearchEngineObserver public: AutomationProviderSearchEngineObserver( AutomationProvider* provider, - IPC::Message* reply_message) - : provider_(provider), - reply_message_(reply_message) {} + IPC::Message* reply_message); virtual void OnTemplateURLModelChanged(); private: - AutomationProvider* provider_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> provider_; + scoped_ptr<IPC::Message> reply_message_; DISALLOW_COPY_AND_ASSIGN(AutomationProviderSearchEngineObserver); }; @@ -804,17 +791,14 @@ class AutomationProviderHistoryObserver { public: AutomationProviderHistoryObserver( AutomationProvider* provider, - IPC::Message* reply_message) { - provider_ = provider; - reply_message_ = reply_message; - } - ~AutomationProviderHistoryObserver() {} + IPC::Message* reply_message); + void HistoryQueryComplete(HistoryService::Handle request_handle, history::QueryResults* results); private: - AutomationProvider* provider_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> provider_; + scoped_ptr<IPC::Message> reply_message_; }; // Allows the automation provider to wait for import queries to finish. @@ -823,16 +807,15 @@ class AutomationProviderImportSettingsObserver public: AutomationProviderImportSettingsObserver( AutomationProvider* provider, - IPC::Message* reply_message) - : provider_(provider), - reply_message_(reply_message) {} - virtual void ImportStarted() {} - virtual void ImportItemStarted(importer::ImportItem item) {} - virtual void ImportItemEnded(importer::ImportItem item) {} + IPC::Message* reply_message); + + virtual void ImportStarted(); + virtual void ImportItemStarted(importer::ImportItem item); + virtual void ImportItemEnded(importer::ImportItem item); virtual void ImportEnded(); private: - AutomationProvider* provider_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> provider_; + scoped_ptr<IPC::Message> reply_message_; }; // Allows automation provider to wait for getting passwords to finish. @@ -841,16 +824,14 @@ class AutomationProviderGetPasswordsObserver public: AutomationProviderGetPasswordsObserver( AutomationProvider* provider, - IPC::Message* reply_message) - : provider_(provider), - reply_message_(reply_message) {} + IPC::Message* reply_message); virtual void OnPasswordStoreRequestDone( int handle, const std::vector<webkit_glue::PasswordForm*>& result); private: - AutomationProvider* provider_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> provider_; + scoped_ptr<IPC::Message> reply_message_; }; // Allows the automation provider to wait for clearing browser data to finish. @@ -859,14 +840,13 @@ class AutomationProviderBrowsingDataObserver public: AutomationProviderBrowsingDataObserver( AutomationProvider* provider, - IPC::Message* reply_message) - : provider_(provider), - reply_message_(reply_message) {} + IPC::Message* reply_message); + virtual void OnBrowsingDataRemoverDone(); private: - AutomationProvider* provider_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> provider_; + scoped_ptr<IPC::Message> reply_message_; }; // Allows automation provider to wait until page load after selecting an item @@ -884,8 +864,8 @@ class OmniboxAcceptNotificationObserver : public NotificationObserver { private: NotificationRegistrar registrar_; - AutomationProvider* automation_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> automation_; + scoped_ptr<IPC::Message> reply_message_; NavigationController* controller_; DISALLOW_COPY_AND_ASSIGN(OmniboxAcceptNotificationObserver); @@ -905,8 +885,8 @@ class SavePackageNotificationObserver : public NotificationObserver { private: NotificationRegistrar registrar_; - AutomationProvider* automation_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> automation_; + scoped_ptr<IPC::Message> reply_message_; DISALLOW_COPY_AND_ASSIGN(SavePackageNotificationObserver); }; @@ -937,8 +917,8 @@ class PageSnapshotTaker : public DomOperationObserver { // Helper method to send a response back to the client. Deletes this. void SendMessage(bool success); - AutomationProvider* automation_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> automation_; + scoped_ptr<IPC::Message> reply_message_; RenderViewHost* render_view_; FilePath image_path_; bool received_width_; @@ -962,8 +942,8 @@ class NTPInfoObserver : public NotificationObserver { void OnTopSitesLoaded(); void OnTopSitesReceived(const history::MostVisitedURLList& visited_list); - AutomationProvider* automation_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> automation_; + scoped_ptr<IPC::Message> reply_message_; CancelableRequestConsumer* consumer_; CancelableRequestProvider::Handle request_; scoped_ptr<DictionaryValue> ntp_info_; @@ -987,8 +967,8 @@ class AutocompleteEditFocusedObserver : public NotificationObserver { private: NotificationRegistrar registrar_; - AutomationProvider* automation_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> automation_; + scoped_ptr<IPC::Message> reply_message_; AutocompleteEditModel* autocomplete_edit_model_; DISALLOW_COPY_AND_ASSIGN(AutocompleteEditFocusedObserver); @@ -1046,8 +1026,8 @@ class RendererProcessClosedObserver : public NotificationObserver { private: NotificationRegistrar registrar_; - AutomationProvider* automation_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> automation_; + scoped_ptr<IPC::Message> reply_message_; DISALLOW_COPY_AND_ASSIGN(RendererProcessClosedObserver); }; @@ -1066,8 +1046,8 @@ class InputEventAckNotificationObserver : public NotificationObserver { private: NotificationRegistrar registrar_; - AutomationProvider* automation_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> automation_; + scoped_ptr<IPC::Message> reply_message_; int event_type_; DISALLOW_COPY_AND_ASSIGN(InputEventAckNotificationObserver); @@ -1086,8 +1066,8 @@ class NewTabObserver : public NotificationObserver { ~NewTabObserver(); NotificationRegistrar registrar_; - scoped_refptr<AutomationProvider> automation_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> automation_; + scoped_ptr<IPC::Message> reply_message_; DISALLOW_COPY_AND_ASSIGN(NewTabObserver); }; @@ -1096,22 +1076,23 @@ class NewTabObserver : public NotificationObserver { // back to the UI thread that notifies the provider we're done. class WaitForProcessLauncherThreadToGoIdleObserver : public base::RefCountedThreadSafe< - WaitForProcessLauncherThreadToGoIdleObserver> { + WaitForProcessLauncherThreadToGoIdleObserver, + BrowserThread::DeleteOnUIThread> { public: WaitForProcessLauncherThreadToGoIdleObserver( AutomationProvider* automation, IPC::Message* reply_message); private: - friend class base::RefCountedThreadSafe< - WaitForProcessLauncherThreadToGoIdleObserver>; + friend class BrowserThread; + friend class DeleteTask<WaitForProcessLauncherThreadToGoIdleObserver>; ~WaitForProcessLauncherThreadToGoIdleObserver(); void RunOnProcessLauncherThread(); void RunOnUIThread(); - scoped_refptr<AutomationProvider> automation_; - IPC::Message* reply_message_; + base::WeakPtr<AutomationProvider> automation_; + scoped_ptr<IPC::Message> reply_message_; DISALLOW_COPY_AND_ASSIGN(WaitForProcessLauncherThreadToGoIdleObserver); }; diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 12c752c..b896b3f 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -450,7 +450,8 @@ void TestingAutomationProvider::AppendTab(int handle, if (browser_tracker_->ContainsHandle(handle)) { Browser* browser = browser_tracker_->GetResource(handle); - observer = AddTabStripObserver(browser, reply_message); + observer = new TabAppendedNotificationObserver(browser, this, + reply_message); TabContentsWrapper* contents = browser->AddSelectedTabWithURL(url, PageTransition::TYPED); if (contents) { @@ -460,11 +461,10 @@ void TestingAutomationProvider::AppendTab(int handle, } if (append_tab_response < 0) { - // The append tab failed. Remove the TabStripObserver - if (observer) { - RemoveTabStripObserver(observer); + // Appending tab failed. Clean up and send failure response. + + if (observer) delete observer; - } AutomationMsg_AppendTab::WriteReplyParams(reply_message, append_tab_response); @@ -586,8 +586,8 @@ void TestingAutomationProvider::NavigateToURLBlockUntilNavigationsComplete( Browser* browser = FindAndActivateTab(tab); if (browser) { - AddNavigationStatusListener(tab, reply_message, number_of_navigations, - false); + new NavigationNotificationObserver(tab, this, reply_message, + number_of_navigations, false); // TODO(darin): avoid conversion to GURL. browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED); @@ -635,7 +635,7 @@ void TestingAutomationProvider::Reload(int handle, NavigationController* tab = tab_tracker_->GetResource(handle); Browser* browser = FindAndActivateTab(tab); if (browser && browser->command_updater()->IsCommandEnabled(IDC_RELOAD)) { - AddNavigationStatusListener(tab, reply_message, 1, false); + new NavigationNotificationObserver(tab, this, reply_message, 1, false); browser->Reload(CURRENT_TAB); return; } @@ -659,7 +659,7 @@ void TestingAutomationProvider::SetAuth(int tab_handle, // not strictly correct, because a navigation can require both proxy and // server auth, but it should be OK for now. LoginHandler* handler = iter->second; - AddNavigationStatusListener(tab, reply_message, 1, false); + new NavigationNotificationObserver(tab, this, reply_message, 1, false); handler->SetAuth(username, password); return; } @@ -679,7 +679,7 @@ void TestingAutomationProvider::CancelAuth(int tab_handle, if (iter != login_handler_map_.end()) { // If auth is needed again after this, something is screwy. LoginHandler* handler = iter->second; - AddNavigationStatusListener(tab, reply_message, 1, false); + new NavigationNotificationObserver(tab, this, reply_message, 1, false); handler->CancelAuth(); return; } @@ -1236,7 +1236,9 @@ void TestingAutomationProvider::ShowInterstitialPage( NavigationController* controller = tab_tracker_->GetResource(tab_handle); TabContents* tab_contents = controller->tab_contents(); - AddNavigationStatusListener(controller, reply_message, 1, false); + new NavigationNotificationObserver(controller, this, reply_message, 1, + false); + AutomationInterstitialPage* interstitial = new AutomationInterstitialPage(tab_contents, GURL("about:interstitial"), @@ -1334,7 +1336,8 @@ void TestingAutomationProvider::ActionOnSSLBlockingPage( InterstitialPage::GetInterstitialPage(tab_contents); if (ssl_blocking_page) { if (proceed) { - AddNavigationStatusListener(tab, reply_message, 1, false); + new NavigationNotificationObserver(tab, this, reply_message, 1, + false); ssl_blocking_page->Proceed(); return; } @@ -1375,15 +1378,24 @@ void TestingAutomationProvider::IsMenuCommandEnabled(int browser_handle, void TestingAutomationProvider::PrintNow(int tab_handle, IPC::Message* reply_message) { + NavigationController* tab = NULL; TabContents* tab_contents = GetTabContentsForHandle(tab_handle, &tab); if (tab_contents) { FindAndActivateTab(tab); - notification_observer_list_.AddObserver( - new DocumentPrintedNotificationObserver(this, reply_message)); - if (tab_contents->PrintNow()) - return; + + NotificationObserver* observer = + new DocumentPrintedNotificationObserver(this, reply_message); + + if (!tab_contents->PrintNow()) { + // Clean up the observer. It will send the reply message. + delete observer; + } + + // Return now to avoid sending reply message twice. + return; } + AutomationMsg_PrintNow::WriteReplyParams(reply_message, false); Send(reply_message); } @@ -1690,8 +1702,10 @@ void TestingAutomationProvider::ClickInfoBarAccept( NavigationController* nav_controller = tab_tracker_->GetResource(handle); if (nav_controller) { if (info_bar_index < nav_controller->tab_contents()->infobar_count()) { - if (wait_for_navigation) - AddNavigationStatusListener(nav_controller, reply_message, 1, false); + if (wait_for_navigation) { + new NavigationNotificationObserver(nav_controller, this, + reply_message, 1, false); + } InfoBarDelegate* delegate = nav_controller->tab_contents()->GetInfoBarDelegateAt( info_bar_index); @@ -1733,7 +1747,7 @@ void TestingAutomationProvider::WaitForNavigation(int handle, return; } - AddNavigationStatusListener(controller, reply_message, 1, true); + new NavigationNotificationObserver(controller, this, reply_message, 1, true); } void TestingAutomationProvider::SetIntPreference(int handle, @@ -1857,8 +1871,8 @@ void TestingAutomationProvider::GoBackBlockUntilNavigationsComplete( NavigationController* tab = tab_tracker_->GetResource(handle); Browser* browser = FindAndActivateTab(tab); if (browser && browser->command_updater()->IsCommandEnabled(IDC_BACK)) { - AddNavigationStatusListener(tab, reply_message, number_of_navigations, - false); + new NavigationNotificationObserver(tab, this, reply_message, + number_of_navigations, false); browser->GoBack(CURRENT_TAB); return; } @@ -1875,8 +1889,8 @@ void TestingAutomationProvider::GoForwardBlockUntilNavigationsComplete( NavigationController* tab = tab_tracker_->GetResource(handle); Browser* browser = FindAndActivateTab(tab); if (browser && browser->command_updater()->IsCommandEnabled(IDC_FORWARD)) { - AddNavigationStatusListener(tab, reply_message, number_of_navigations, - false); + new NavigationNotificationObserver(tab, this, reply_message, + number_of_navigations, false); browser->GoForward(CURRENT_TAB); return; } @@ -2943,11 +2957,7 @@ void TestingAutomationProvider::OmniboxAcceptInput( IPC::Message* reply_message) { NavigationController& controller = browser->GetSelectedTabContents()->controller(); - // Setup observer to wait until the selected item loads. - NotificationObserver* observer = - new OmniboxAcceptNotificationObserver(&controller, this, reply_message); - notification_observer_list_.AddObserver(observer); - + new OmniboxAcceptNotificationObserver(&controller, this, reply_message); browser->window()->GetLocationBar()->AcceptInput(); } |