summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-21 18:47:14 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-21 18:47:14 +0000
commit1c58a5c5098144cb4d281301aa79408d21998239 (patch)
tree2608f092014f1564f055a8459e1f75a267b20d0d
parentb31cb10adc5b1150ad6725b2f0b503c4e1593b33 (diff)
downloadchromium_src-1c58a5c5098144cb4d281301aa79408d21998239.zip
chromium_src-1c58a5c5098144cb4d281301aa79408d21998239.tar.gz
chromium_src-1c58a5c5098144cb4d281301aa79408d21998239.tar.bz2
Use NotificationRegistrar to handle notification observing.Also cleans up some other stuff: use {} on multi-line conditional bodies, remove a bunch of unused routing_id members, don't wrap lines that don't need to, etc.BUG=2381
Review URL: http://codereview.chromium.org/115602 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16634 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/automation/automation_autocomplete_edit_tracker.h13
-rw-r--r--chrome/browser/automation/automation_browser_tracker.h9
-rw-r--r--chrome/browser/automation/automation_constrained_window_tracker.h11
-rw-r--r--chrome/browser/automation/automation_provider.cc398
-rw-r--r--chrome/browser/automation/automation_provider.h13
-rw-r--r--chrome/browser/automation/automation_resource_tracker.cc7
-rw-r--r--chrome/browser/automation/automation_resource_tracker.h40
-rw-r--r--chrome/browser/automation/automation_tab_tracker.h3
-rw-r--r--chrome/browser/automation/automation_window_tracker.h11
-rw-r--r--chrome/browser/external_tab_container.cc1
10 files changed, 172 insertions, 334 deletions
diff --git a/chrome/browser/automation/automation_autocomplete_edit_tracker.h b/chrome/browser/automation/automation_autocomplete_edit_tracker.h
index 5a7c8e4..88e38d4 100644
--- a/chrome/browser/automation/automation_autocomplete_edit_tracker.h
+++ b/chrome/browser/automation/automation_autocomplete_edit_tracker.h
@@ -8,6 +8,8 @@
#include "chrome/browser/autocomplete/autocomplete_edit.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
#include "chrome/browser/automation/automation_resource_tracker.h"
+#include "chrome/common/notification_source.h"
+#include "chrome/common/notification_type.h"
class AutomationAutocompleteEditTracker :
public AutomationResourceTracker<AutocompleteEditView*> {
@@ -16,19 +18,16 @@ class AutomationAutocompleteEditTracker :
: AutomationResourceTracker<AutocompleteEditView*>(automation) { }
virtual ~AutomationAutocompleteEditTracker() {
- ClearAllMappings();
}
virtual void AddObserver(AutocompleteEditView* resource) {
- NotificationService::current()->AddObserver(
- this, NotificationType::AUTOCOMPLETE_EDIT_DESTROYED,
- Source<AutocompleteEditView>(resource));
+ registrar_.Add(this, NotificationType::AUTOCOMPLETE_EDIT_DESTROYED,
+ Source<AutocompleteEditView>(resource));
}
virtual void RemoveObserver(AutocompleteEditView* resource) {
- NotificationService::current()->RemoveObserver(
- this, NotificationType::AUTOCOMPLETE_EDIT_DESTROYED,
- Source<AutocompleteEditView>(resource));
+ registrar_.Remove(this, NotificationType::AUTOCOMPLETE_EDIT_DESTROYED,
+ Source<AutocompleteEditView>(resource));
}
};
diff --git a/chrome/browser/automation/automation_browser_tracker.h b/chrome/browser/automation/automation_browser_tracker.h
index dbc8959..2f14c97 100644
--- a/chrome/browser/automation/automation_browser_tracker.h
+++ b/chrome/browser/automation/automation_browser_tracker.h
@@ -16,17 +16,16 @@ public:
: AutomationResourceTracker<Browser*>(automation) { }
virtual ~AutomationBrowserTracker() {
- ClearAllMappings();
}
virtual void AddObserver(Browser* resource) {
- NotificationService::current()->AddObserver(
- this, NotificationType::BROWSER_CLOSED, Source<Browser>(resource));
+ registrar_.Add(this, NotificationType::BROWSER_CLOSED,
+ Source<Browser>(resource));
}
virtual void RemoveObserver(Browser* resource) {
- NotificationService::current()->RemoveObserver(
- this, NotificationType::BROWSER_CLOSED, Source<Browser>(resource));
+ registrar_.Remove(this, NotificationType::BROWSER_CLOSED,
+ Source<Browser>(resource));
}
};
diff --git a/chrome/browser/automation/automation_constrained_window_tracker.h b/chrome/browser/automation/automation_constrained_window_tracker.h
index 0986f4a..47d1f99 100644
--- a/chrome/browser/automation/automation_constrained_window_tracker.h
+++ b/chrome/browser/automation/automation_constrained_window_tracker.h
@@ -17,19 +17,16 @@ public:
: AutomationResourceTracker(automation) {}
virtual ~AutomationConstrainedWindowTracker() {
- ClearAllMappings();
}
virtual void AddObserver(ConstrainedWindow* resource) {
- NotificationService::current()->AddObserver(
- this, NotificationType::CWINDOW_CLOSED,
- Source<ConstrainedWindow>(resource));
+ registrar_.Add(this, NotificationType::CWINDOW_CLOSED,
+ Source<ConstrainedWindow>(resource));
}
virtual void RemoveObserver(ConstrainedWindow* resource) {
- NotificationService::current()->RemoveObserver(
- this, NotificationType::CWINDOW_CLOSED,
- Source<ConstrainedWindow>(resource));
+ registrar_.Remove(this, NotificationType::CWINDOW_CLOSED,
+ Source<ConstrainedWindow>(resource));
}
};
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index 0030946..641e883 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -33,7 +33,7 @@
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_contents_view.h"
#include "chrome/common/chrome_paths.h"
-#include "chrome/common/notification_registrar.h"
+#include "chrome/common/notification_service.h"
#include "chrome/common/platform_util.h"
#include "chrome/common/pref_service.h"
#include "chrome/test/automation/automation_messages.h"
@@ -114,19 +114,11 @@ class NewTabUILoadObserver : public NotificationObserver {
public:
explicit NewTabUILoadObserver(AutomationProvider* automation)
: automation_(automation) {
- NotificationService::current()->AddObserver(
- this, NotificationType::INITIAL_NEW_TAB_UI_LOAD,
- NotificationService::AllSources());
+ registrar_.Add(this, NotificationType::INITIAL_NEW_TAB_UI_LOAD,
+ NotificationService::AllSources());
}
~NewTabUILoadObserver() {
- Unregister();
- }
-
- void Unregister() {
- NotificationService::current()->RemoveObserver(
- this, NotificationType::INITIAL_NEW_TAB_UI_LOAD,
- NotificationService::AllSources());
}
virtual void Observe(NotificationType type,
@@ -142,6 +134,7 @@ class NewTabUILoadObserver : public NotificationObserver {
}
private:
+ NotificationRegistrar registrar_;
AutomationProvider* automation_;
};
@@ -149,26 +142,19 @@ class NavigationControllerRestoredObserver : public NotificationObserver {
public:
NavigationControllerRestoredObserver(AutomationProvider* automation,
NavigationController* controller,
- int32 routing_id,
IPC::Message* reply_message)
: automation_(automation),
controller_(controller),
- routing_id_(routing_id),
reply_message_(reply_message) {
if (FinishedRestoring()) {
- registered_ = false;
SendDone();
} else {
- registered_ = true;
- NotificationService* service = NotificationService::current();
- service->AddObserver(this, NotificationType::LOAD_STOP,
- NotificationService::AllSources());
+ registrar_.Add(this, NotificationType::LOAD_STOP,
+ NotificationService::AllSources());
}
}
~NavigationControllerRestoredObserver() {
- if (registered_)
- Unregister();
}
virtual void Observe(NotificationType type,
@@ -176,18 +162,11 @@ class NavigationControllerRestoredObserver : public NotificationObserver {
const NotificationDetails& details) {
if (FinishedRestoring()) {
SendDone();
- Unregister();
+ registrar_.RemoveAll();
}
}
private:
- void Unregister() {
- NotificationService* service = NotificationService::current();
- service->RemoveObserver(this, NotificationType::LOAD_STOP,
- NotificationService::AllSources());
- registered_ = false;
- }
-
bool FinishedRestoring() {
return (!controller_->needs_reload() && !controller_->pending_entry() &&
!controller_->tab_contents()->is_loading());
@@ -198,10 +177,9 @@ class NavigationControllerRestoredObserver : public NotificationObserver {
automation_->Send(reply_message_);
}
- bool registered_;
+ NotificationRegistrar registrar_;
AutomationProvider* automation_;
NavigationController* controller_;
- const int routing_id_;
IPC::Message* reply_message_;
DISALLOW_COPY_AND_ASSIGN(NavigationControllerRestoredObserver);
@@ -223,21 +201,26 @@ class NavigationNotificationObserver : public NotificationObserver {
success_code_(success_code),
auth_needed_code_(auth_needed_code),
failed_code_(failed_code) {
- NotificationService* service = NotificationService::current();
- service->AddObserver(this, NotificationType::NAV_ENTRY_COMMITTED,
- Source<NavigationController>(controller_));
- service->AddObserver(this, NotificationType::LOAD_START,
- Source<NavigationController>(controller_));
- service->AddObserver(this, NotificationType::LOAD_STOP,
- Source<NavigationController>(controller_));
- service->AddObserver(this, NotificationType::AUTH_NEEDED,
- Source<NavigationController>(controller_));
- service->AddObserver(this, NotificationType::AUTH_SUPPLIED,
- Source<NavigationController>(controller_));
+ Source<NavigationController> source(controller_);
+ registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, source);
+ registrar_.Add(this, NotificationType::LOAD_START, source);
+ registrar_.Add(this, NotificationType::LOAD_STOP, source);
+ registrar_.Add(this, NotificationType::AUTH_NEEDED, source);
+ registrar_.Add(this, NotificationType::AUTH_SUPPLIED, source);
}
~NavigationNotificationObserver() {
- Unregister();
+ 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<NavigationCodeType>::Write(reply_message_,
+ failed_code_);
+ automation_->Send(reply_message_);
+ reply_message_ = NULL;
+ }
+
+ automation_->RemoveNavigationStatusListener(this);
}
void ConditionMet(NavigationCodeType navigation_result) {
@@ -251,32 +234,6 @@ class NavigationNotificationObserver : public NotificationObserver {
delete this;
}
- void Unregister() {
- // 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.
- if (reply_message_) {
- IPC::ParamTraits<NavigationCodeType>::Write(reply_message_,
- failed_code_);
- automation_->Send(reply_message_);
- reply_message_ = NULL;
- }
-
- automation_->RemoveNavigationStatusListener(this);
-
- NotificationService* service = NotificationService::current();
- service->RemoveObserver(this, NotificationType::NAV_ENTRY_COMMITTED,
- Source<NavigationController>(controller_));
- service->RemoveObserver(this, NotificationType::LOAD_START,
- Source<NavigationController>(controller_));
- service->RemoveObserver(this, NotificationType::LOAD_STOP,
- Source<NavigationController>(controller_));
- service->RemoveObserver(this, NotificationType::AUTH_NEEDED,
- Source<NavigationController>(controller_));
- service->RemoveObserver(this, NotificationType::AUTH_SUPPLIED,
- Source<NavigationController>(controller_));
- }
-
virtual void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
@@ -326,6 +283,7 @@ class NavigationNotificationObserver : public NotificationObserver {
}
private:
+ NotificationRegistrar registrar_;
AutomationProvider* automation_;
IPC::Message* reply_message_;
NavigationController* controller_;
@@ -337,23 +295,14 @@ class NavigationNotificationObserver : public NotificationObserver {
class TabStripNotificationObserver : public NotificationObserver {
public:
- TabStripNotificationObserver(Browser* parent, NotificationType notification,
- AutomationProvider* automation, int32 routing_id)
- : automation_(automation),
- parent_(parent),
- notification_(notification),
- routing_id_(routing_id) {
- NotificationService::current()->
- AddObserver(this, notification_, NotificationService::AllSources());
+ TabStripNotificationObserver(NotificationType notification,
+ AutomationProvider* automation)
+ : automation_(automation),
+ notification_(notification) {
+ registrar_.Add(this, notification_, NotificationService::AllSources());
}
virtual ~TabStripNotificationObserver() {
- Unregister();
- }
-
- void Unregister() {
- NotificationService::current()->
- RemoveObserver(this, notification_, NotificationService::AllSources());
}
virtual void Observe(NotificationType type,
@@ -373,27 +322,26 @@ class TabStripNotificationObserver : public NotificationObserver {
virtual void ObserveTab(NavigationController* controller) = 0;
protected:
+ NotificationRegistrar registrar_;
AutomationProvider* automation_;
- Browser* parent_;
NotificationType notification_;
- int32 routing_id_;
};
class TabAppendedNotificationObserver : public TabStripNotificationObserver {
public:
TabAppendedNotificationObserver(Browser* parent,
- AutomationProvider* automation, int32 routing_id,
- IPC::Message* reply_message)
- : TabStripNotificationObserver(parent, NotificationType::TAB_PARENTED,
- automation, routing_id),
+ AutomationProvider* automation,
+ IPC::Message* reply_message)
+ : TabStripNotificationObserver(NotificationType::TAB_PARENTED,
+ automation),
+ parent_(parent),
reply_message_(reply_message) {
}
virtual void ObserveTab(NavigationController* controller) {
- int tab_index =
- automation_->GetIndexForNavigationController(controller, parent_);
- if (tab_index == TabStripModel::kNoTab) {
- // This tab notification doesn't belong to the parent_
+ if (automation_->GetIndexForNavigationController(controller, parent_) ==
+ TabStripModel::kNoTab) {
+ // This tab notification doesn't belong to the parent_.
return;
}
@@ -404,37 +352,36 @@ class TabAppendedNotificationObserver : public TabStripNotificationObserver {
}
protected:
+ Browser* parent_;
IPC::Message* reply_message_;
};
class TabClosedNotificationObserver : public TabStripNotificationObserver {
public:
- TabClosedNotificationObserver(Browser* parent,
- AutomationProvider* automation,
- int32 routing_id,
+ TabClosedNotificationObserver(AutomationProvider* automation,
bool wait_until_closed,
IPC::Message* reply_message)
- : TabStripNotificationObserver(parent,
- wait_until_closed ? NotificationType::TAB_CLOSED :
- NotificationType::TAB_CLOSING,
- automation,
- routing_id),
- reply_message_(reply_message),
- for_browser_command_(false) {
+ : TabStripNotificationObserver(wait_until_closed ?
+ NotificationType::TAB_CLOSED : NotificationType::TAB_CLOSING,
+ automation),
+ reply_message_(reply_message),
+ for_browser_command_(false) {
}
virtual void ObserveTab(NavigationController* controller) {
- if (for_browser_command_)
+ if (for_browser_command_) {
AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_,
true);
- else
+ } else {
AutomationMsg_CloseTab::WriteReplyParams(reply_message_, true);
+ }
automation_->Send(reply_message_);
}
void set_for_browser_command(bool for_browser_command) {
for_browser_command_ = for_browser_command;
}
+
protected:
IPC::Message* reply_message_;
bool for_browser_command_;
@@ -458,9 +405,10 @@ class BrowserOpenedNotificationObserver : public NotificationObserver {
const NotificationSource& source,
const NotificationDetails& details) {
if (type == NotificationType::BROWSER_OPENED) {
- if (for_browser_command_)
+ if (for_browser_command_) {
AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_,
true);
+ }
automation_->Send(reply_message_);
delete this;
} else {
@@ -471,10 +419,11 @@ class BrowserOpenedNotificationObserver : public NotificationObserver {
void set_for_browser_command(bool for_browser_command) {
for_browser_command_ = for_browser_command;
}
+
private:
+ NotificationRegistrar registrar_;
AutomationProvider* automation_;
IPC::Message* reply_message_;
- NotificationRegistrar registrar_;
bool for_browser_command_;
};
@@ -482,10 +431,8 @@ class BrowserClosedNotificationObserver : public NotificationObserver {
public:
BrowserClosedNotificationObserver(Browser* browser,
AutomationProvider* automation,
- int32 routing_id,
IPC::Message* reply_message)
: automation_(automation),
- routing_id_(routing_id),
reply_message_(reply_message),
for_browser_command_(false) {
registrar_.Add(this, NotificationType::BROWSER_CLOSED,
@@ -498,12 +445,13 @@ class BrowserClosedNotificationObserver : public NotificationObserver {
DCHECK(type == NotificationType::BROWSER_CLOSED);
Details<bool> close_app(details);
DCHECK(reply_message_ != NULL);
- if (for_browser_command_)
+ if (for_browser_command_) {
AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_,
true);
- else
+ } else {
AutomationMsg_CloseBrowser::WriteReplyParams(reply_message_, true,
*(close_app.ptr()));
+ }
automation_->Send(reply_message_);
reply_message_ = NULL;
delete this;
@@ -512,11 +460,11 @@ class BrowserClosedNotificationObserver : public NotificationObserver {
void set_for_browser_command(bool for_browser_command) {
for_browser_command_ = for_browser_command;
}
+
private:
+ NotificationRegistrar registrar_;
AutomationProvider* automation_;
- int32 routing_id_;
IPC::Message* reply_message_;
- NotificationRegistrar registrar_;
bool for_browser_command_;
};
@@ -552,24 +500,20 @@ class ExecuteBrowserCommandObserver : public NotificationObserver {
case IDC_NEW_WINDOW:
case IDC_NEW_INCOGNITO_WINDOW: {
BrowserOpenedNotificationObserver* observer =
- new BrowserOpenedNotificationObserver(automation,
- reply_message);
+ new BrowserOpenedNotificationObserver(automation, reply_message);
observer->set_for_browser_command(true);
break;
}
case IDC_CLOSE_WINDOW: {
BrowserClosedNotificationObserver* observer =
new BrowserClosedNotificationObserver(browser, automation,
- reply_message->routing_id(),
reply_message);
observer->set_for_browser_command(true);
break;
}
case IDC_CLOSE_TAB: {
TabClosedNotificationObserver* observer =
- new TabClosedNotificationObserver(browser, automation,
- reply_message->routing_id(),
- true, reply_message);
+ new TabClosedNotificationObserver(automation, true, reply_message);
observer->set_for_browser_command(true);
break;
}
@@ -621,8 +565,7 @@ class ExecuteBrowserCommandObserver : public NotificationObserver {
bool Register(int command) {
if (!GetNotificationType(command, &notification_type_))
return false;
- registrar_.Add(this, notification_type_,
- NotificationService::AllSources());
+ registrar_.Add(this, notification_type_, NotificationService::AllSources());
return true;
}
@@ -640,42 +583,30 @@ class ExecuteBrowserCommandObserver : public NotificationObserver {
return found;
}
+ NotificationRegistrar registrar_;
AutomationProvider* automation_;
NotificationType::Type notification_type_;
IPC::Message* reply_message_;
- NotificationRegistrar registrar_;
};
class FindInPageNotificationObserver : public NotificationObserver {
public:
FindInPageNotificationObserver(AutomationProvider* automation,
TabContents* parent_tab,
- int32 routing_id,
IPC::Message* reply_message)
: automation_(automation),
- parent_tab_(parent_tab),
- routing_id_(routing_id),
active_match_ordinal_(-1),
reply_message_(reply_message) {
- NotificationService::current()->AddObserver(
- this,
- NotificationType::FIND_RESULT_AVAILABLE,
- Source<TabContents>(parent_tab_));
+ registrar_.Add(this, NotificationType::FIND_RESULT_AVAILABLE,
+ Source<TabContents>(parent_tab));
}
~FindInPageNotificationObserver() {
- Unregister();
- }
-
- void Unregister() {
- DCHECK(reply_message_ == NULL);
- NotificationService::current()->
- RemoveObserver(this, NotificationType::FIND_RESULT_AVAILABLE,
- Source<TabContents>(parent_tab_));
}
- virtual void Observe(NotificationType type, const NotificationSource& source,
- const NotificationDetails& details) {
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
if (type == NotificationType::FIND_RESULT_AVAILABLE) {
Details<FindNotificationDetails> find_details(details);
if (find_details->request_id() == kFindInPageRequestId) {
@@ -686,9 +617,8 @@ class FindInPageNotificationObserver : public NotificationObserver {
if (find_details->final_update()) {
DCHECK(reply_message_ != NULL);
- AutomationMsg_FindInPage::WriteReplyParams(
- reply_message_, active_match_ordinal_,
- find_details->number_of_matches());
+ AutomationMsg_FindInPage::WriteReplyParams(reply_message_,
+ active_match_ordinal_, find_details->number_of_matches());
automation_->Send(reply_message_);
reply_message_ = NULL;
@@ -709,10 +639,10 @@ class FindInPageNotificationObserver : public NotificationObserver {
// don't need a rolling id to identify each search. But, we still need to
// specify one, so we just use a fixed one - its value does not matter.
static const int kFindInPageRequestId;
+
private:
+ NotificationRegistrar registrar_;
AutomationProvider* automation_;
- TabContents* parent_tab_;
- int32 routing_id_;
// 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_;
@@ -725,31 +655,30 @@ class DomOperationNotificationObserver : public NotificationObserver {
public:
explicit DomOperationNotificationObserver(AutomationProvider* automation)
: automation_(automation) {
- NotificationService::current()->
- AddObserver(this, NotificationType::DOM_OPERATION_RESPONSE,
- NotificationService::AllSources());
+ registrar_.Add(this, NotificationType::DOM_OPERATION_RESPONSE,
+ NotificationService::AllSources());
}
~DomOperationNotificationObserver() {
- NotificationService::current()->
- RemoveObserver(this, NotificationType::DOM_OPERATION_RESPONSE,
- NotificationService::AllSources());
}
- virtual void Observe(NotificationType type, const NotificationSource& source,
- const NotificationDetails& details) {
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
if (NotificationType::DOM_OPERATION_RESPONSE == type) {
Details<DomOperationNotificationDetails> dom_op_details(details);
IPC::Message* reply_message = automation_->reply_message_release();
DCHECK(reply_message != NULL);
- AutomationMsg_DomOperation::WriteReplyParams(
- reply_message, dom_op_details->json());
+ AutomationMsg_DomOperation::WriteReplyParams(reply_message,
+ dom_op_details->json());
automation_->Send(reply_message);
}
}
+
private:
+ NotificationRegistrar registrar_;
AutomationProvider* automation_;
};
@@ -757,17 +686,11 @@ class DomInspectorNotificationObserver : public NotificationObserver {
public:
explicit DomInspectorNotificationObserver(AutomationProvider* automation)
: automation_(automation) {
- NotificationService::current()->AddObserver(
- this,
- NotificationType::DOM_INSPECT_ELEMENT_RESPONSE,
- NotificationService::AllSources());
+ registrar_.Add(this, NotificationType::DOM_INSPECT_ELEMENT_RESPONSE,
+ NotificationService::AllSources());
}
~DomInspectorNotificationObserver() {
- NotificationService::current()->RemoveObserver(
- this,
- NotificationType::DOM_INSPECT_ELEMENT_RESPONSE,
- NotificationService::AllSources());
}
virtual void Observe(NotificationType type, const NotificationSource& source,
@@ -779,6 +702,7 @@ class DomInspectorNotificationObserver : public NotificationObserver {
}
private:
+ NotificationRegistrar registrar_;
AutomationProvider* automation_;
};
@@ -787,16 +711,12 @@ class DomInspectorNotificationObserver : public NotificationObserver {
class DocumentPrintedNotificationObserver : public NotificationObserver {
public:
DocumentPrintedNotificationObserver(AutomationProvider* automation,
- int32 routing_id,
IPC::Message* reply_message)
: automation_(automation),
- routing_id_(routing_id),
success_(false),
reply_message_(reply_message) {
- NotificationService::current()->AddObserver(
- this,
- NotificationType::PRINT_JOB_EVENT,
- NotificationService::AllSources());
+ registrar_.Add(this, NotificationType::PRINT_JOB_EVENT,
+ NotificationService::AllSources());
}
~DocumentPrintedNotificationObserver() {
@@ -804,10 +724,6 @@ class DocumentPrintedNotificationObserver : public NotificationObserver {
AutomationMsg_PrintNow::WriteReplyParams(reply_message_, success_);
automation_->Send(reply_message_);
automation_->RemoveNavigationStatusListener(this);
- NotificationService::current()->RemoveObserver(
- this,
- NotificationType::PRINT_JOB_EVENT,
- NotificationService::AllSources());
}
virtual void Observe(NotificationType type, const NotificationSource& source,
@@ -845,8 +761,8 @@ class DocumentPrintedNotificationObserver : public NotificationObserver {
}
private:
+ NotificationRegistrar registrar_;
scoped_refptr<AutomationProvider> automation_;
- int32 routing_id_;
bool success_;
IPC::Message* reply_message_;
};
@@ -946,10 +862,10 @@ void AutomationProvider::RemoveNavigationStatusListener(
}
NotificationObserver* AutomationProvider::AddTabStripObserver(
- Browser* parent, int32 routing_id, IPC::Message* reply_message) {
+ Browser* parent,
+ IPC::Message* reply_message) {
NotificationObserver* observer =
- new TabAppendedNotificationObserver(parent, this, routing_id,
- reply_message);
+ new TabAppendedNotificationObserver(parent, this, reply_message);
notification_observer_list_.AddObserver(observer);
return observer;
@@ -1007,8 +923,7 @@ int AutomationProvider::GetIndexForNavigationController(
void AutomationProvider::OnMessageReceived(const IPC::Message& message) {
IPC_BEGIN_MESSAGE_MAP(AutomationProvider, message)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseBrowser,
- CloseBrowser)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseBrowser, CloseBrowser)
IPC_MESSAGE_HANDLER(AutomationMsg_CloseBrowserRequestAsync,
CloseBrowserAsync)
IPC_MESSAGE_HANDLER(AutomationMsg_ActivateTab, ActivateTab)
@@ -1017,20 +932,17 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseTab, CloseTab)
IPC_MESSAGE_HANDLER(AutomationMsg_GetCookies, GetCookies)
IPC_MESSAGE_HANDLER(AutomationMsg_SetCookie, SetCookie)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_NavigateToURL,
- NavigateToURL)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_NavigateToURL, NavigateToURL)
IPC_MESSAGE_HANDLER(AutomationMsg_NavigationAsync, NavigationAsync)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_GoBack, GoBack)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_GoForward, GoForward)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Reload, Reload)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SetAuth, SetAuth)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CancelAuth,
- CancelAuth)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CancelAuth, CancelAuth)
IPC_MESSAGE_HANDLER(AutomationMsg_NeedsAuth, NeedsAuth)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_RedirectsFrom,
GetRedirectsFrom)
- IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindowCount,
- GetBrowserWindowCount)
+ IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindowCount, GetBrowserWindowCount)
IPC_MESSAGE_HANDLER(AutomationMsg_NormalBrowserWindowCount,
GetNormalBrowserWindowCount)
IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindow, GetBrowserWindow)
@@ -1040,7 +952,7 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(AutomationMsg_FindNormalBrowserWindow,
FindNormalBrowserWindow)
IPC_MESSAGE_HANDLER(AutomationMsg_IsWindowActive, IsWindowActive)
- IPC_MESSAGE_HANDLER(AutomationMsg_ActivateWindow, ActivateWindow);
+ IPC_MESSAGE_HANDLER(AutomationMsg_ActivateWindow, ActivateWindow)
#if defined(OS_WIN)
IPC_MESSAGE_HANDLER(AutomationMsg_WindowHWND, GetWindowHWND)
#endif // defined(OS_WIN)
@@ -1048,14 +960,11 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) {
ExecuteBrowserCommandAsync)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowExecuteCommand,
ExecuteBrowserCommand)
- IPC_MESSAGE_HANDLER(AutomationMsg_WindowViewBounds,
- WindowGetViewBounds)
- IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowVisible,
- SetWindowVisible)
+ IPC_MESSAGE_HANDLER(AutomationMsg_WindowViewBounds, WindowGetViewBounds)
+ IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowVisible, SetWindowVisible)
#if defined(OS_WIN)
IPC_MESSAGE_HANDLER(AutomationMsg_WindowClick, WindowSimulateClick)
- IPC_MESSAGE_HANDLER(AutomationMsg_WindowKeyPress,
- WindowSimulateKeyPress)
+ IPC_MESSAGE_HANDLER(AutomationMsg_WindowKeyPress, WindowSimulateKeyPress)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowDrag,
WindowSimulateDrag)
#endif // defined(OS_WIN)
@@ -1068,46 +977,36 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(AutomationMsg_TabTitle, GetTabTitle)
IPC_MESSAGE_HANDLER(AutomationMsg_TabIndex, GetTabIndex)
IPC_MESSAGE_HANDLER(AutomationMsg_TabURL, GetTabURL)
- IPC_MESSAGE_HANDLER(AutomationMsg_ShelfVisibility,
- GetShelfVisibility)
+ IPC_MESSAGE_HANDLER(AutomationMsg_ShelfVisibility, GetShelfVisibility)
IPC_MESSAGE_HANDLER(AutomationMsg_HandleUnused, HandleUnused)
- IPC_MESSAGE_HANDLER(AutomationMsg_ApplyAccelerator,
- ApplyAccelerator)
+ IPC_MESSAGE_HANDLER(AutomationMsg_ApplyAccelerator, ApplyAccelerator)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_DomOperation,
ExecuteJavascript)
IPC_MESSAGE_HANDLER(AutomationMsg_ConstrainedWindowCount,
GetConstrainedWindowCount)
- IPC_MESSAGE_HANDLER(AutomationMsg_ConstrainedWindow,
- GetConstrainedWindow)
- IPC_MESSAGE_HANDLER(AutomationMsg_ConstrainedTitle,
- GetConstrainedTitle)
- IPC_MESSAGE_HANDLER(AutomationMsg_FindInPage,
- HandleFindInPageRequest)
- IPC_MESSAGE_HANDLER(AutomationMsg_GetFocusedViewID,
- GetFocusedViewID)
+ IPC_MESSAGE_HANDLER(AutomationMsg_ConstrainedWindow, GetConstrainedWindow)
+ IPC_MESSAGE_HANDLER(AutomationMsg_ConstrainedTitle, GetConstrainedTitle)
+ IPC_MESSAGE_HANDLER(AutomationMsg_FindInPage, HandleFindInPageRequest)
+ IPC_MESSAGE_HANDLER(AutomationMsg_GetFocusedViewID, GetFocusedViewID)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_InspectElement,
HandleInspectElementRequest)
- IPC_MESSAGE_HANDLER(AutomationMsg_SetFilteredInet,
- SetFilteredInet);
- IPC_MESSAGE_HANDLER(AutomationMsg_DownloadDirectory,
- GetDownloadDirectory);
+ IPC_MESSAGE_HANDLER(AutomationMsg_SetFilteredInet, SetFilteredInet)
+ IPC_MESSAGE_HANDLER(AutomationMsg_DownloadDirectory, GetDownloadDirectory)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindow,
- OpenNewBrowserWindow);
- IPC_MESSAGE_HANDLER(AutomationMsg_WindowForBrowser,
- GetWindowForBrowser);
+ OpenNewBrowserWindow)
+ IPC_MESSAGE_HANDLER(AutomationMsg_WindowForBrowser, GetWindowForBrowser)
IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditForBrowser,
- GetAutocompleteEditForBrowser);
- IPC_MESSAGE_HANDLER(AutomationMsg_BrowserForWindow,
- GetBrowserForWindow);
+ GetAutocompleteEditForBrowser)
+ IPC_MESSAGE_HANDLER(AutomationMsg_BrowserForWindow, GetBrowserForWindow)
#if defined(OS_WIN)
IPC_MESSAGE_HANDLER(AutomationMsg_CreateExternalTab, CreateExternalTab)
#endif
IPC_MESSAGE_HANDLER(AutomationMsg_NavigateInExternalTab,
NavigateInExternalTab)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ShowInterstitialPage,
- ShowInterstitialPage);
+ ShowInterstitialPage)
IPC_MESSAGE_HANDLER(AutomationMsg_HideInterstitialPage,
- HideInterstitialPage);
+ HideInterstitialPage)
#if defined(OS_WIN)
IPC_MESSAGE_HANDLER(AutomationMsg_SetAcceleratorsForTab,
SetAcceleratorsForTab)
@@ -1116,15 +1015,12 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) {
#endif
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabToBeRestored,
WaitForTabToBeRestored)
- IPC_MESSAGE_HANDLER(AutomationMsg_SetInitialFocus,
- SetInitialFocus)
+ IPC_MESSAGE_HANDLER(AutomationMsg_SetInitialFocus, SetInitialFocus)
#if defined(OS_WIN)
IPC_MESSAGE_HANDLER(AutomationMsg_TabReposition, OnTabReposition)
#endif
- IPC_MESSAGE_HANDLER(AutomationMsg_GetSecurityState,
- GetSecurityState)
- IPC_MESSAGE_HANDLER(AutomationMsg_GetPageType,
- GetPageType)
+ IPC_MESSAGE_HANDLER(AutomationMsg_GetSecurityState, GetSecurityState)
+ IPC_MESSAGE_HANDLER(AutomationMsg_GetPageType, GetPageType)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ActionOnSSLBlockingPage,
ActionOnSSLBlockingPage)
IPC_MESSAGE_HANDLER(AutomationMsg_BringBrowserToFront, BringBrowserToFront)
@@ -1146,42 +1042,36 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) {
HandleOpenFindInPageRequest)
IPC_MESSAGE_HANDLER(AutomationMsg_HandleMessageFromExternalHost,
OnMessageFromExternalHost)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Find,
- HandleFindRequest)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Find, HandleFindRequest)
IPC_MESSAGE_HANDLER(AutomationMsg_FindWindowVisibility,
GetFindWindowVisibility)
IPC_MESSAGE_HANDLER(AutomationMsg_FindWindowLocation,
HandleFindWindowLocationRequest)
IPC_MESSAGE_HANDLER(AutomationMsg_BookmarkBarVisibility,
GetBookmarkBarVisibility)
- IPC_MESSAGE_HANDLER(AutomationMsg_GetSSLInfoBarCount,
- GetSSLInfoBarCount)
+ IPC_MESSAGE_HANDLER(AutomationMsg_GetSSLInfoBarCount, GetSSLInfoBarCount)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ClickSSLInfoBarLink,
ClickSSLInfoBarLink)
IPC_MESSAGE_HANDLER(AutomationMsg_GetLastNavigationTime,
GetLastNavigationTime)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForNavigation,
WaitForNavigation)
- IPC_MESSAGE_HANDLER(AutomationMsg_SetIntPreference,
- SetIntPreference)
+ IPC_MESSAGE_HANDLER(AutomationMsg_SetIntPreference, SetIntPreference)
IPC_MESSAGE_HANDLER(AutomationMsg_ShowingAppModalDialog,
GetShowingAppModalDialog)
IPC_MESSAGE_HANDLER(AutomationMsg_ClickAppModalDialogButton,
ClickAppModalDialogButton)
- IPC_MESSAGE_HANDLER(AutomationMsg_SetStringPreference,
- SetStringPreference)
+ IPC_MESSAGE_HANDLER(AutomationMsg_SetStringPreference, SetStringPreference)
IPC_MESSAGE_HANDLER(AutomationMsg_GetBooleanPreference,
GetBooleanPreference)
IPC_MESSAGE_HANDLER(AutomationMsg_SetBooleanPreference,
SetBooleanPreference)
IPC_MESSAGE_HANDLER(AutomationMsg_GetPageCurrentEncoding,
GetPageCurrentEncoding)
- IPC_MESSAGE_HANDLER(AutomationMsg_OverrideEncoding,
- OverrideEncoding)
+ IPC_MESSAGE_HANDLER(AutomationMsg_OverrideEncoding, OverrideEncoding)
IPC_MESSAGE_HANDLER(AutomationMsg_SavePackageShouldPromptUser,
SavePackageShouldPromptUser)
- IPC_MESSAGE_HANDLER(AutomationMsg_WindowTitle,
- GetWindowTitle)
+ IPC_MESSAGE_HANDLER(AutomationMsg_WindowTitle, GetWindowTitle)
IPC_MESSAGE_HANDLER(AutomationMsg_SetEnableExtensionAutomation,
SetEnableExtensionAutomation)
IPC_END_MESSAGE_MAP()
@@ -1205,8 +1095,7 @@ void AutomationProvider::AppendTab(int handle, const GURL& url,
if (browser_tracker_->ContainsHandle(handle)) {
Browser* browser = browser_tracker_->GetResource(handle);
- observer = AddTabStripObserver(browser, reply_message->routing_id(),
- reply_message);
+ observer = AddTabStripObserver(browser, reply_message);
TabContents* tab_contents = browser->AddTabWithURL(url, GURL(),
PageTransition::TYPED,
true, -1, false, NULL);
@@ -1413,7 +1302,6 @@ void AutomationProvider::GetRedirectsFrom(int tab_handle,
// Schedule a history query for redirects. The response will be sent
// asynchronously from the callback the history system uses to notify us
// that it's done: OnRedirectQueryComplete.
- redirect_query_routing_id_ = reply_message->routing_id();
redirect_query_ = history_service->QueryRedirectsFrom(
source_url, &consumer_,
NewCallback(this, &AutomationProvider::OnRedirectQueryComplete));
@@ -1679,10 +1567,9 @@ class InvokeTaskLaterTask : public Task {
// loop) have been processed by the time this is sent.
class WindowDragResponseTask : public Task {
public:
- WindowDragResponseTask(AutomationProvider* provider, int routing_id,
+ WindowDragResponseTask(AutomationProvider* provider,
IPC::Message* reply_message)
- : provider_(provider), routing_id_(routing_id),
- reply_message_(reply_message) {}
+ : provider_(provider), reply_message_(reply_message) {}
virtual ~WindowDragResponseTask() {}
virtual void Run() {
@@ -1693,7 +1580,6 @@ class WindowDragResponseTask : public Task {
private:
AutomationProvider* provider_;
- int routing_id_;
IPC::Message* reply_message_;
DISALLOW_COPY_AND_ASSIGN(WindowDragResponseTask);
@@ -1792,10 +1678,8 @@ void AutomationProvider::WindowSimulateDrag(int handle,
SendMessage(top_level_hwnd, up_message, wparam_flags,
MAKELPARAM(end.x, end.y));
- MessageLoop::current()->PostTask(FROM_HERE,
- new InvokeTaskLaterTask(
- new WindowDragResponseTask(this, reply_message->routing_id(),
- reply_message)));
+ MessageLoop::current()->PostTask(FROM_HERE, new InvokeTaskLaterTask(
+ new WindowDragResponseTask(this, reply_message)));
} else {
AutomationMsg_WindowDrag::WriteReplyParams(reply_message, true);
Send(reply_message);
@@ -2153,9 +2037,7 @@ void AutomationProvider::HandleFindRequest(
TabContents* tab_contents = nav->tab_contents();
find_in_page_observer_.reset(new
- FindInPageNotificationObserver(this, tab_contents,
- reply_message->routing_id(),
- reply_message));
+ FindInPageNotificationObserver(this, tab_contents, reply_message));
tab_contents->set_current_find_request_id(
FindInPageNotificationObserver::kFindInPageRequestId);
@@ -2231,7 +2113,6 @@ void AutomationProvider::HandleInspectElementRequest(
reply_message_ = reply_message;
tab_contents->render_view_host()->InspectElementAt(x, y);
- inspect_element_routing_id_ = reply_message->routing_id();
} else {
AutomationMsg_InspectElement::WriteReplyParams(reply_message, -1);
Send(reply_message);
@@ -2402,9 +2283,7 @@ void AutomationProvider::CloseTab(int tab_handle,
int index;
Browser* browser = Browser::GetBrowserForController(controller, &index);
DCHECK(browser);
- new TabClosedNotificationObserver(browser, this,
- reply_message->routing_id(),
- wait_until_closed, reply_message);
+ new TabClosedNotificationObserver(this, wait_until_closed, reply_message);
browser->CloseContents(controller->tab_contents());
return;
}
@@ -2417,7 +2296,6 @@ void AutomationProvider::CloseBrowser(int browser_handle,
if (browser_tracker_->ContainsHandle(browser_handle)) {
Browser* browser = browser_tracker_->GetResource(browser_handle);
new BrowserClosedNotificationObserver(browser, this,
- reply_message->routing_id(),
reply_message);
browser->window()->Close();
} else {
@@ -2501,9 +2379,7 @@ void AutomationProvider::WaitForTabToBeRestored(int tab_handle,
if (tab_tracker_->ContainsHandle(tab_handle)) {
NavigationController* tab = tab_tracker_->GetResource(tab_handle);
restore_tracker_.reset(
- new NavigationControllerRestoredObserver(this, tab,
- reply_message->routing_id(),
- reply_message));
+ new NavigationControllerRestoredObserver(this, tab, reply_message));
}
}
@@ -2623,9 +2499,7 @@ void AutomationProvider::PrintNow(int tab_handle,
if (tab_contents) {
FindAndActivateTab(tab);
notification_observer_list_.AddObserver(
- new DocumentPrintedNotificationObserver(this,
- reply_message->routing_id(),
- reply_message));
+ new DocumentPrintedNotificationObserver(this, reply_message));
if (tab_contents->PrintNow())
return;
}
@@ -2778,17 +2652,11 @@ ExternalTabContainer* AutomationProvider::GetExternalTabForHandle(int handle) {
TestingAutomationProvider::TestingAutomationProvider(Profile* profile)
: AutomationProvider(profile) {
BrowserList::AddObserver(this);
- NotificationService::current()->AddObserver(
- this,
- NotificationType::SESSION_END,
- NotificationService::AllSources());
+ registrar_.Add(this, NotificationType::SESSION_END,
+ NotificationService::AllSources());
}
TestingAutomationProvider::~TestingAutomationProvider() {
- NotificationService::current()->RemoveObserver(
- this,
- NotificationType::SESSION_END,
- NotificationService::AllSources());
BrowserList::RemoveObserver(this);
}
diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h
index 0b57b89..d90e2dc29 100644
--- a/chrome/browser/automation/automation_provider.h
+++ b/chrome/browser/automation/automation_provider.h
@@ -25,7 +25,7 @@
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/common/ipc_message.h"
#include "chrome/common/ipc_sync_channel.h"
-#include "chrome/common/notification_observer.h"
+#include "chrome/common/notification_registrar.h"
#include "chrome/test/automation/automation_messages.h"
#if defined(OS_WIN)
#include "views/event.h"
@@ -87,7 +87,6 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
// NOT be deleted and should be released by calling the corresponding
// RemoveTabStripObserver method.
NotificationObserver* AddTabStripObserver(Browser* parent,
- int32 routing_id,
IPC::Message* reply_message);
void RemoveTabStripObserver(NotificationObserver* obs);
@@ -486,14 +485,8 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
// Handle for an in-process redirect query. We expect only one redirect query
// at a time (we should have only one caller, and it will block while waiting
// for the results) so there is only one handle. When non-0, indicates a
- // query in progress. The routing ID will be set when the query is valid so
- // we know where to send the response.
+ // query in progress.
HistoryService::Handle redirect_query_;
- int redirect_query_routing_id_;
-
- // routing id for inspect element request so that we can send back the
- // response later
- int inspect_element_routing_id_;
// Consumer for asynchronous history queries.
CancelableRequestConsumer consumer_;
@@ -533,6 +526,8 @@ class TestingAutomationProvider : public AutomationProvider,
const NotificationDetails& details);
void OnRemoveProvider(); // Called via PostTask
+
+ NotificationRegistrar registrar_;
};
#endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_H_
diff --git a/chrome/browser/automation/automation_resource_tracker.cc b/chrome/browser/automation/automation_resource_tracker.cc
index be3d6fa..de20ba1 100644
--- a/chrome/browser/automation/automation_resource_tracker.cc
+++ b/chrome/browser/automation/automation_resource_tracker.cc
@@ -48,13 +48,6 @@ bool AutomationResourceTrackerImpl::ContainsHandleImpl(int handle) {
return handle_to_resource_.find(handle) != handle_to_resource_.end();
}
-void AutomationResourceTrackerImpl::ClearAllMappingsImpl() {
- while (!resource_to_handle_.empty()) {
- RemoveImpl(resource_to_handle_.begin()->first);
- }
- cleared_mappings_ = true;
-}
-
void* AutomationResourceTrackerImpl::GetResourceImpl(int handle) {
HandleToResourceMap::const_iterator iter = handle_to_resource_.find(handle);
if (iter == handle_to_resource_.end())
diff --git a/chrome/browser/automation/automation_resource_tracker.h b/chrome/browser/automation/automation_resource_tracker.h
index 53d80b9..a5ba0aa 100644
--- a/chrome/browser/automation/automation_resource_tracker.h
+++ b/chrome/browser/automation/automation_resource_tracker.h
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "chrome/common/ipc_message.h"
+#include "chrome/common/notification_registrar.h"
#include "chrome/common/notification_service.h"
// Template trick so that AutomationResourceTracker can be used with non-pointer
@@ -28,7 +29,7 @@ struct AutomationResourceTraits<T*> {
class AutomationResourceTrackerImpl {
public:
AutomationResourceTrackerImpl(IPC::Message::Sender* sender)
- : cleared_mappings_(false), sender_(sender) {}
+ : sender_(sender) {}
virtual ~AutomationResourceTrackerImpl() {}
@@ -43,13 +44,11 @@ public:
int GenerateHandle();
bool ContainsResourceImpl(void* resource);
bool ContainsHandleImpl(int handle);
- void ClearAllMappingsImpl();
void* GetResourceImpl(int handle);
int GetHandleImpl(void* resource);
void HandleCloseNotification(void* resource);
protected:
- bool cleared_mappings_;
typedef std::map<void*, int> ResourceToHandleMap;
typedef std::map<int, void*> HandleToResourceMap;
ResourceToHandleMap resource_to_handle_;
@@ -65,7 +64,7 @@ private:
// a particular kind of application resource (like windows or tabs) for
// automation purposes. The only things that a subclass should need to
// define are AddObserver and RemoveObserver for the given resource's
-// close notifications, ***and a destructor that calls ClearAllMappings***.
+// close notifications.
template <class T>
class AutomationResourceTracker : public NotificationObserver,
private AutomationResourceTrackerImpl {
@@ -74,17 +73,6 @@ class AutomationResourceTracker : public NotificationObserver,
: AutomationResourceTrackerImpl(automation) {}
virtual ~AutomationResourceTracker() {
- // NOTE: Be sure to call ClearAllMappings() from the destructor of your
- // subclass! It can't be called here, because it eventually uses
- // the subclass's RemoveObserver, which no longer exists by the time
- // this base class destructor is executed.
- DCHECK(cleared_mappings_);
- }
-
- // Removes all mappings from this tracker, including unregistering from
- // any associated resource notifications (via Remove calling RemoveObserver).
- void ClearAllMappings() {
- ClearAllMappingsImpl();
}
// The implementations for these should call the NotificationService
@@ -140,16 +128,20 @@ class AutomationResourceTracker : public NotificationObserver,
HandleCloseNotification(resource);
}
+
+ protected:
+ NotificationRegistrar registrar_;
+
private:
- // These proxy calls from the base Impl class to the template's subclss.
- virtual void AddObserverTypeProxy(void* resource) {
- AddObserver(static_cast<T>(resource));
- }
- virtual void RemoveObserverTypeProxy(void* resource) {
- RemoveObserver(static_cast<T>(resource));
- }
-
- DISALLOW_EVIL_CONSTRUCTORS(AutomationResourceTracker);
+ // These proxy calls from the base Impl class to the template's subclss.
+ virtual void AddObserverTypeProxy(void* resource) {
+ AddObserver(static_cast<T>(resource));
+ }
+ virtual void RemoveObserverTypeProxy(void* resource) {
+ RemoveObserver(static_cast<T>(resource));
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(AutomationResourceTracker);
};
#endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_RESOURCE_TRACKER_H__
diff --git a/chrome/browser/automation/automation_tab_tracker.h b/chrome/browser/automation/automation_tab_tracker.h
index 70172ec..2674bde 100644
--- a/chrome/browser/automation/automation_tab_tracker.h
+++ b/chrome/browser/automation/automation_tab_tracker.h
@@ -19,7 +19,6 @@ public:
: AutomationResourceTracker<NavigationController*>(automation) {}
virtual ~AutomationTabTracker() {
- ClearAllMappings();
}
virtual void AddObserver(NavigationController* resource) {
@@ -83,8 +82,6 @@ public:
}
private:
- NotificationRegistrar registrar_;
-
// Last time a navigation occurred.
std::map<NavigationController*, base::Time> last_navigation_times_;
diff --git a/chrome/browser/automation/automation_window_tracker.h b/chrome/browser/automation/automation_window_tracker.h
index effa61e..518692b 100644
--- a/chrome/browser/automation/automation_window_tracker.h
+++ b/chrome/browser/automation/automation_window_tracker.h
@@ -35,19 +35,16 @@ class AutomationWindowTracker
AutomationWindowTracker(IPC::Message::Sender* automation)
: AutomationResourceTracker<gfx::NativeWindow>(automation) { }
virtual ~AutomationWindowTracker() {
- ClearAllMappings();
}
virtual void AddObserver(gfx::NativeWindow resource) {
- NotificationService::current()->AddObserver(
- this, NotificationType::WINDOW_CLOSED,
- Source<gfx::NativeWindow>(resource));
+ registrar_.Add(this, NotificationType::WINDOW_CLOSED,
+ Source<gfx::NativeWindow>(resource));
}
virtual void RemoveObserver(gfx::NativeWindow resource) {
- NotificationService::current()->RemoveObserver(
- this, NotificationType::WINDOW_CLOSED,
- Source<gfx::NativeWindow>(resource));
+ registrar_.Remove(this, NotificationType::WINDOW_CLOSED,
+ Source<gfx::NativeWindow>(resource));
}
};
diff --git a/chrome/browser/external_tab_container.cc b/chrome/browser/external_tab_container.cc
index cc0782f..d250868 100644
--- a/chrome/browser/external_tab_container.cc
+++ b/chrome/browser/external_tab_container.cc
@@ -16,6 +16,7 @@
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/views/tab_contents_container_view.h"
#include "chrome/common/chrome_constants.h"
+#include "chrome/common/notification_service.h"
#include "chrome/test/automation/automation_messages.h"
// Included for SetRootViewForHWND.
#include "views/widget/widget_win.h"