OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/automation/automation_tab_tracker.h" | 5 #include "chrome/browser/automation/automation_tab_tracker.h" |
6 | 6 |
7 #include "chrome/common/chrome_notification_types.h" | 7 #include "chrome/common/chrome_notification_types.h" |
8 #include "content/public/browser/navigation_controller.h" | 8 #include "content/public/browser/navigation_controller.h" |
9 #include "content/public/browser/notification_source.h" | 9 #include "content/public/browser/notification_source.h" |
10 | 10 |
| 11 using content::NavigationController; |
| 12 |
11 AutomationTabTracker::AutomationTabTracker(IPC::Message::Sender* automation) | 13 AutomationTabTracker::AutomationTabTracker(IPC::Message::Sender* automation) |
12 : AutomationResourceTracker<content::NavigationController*>(automation) { | 14 : AutomationResourceTracker<NavigationController*>(automation) { |
13 } | 15 } |
14 | 16 |
15 AutomationTabTracker::~AutomationTabTracker() { | 17 AutomationTabTracker::~AutomationTabTracker() { |
16 } | 18 } |
17 | 19 |
18 void AutomationTabTracker::AddObserver( | 20 void AutomationTabTracker::AddObserver(NavigationController* resource) { |
19 content::NavigationController* resource) { | |
20 // This tab could either be a regular tab or an external tab | 21 // This tab could either be a regular tab or an external tab |
21 // Register for both notifications. | 22 // Register for both notifications. |
22 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSING, | 23 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSING, |
23 content::Source<content::NavigationController>(resource)); | 24 content::Source<NavigationController>(resource)); |
24 registrar_.Add(this, chrome::NOTIFICATION_EXTERNAL_TAB_CLOSED, | 25 registrar_.Add(this, chrome::NOTIFICATION_EXTERNAL_TAB_CLOSED, |
25 content::Source<content::NavigationController>(resource)); | 26 content::Source<NavigationController>(resource)); |
26 // We also want to know about navigations so we can keep track of the last | 27 // We also want to know about navigations so we can keep track of the last |
27 // navigation time. | 28 // navigation time. |
28 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, | 29 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
29 content::Source<content::NavigationController>(resource)); | 30 content::Source<NavigationController>(resource)); |
30 } | 31 } |
31 | 32 |
32 void AutomationTabTracker::RemoveObserver( | 33 void AutomationTabTracker::RemoveObserver(NavigationController* resource) { |
33 content::NavigationController* resource) { | |
34 registrar_.Remove(this, content::NOTIFICATION_TAB_CLOSING, | 34 registrar_.Remove(this, content::NOTIFICATION_TAB_CLOSING, |
35 content::Source<content::NavigationController>(resource)); | 35 content::Source<NavigationController>(resource)); |
36 registrar_.Remove(this, chrome::NOTIFICATION_EXTERNAL_TAB_CLOSED, | 36 registrar_.Remove(this, chrome::NOTIFICATION_EXTERNAL_TAB_CLOSED, |
37 content::Source<content::NavigationController>(resource)); | 37 content::Source<NavigationController>(resource)); |
38 registrar_.Remove(this, content::NOTIFICATION_LOAD_STOP, | 38 registrar_.Remove(this, content::NOTIFICATION_LOAD_STOP, |
39 content::Source<content::NavigationController>(resource)); | 39 content::Source<NavigationController>(resource)); |
40 } | 40 } |
41 | 41 |
42 void AutomationTabTracker::Observe( | 42 void AutomationTabTracker::Observe( |
43 int type, | 43 int type, |
44 const content::NotificationSource& source, | 44 const content::NotificationSource& source, |
45 const content::NotificationDetails& details) { | 45 const content::NotificationDetails& details) { |
46 switch (type) { | 46 switch (type) { |
47 case content::NOTIFICATION_LOAD_STOP: | 47 case content::NOTIFICATION_LOAD_STOP: |
48 last_navigation_times_[ | 48 last_navigation_times_[ |
49 content::Source<content::NavigationController>(source).ptr()] = | 49 content::Source<NavigationController>(source).ptr()] = |
50 base::Time::Now(); | 50 base::Time::Now(); |
51 return; | 51 return; |
52 case chrome::NOTIFICATION_EXTERNAL_TAB_CLOSED: | 52 case chrome::NOTIFICATION_EXTERNAL_TAB_CLOSED: |
53 case content::NOTIFICATION_TAB_CLOSING: | 53 case content::NOTIFICATION_TAB_CLOSING: |
54 { | 54 { |
55 std::map<content::NavigationController*, base::Time>::iterator iter = | 55 std::map<NavigationController*, base::Time>::iterator iter = |
56 last_navigation_times_.find( | 56 last_navigation_times_.find( |
57 content::Source<content::NavigationController>(source).ptr()); | 57 content::Source<NavigationController>(source).ptr()); |
58 if (iter != last_navigation_times_.end()) | 58 if (iter != last_navigation_times_.end()) |
59 last_navigation_times_.erase(iter); | 59 last_navigation_times_.erase(iter); |
60 } | 60 } |
61 break; | 61 break; |
62 default: | 62 default: |
63 NOTREACHED(); | 63 NOTREACHED(); |
64 } | 64 } |
65 AutomationResourceTracker<content::NavigationController*>::Observe( | 65 AutomationResourceTracker<NavigationController*>::Observe( |
66 type, source, details); | 66 type, source, details); |
67 } | 67 } |
68 | 68 |
69 base::Time AutomationTabTracker::GetLastNavigationTime(int handle) { | 69 base::Time AutomationTabTracker::GetLastNavigationTime(int handle) { |
70 if (ContainsHandle(handle)) { | 70 if (ContainsHandle(handle)) { |
71 content::NavigationController* controller = GetResource(handle); | 71 NavigationController* controller = GetResource(handle); |
72 if (controller) { | 72 if (controller) { |
73 std::map<content::NavigationController*, base::Time>::const_iterator iter | 73 std::map<NavigationController*, base::Time>::const_iterator iter |
74 = last_navigation_times_.find(controller); | 74 = last_navigation_times_.find(controller); |
75 if (iter != last_navigation_times_.end()) | 75 if (iter != last_navigation_times_.end()) |
76 return iter->second; | 76 return iter->second; |
77 } | 77 } |
78 } | 78 } |
79 return base::Time(); | 79 return base::Time(); |
80 } | 80 } |
OLD | NEW |