diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-22 19:42:00 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-22 19:42:00 +0000 |
commit | 7e4468d50ab7c74fad98adcb847d82c5750f2a21 (patch) | |
tree | bcaecf049255d834e454b10512b241172109bd6f /chrome/browser/automation/automation_tab_tracker.cc | |
parent | 2aa3de25c0bca5f7c06a89a100bb7cd50004b853 (diff) | |
download | chromium_src-7e4468d50ab7c74fad98adcb847d82c5750f2a21.zip chromium_src-7e4468d50ab7c74fad98adcb847d82c5750f2a21.tar.gz chromium_src-7e4468d50ab7c74fad98adcb847d82c5750f2a21.tar.bz2 |
FBTF: Move a bunch of code to the headers and remove includes.
BUG=none
TEST=compiles
Review URL: http://codereview.chromium.org/3412016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60208 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation/automation_tab_tracker.cc')
-rw-r--r-- | chrome/browser/automation/automation_tab_tracker.cc | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/chrome/browser/automation/automation_tab_tracker.cc b/chrome/browser/automation/automation_tab_tracker.cc new file mode 100644 index 0000000..e672e2e --- /dev/null +++ b/chrome/browser/automation/automation_tab_tracker.cc @@ -0,0 +1,76 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/automation/automation_tab_tracker.h" + +#include "chrome/browser/tab_contents/navigation_controller.h" +#include "chrome/common/notification_type.h" +#include "chrome/common/notification_source.h" + +AutomationTabTracker::AutomationTabTracker(IPC::Message::Sender* automation) + : AutomationResourceTracker<NavigationController*>(automation) { +} + +AutomationTabTracker::~AutomationTabTracker() { +} + +void AutomationTabTracker::AddObserver(NavigationController* resource) { + // This tab could either be a regular tab or an external tab + // Register for both notifications. + registrar_.Add(this, NotificationType::TAB_CLOSING, + Source<NavigationController>(resource)); + registrar_.Add(this, NotificationType::EXTERNAL_TAB_CLOSED, + Source<NavigationController>(resource)); + // We also want to know about navigations so we can keep track of the last + // navigation time. + registrar_.Add(this, NotificationType::LOAD_STOP, + Source<NavigationController>(resource)); +} + +void AutomationTabTracker::RemoveObserver(NavigationController* resource) { + registrar_.Remove(this, NotificationType::TAB_CLOSING, + Source<NavigationController>(resource)); + registrar_.Remove(this, NotificationType::EXTERNAL_TAB_CLOSED, + Source<NavigationController>(resource)); + registrar_.Remove(this, NotificationType::LOAD_STOP, + Source<NavigationController>(resource)); +} + +void AutomationTabTracker::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + switch (type.value) { + case NotificationType::LOAD_STOP: + last_navigation_times_[Source<NavigationController>(source).ptr()] = + base::Time::Now(); + return; + case NotificationType::EXTERNAL_TAB_CLOSED: + case NotificationType::TAB_CLOSING: + { + std::map<NavigationController*, base::Time>::iterator iter = + last_navigation_times_.find( + Source<NavigationController>(source).ptr()); + if (iter != last_navigation_times_.end()) + last_navigation_times_.erase(iter); + } + break; + default: + NOTREACHED(); + } + AutomationResourceTracker<NavigationController*>::Observe(type, source, + details); +} + +base::Time AutomationTabTracker::GetLastNavigationTime(int handle) { + if (ContainsHandle(handle)) { + NavigationController* controller = GetResource(handle); + if (controller) { + std::map<NavigationController*, base::Time>::const_iterator iter = + last_navigation_times_.find(controller); + if (iter != last_navigation_times_.end()) + return iter->second; + } + } + return base::Time(); +} |