• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/automation/automation_tab_tracker.h"
6 
7 #include "base/logging.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "content/public/browser/navigation_controller.h"
10 #include "content/public/browser/notification_source.h"
11 
12 using content::NavigationController;
13 
AutomationTabTracker(IPC::Sender * automation)14 AutomationTabTracker::AutomationTabTracker(IPC::Sender* automation)
15     : AutomationResourceTracker<NavigationController*>(automation) {
16 }
17 
~AutomationTabTracker()18 AutomationTabTracker::~AutomationTabTracker() {
19 }
20 
AddObserver(NavigationController * resource)21 void AutomationTabTracker::AddObserver(NavigationController* resource) {
22   // This tab could either be a regular tab or an external tab
23   // Register for both notifications.
24   registrar_.Add(this, chrome::NOTIFICATION_TAB_CLOSING,
25                  content::Source<NavigationController>(resource));
26   registrar_.Add(this, chrome::NOTIFICATION_EXTERNAL_TAB_CLOSED,
27                  content::Source<NavigationController>(resource));
28 }
29 
RemoveObserver(NavigationController * resource)30 void AutomationTabTracker::RemoveObserver(NavigationController* resource) {
31   registrar_.Remove(this, chrome::NOTIFICATION_TAB_CLOSING,
32                     content::Source<NavigationController>(resource));
33   registrar_.Remove(this, chrome::NOTIFICATION_EXTERNAL_TAB_CLOSED,
34                     content::Source<NavigationController>(resource));
35 }
36 
Observe(int type,const content::NotificationSource & source,const content::NotificationDetails & details)37 void AutomationTabTracker::Observe(
38     int type,
39     const content::NotificationSource& source,
40     const content::NotificationDetails& details) {
41   switch (type) {
42     case chrome::NOTIFICATION_EXTERNAL_TAB_CLOSED:
43     case chrome::NOTIFICATION_TAB_CLOSING:
44       break;
45     default:
46       NOTREACHED();
47   }
48   AutomationResourceTracker<NavigationController*>::Observe(
49       type, source, details);
50 }
51