diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-03 23:55:15 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-03 23:55:15 +0000 |
commit | 54cea0fd87a8ad562d6ad403b22c5a9b4722ff3b (patch) | |
tree | 1591db9bbe04b443feb1c0fc385b68130e08b6b6 /chrome/browser/automation/automation_provider_observers.cc | |
parent | f9ff629f7e67baf59700abceacbdfb0c6014211a (diff) | |
download | chromium_src-54cea0fd87a8ad562d6ad403b22c5a9b4722ff3b.zip chromium_src-54cea0fd87a8ad562d6ad403b22c5a9b4722ff3b.tar.gz chromium_src-54cea0fd87a8ad562d6ad403b22c5a9b4722ff3b.tar.bz2 |
GTTF: Make WaitForTabCountToBecome automation call not Sleep.
Sleeping is an unreliable method to wait for things.
Instead, we set up an observer.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3300011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58563 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation/automation_provider_observers.cc')
-rw-r--r-- | chrome/browser/automation/automation_provider_observers.cc | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc index 0107708..a30e801 100644 --- a/chrome/browser/automation/automation_provider_observers.cc +++ b/chrome/browser/automation/automation_provider_observers.cc @@ -340,6 +340,49 @@ void TabClosedNotificationObserver::set_for_browser_command( for_browser_command_ = for_browser_command; } +TabCountChangeObserver::TabCountChangeObserver(AutomationProvider* automation, + Browser* browser, + IPC::Message* reply_message, + int target_tab_count) + : automation_(automation), + reply_message_(reply_message), + tab_strip_model_(browser->tabstrip_model()), + target_tab_count_(target_tab_count) { + tab_strip_model_->AddObserver(this); + CheckTabCount(); +} + +TabCountChangeObserver::~TabCountChangeObserver() { + tab_strip_model_->RemoveObserver(this); +} + +void TabCountChangeObserver::TabInsertedAt(TabContents* contents, + int index, + bool foreground) { + CheckTabCount(); +} + +void TabCountChangeObserver::TabClosingAt(TabContents* contents, int index) { + CheckTabCount(); +} + +void TabCountChangeObserver::TabStripModelDeleted() { + AutomationMsg_WaitForTabCountToBecome::WriteReplyParams(reply_message_, + false); + automation_->Send(reply_message_); + delete this; +} + +void TabCountChangeObserver::CheckTabCount() { + if (tab_strip_model_->count() != target_tab_count_) + return; + + AutomationMsg_WaitForTabCountToBecome::WriteReplyParams(reply_message_, + true); + automation_->Send(reply_message_); + delete this; +} + bool DidExtensionHostsStopLoading(ExtensionProcessManager* manager) { for (ExtensionProcessManager::const_iterator iter = manager->begin(); iter != manager->end(); ++iter) { |