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/sync/glue/session_change_processor.h" | 5 #include "chrome/browser/sync/glue/session_change_processor.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "chrome/browser/extensions/extension_tab_helper.h" | 13 #include "chrome/browser/extensions/extension_tab_helper.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/sync/engine/syncapi.h" | 15 #include "chrome/browser/sync/engine/syncapi.h" |
16 #include "chrome/browser/sync/glue/session_model_associator.h" | 16 #include "chrome/browser/sync/glue/session_model_associator.h" |
17 #include "chrome/browser/sync/profile_sync_service.h" | 17 #include "chrome/browser/sync/profile_sync_service.h" |
18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 19 #include "chrome/common/chrome_notification_types.h" |
19 #include "content/browser/tab_contents/navigation_controller.h" | 20 #include "content/browser/tab_contents/navigation_controller.h" |
20 #include "content/browser/tab_contents/tab_contents.h" | 21 #include "content/browser/tab_contents/tab_contents.h" |
21 #include "content/common/notification_details.h" | 22 #include "content/common/notification_details.h" |
22 #include "content/common/notification_service.h" | 23 #include "content/common/notification_service.h" |
23 #include "content/common/notification_source.h" | 24 #include "content/common/notification_source.h" |
24 | 25 |
25 namespace browser_sync { | 26 namespace browser_sync { |
26 | 27 |
27 SessionChangeProcessor::SessionChangeProcessor( | 28 SessionChangeProcessor::SessionChangeProcessor( |
28 UnrecoverableErrorHandler* error_handler, | 29 UnrecoverableErrorHandler* error_handler, |
(...skipping 17 matching lines...) Expand all Loading... |
46 setup_for_test_(setup_for_test) { | 47 setup_for_test_(setup_for_test) { |
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
48 DCHECK(error_handler); | 49 DCHECK(error_handler); |
49 DCHECK(session_model_associator_); | 50 DCHECK(session_model_associator_); |
50 } | 51 } |
51 | 52 |
52 SessionChangeProcessor::~SessionChangeProcessor() { | 53 SessionChangeProcessor::~SessionChangeProcessor() { |
53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
54 } | 55 } |
55 | 56 |
56 void SessionChangeProcessor::Observe(NotificationType type, | 57 void SessionChangeProcessor::Observe(int type, |
57 const NotificationSource& source, | 58 const NotificationSource& source, |
58 const NotificationDetails& details) { | 59 const NotificationDetails& details) { |
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
60 DCHECK(running()); | 61 DCHECK(running()); |
61 DCHECK(profile_); | 62 DCHECK(profile_); |
62 | 63 |
63 // Track which windows and/or tabs are modified. | 64 // Track which windows and/or tabs are modified. |
64 std::vector<TabContentsWrapper*> modified_tabs; | 65 std::vector<TabContentsWrapper*> modified_tabs; |
65 bool windows_changed = false; | 66 bool windows_changed = false; |
66 switch (type.value) { | 67 switch (type) { |
67 case NotificationType::BROWSER_OPENED: { | 68 case chrome::NOTIFICATION_BROWSER_OPENED: { |
68 Browser* browser = Source<Browser>(source).ptr(); | 69 Browser* browser = Source<Browser>(source).ptr(); |
69 if (browser->profile() != profile_) { | 70 if (browser->profile() != profile_) { |
70 return; | 71 return; |
71 } | 72 } |
72 | 73 |
73 windows_changed = true; | 74 windows_changed = true; |
74 break; | 75 break; |
75 } | 76 } |
76 | 77 |
77 case NotificationType::TAB_PARENTED: { | 78 case content::NOTIFICATION_TAB_PARENTED: { |
78 TabContentsWrapper* tab = Source<TabContentsWrapper>(source).ptr(); | 79 TabContentsWrapper* tab = Source<TabContentsWrapper>(source).ptr(); |
79 if (tab->profile() != profile_) { | 80 if (tab->profile() != profile_) { |
80 return; | 81 return; |
81 } | 82 } |
82 windows_changed = true; | 83 windows_changed = true; |
83 modified_tabs.push_back(tab); | 84 modified_tabs.push_back(tab); |
84 break; | 85 break; |
85 } | 86 } |
86 | 87 |
87 case NotificationType::TAB_CLOSED: { | 88 case content::NOTIFICATION_TAB_CLOSED: { |
88 TabContentsWrapper* tab = | 89 TabContentsWrapper* tab = |
89 TabContentsWrapper::GetCurrentWrapperForContents( | 90 TabContentsWrapper::GetCurrentWrapperForContents( |
90 Source<NavigationController>(source).ptr()->tab_contents()); | 91 Source<NavigationController>(source).ptr()->tab_contents()); |
91 if (!tab || tab->profile() != profile_) { | 92 if (!tab || tab->profile() != profile_) { |
92 return; | 93 return; |
93 } | 94 } |
94 windows_changed = true; | 95 windows_changed = true; |
95 modified_tabs.push_back(tab); | 96 modified_tabs.push_back(tab); |
96 break; | 97 break; |
97 } | 98 } |
98 | 99 |
99 case NotificationType::NAV_LIST_PRUNED: { | 100 case content::NOTIFICATION_NAV_LIST_PRUNED: { |
100 TabContentsWrapper* tab = | 101 TabContentsWrapper* tab = |
101 TabContentsWrapper::GetCurrentWrapperForContents( | 102 TabContentsWrapper::GetCurrentWrapperForContents( |
102 Source<NavigationController>(source).ptr()->tab_contents()); | 103 Source<NavigationController>(source).ptr()->tab_contents()); |
103 if (!tab || tab->profile() != profile_) { | 104 if (!tab || tab->profile() != profile_) { |
104 return; | 105 return; |
105 } | 106 } |
106 modified_tabs.push_back(tab); | 107 modified_tabs.push_back(tab); |
107 break; | 108 break; |
108 } | 109 } |
109 | 110 |
110 case NotificationType::NAV_ENTRY_CHANGED: { | 111 case content::NOTIFICATION_NAV_ENTRY_CHANGED: { |
111 TabContentsWrapper* tab = | 112 TabContentsWrapper* tab = |
112 TabContentsWrapper::GetCurrentWrapperForContents( | 113 TabContentsWrapper::GetCurrentWrapperForContents( |
113 Source<NavigationController>(source).ptr()->tab_contents()); | 114 Source<NavigationController>(source).ptr()->tab_contents()); |
114 if (!tab || tab->profile() != profile_) { | 115 if (!tab || tab->profile() != profile_) { |
115 return; | 116 return; |
116 } | 117 } |
117 modified_tabs.push_back(tab); | 118 modified_tabs.push_back(tab); |
118 break; | 119 break; |
119 } | 120 } |
120 | 121 |
121 case NotificationType::NAV_ENTRY_COMMITTED: { | 122 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { |
122 TabContentsWrapper* tab = | 123 TabContentsWrapper* tab = |
123 TabContentsWrapper::GetCurrentWrapperForContents( | 124 TabContentsWrapper::GetCurrentWrapperForContents( |
124 Source<NavigationController>(source).ptr()->tab_contents()); | 125 Source<NavigationController>(source).ptr()->tab_contents()); |
125 if (!tab || tab->profile() != profile_) { | 126 if (!tab || tab->profile() != profile_) { |
126 return; | 127 return; |
127 } | 128 } |
128 modified_tabs.push_back(tab); | 129 modified_tabs.push_back(tab); |
129 break; | 130 break; |
130 } | 131 } |
131 | 132 |
132 case NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED: { | 133 case chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED: { |
133 ExtensionTabHelper* extension_tab_helper = | 134 ExtensionTabHelper* extension_tab_helper = |
134 Source<ExtensionTabHelper>(source).ptr(); | 135 Source<ExtensionTabHelper>(source).ptr(); |
135 if (extension_tab_helper->tab_contents()->profile() != profile_) { | 136 if (extension_tab_helper->tab_contents()->profile() != profile_) { |
136 return; | 137 return; |
137 } | 138 } |
138 if (extension_tab_helper->extension_app()) { | 139 if (extension_tab_helper->extension_app()) { |
139 modified_tabs.push_back(extension_tab_helper->tab_contents_wrapper()); | 140 modified_tabs.push_back(extension_tab_helper->tab_contents_wrapper()); |
140 } | 141 } |
141 break; | 142 break; |
142 } | 143 } |
143 default: | 144 default: |
144 LOG(ERROR) << "Received unexpected notification of type " | 145 LOG(ERROR) << "Received unexpected notification of type " |
145 << type.value; | 146 << type; |
146 break; | 147 break; |
147 } | 148 } |
148 | 149 |
149 // Associate windows first to ensure tabs have homes. | 150 // Associate windows first to ensure tabs have homes. |
150 if (windows_changed) | 151 if (windows_changed) |
151 session_model_associator_->ReassociateWindows(false); | 152 session_model_associator_->ReassociateWindows(false); |
152 if (!modified_tabs.empty()) | 153 if (!modified_tabs.empty()) |
153 session_model_associator_->ReassociateTabs(modified_tabs); | 154 session_model_associator_->ReassociateTabs(modified_tabs); |
154 } | 155 } |
155 | 156 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 LOG(WARNING) << "Dropping modification to local session."; | 214 LOG(WARNING) << "Dropping modification to local session."; |
214 return; | 215 return; |
215 } | 216 } |
216 const int64 mtime = sync_node.GetModificationTime(); | 217 const int64 mtime = sync_node.GetModificationTime(); |
217 // Model associator handles foreign session update and add the same. | 218 // Model associator handles foreign session update and add the same. |
218 session_model_associator_->AssociateForeignSpecifics(specifics, mtime); | 219 session_model_associator_->AssociateForeignSpecifics(specifics, mtime); |
219 } | 220 } |
220 | 221 |
221 // Notify foreign session handlers that there are new sessions. | 222 // Notify foreign session handlers that there are new sessions. |
222 NotificationService::current()->Notify( | 223 NotificationService::current()->Notify( |
223 NotificationType::FOREIGN_SESSION_UPDATED, | 224 chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED, |
224 NotificationService::AllSources(), | 225 NotificationService::AllSources(), |
225 NotificationService::NoDetails()); | 226 NotificationService::NoDetails()); |
226 | 227 |
227 StartObserving(); | 228 StartObserving(); |
228 } | 229 } |
229 | 230 |
230 void SessionChangeProcessor::StartImpl(Profile* profile) { | 231 void SessionChangeProcessor::StartImpl(Profile* profile) { |
231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
232 DCHECK(profile); | 233 DCHECK(profile); |
233 DCHECK(profile_ == NULL); | 234 DCHECK(profile_ == NULL); |
234 profile_ = profile; | 235 profile_ = profile; |
235 StartObserving(); | 236 StartObserving(); |
236 } | 237 } |
237 | 238 |
238 void SessionChangeProcessor::StopImpl() { | 239 void SessionChangeProcessor::StopImpl() { |
239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
240 StopObserving(); | 241 StopObserving(); |
241 profile_ = NULL; | 242 profile_ = NULL; |
242 } | 243 } |
243 | 244 |
244 void SessionChangeProcessor::StartObserving() { | 245 void SessionChangeProcessor::StartObserving() { |
245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
246 DCHECK(profile_); | 247 DCHECK(profile_); |
247 notification_registrar_.Add(this, NotificationType::TAB_PARENTED, | 248 notification_registrar_.Add(this, content::NOTIFICATION_TAB_PARENTED, |
248 NotificationService::AllSources()); | 249 NotificationService::AllSources()); |
249 notification_registrar_.Add(this, NotificationType::TAB_CLOSED, | 250 notification_registrar_.Add(this, content::NOTIFICATION_TAB_CLOSED, |
250 NotificationService::AllSources()); | 251 NotificationService::AllSources()); |
251 notification_registrar_.Add(this, NotificationType::NAV_LIST_PRUNED, | 252 notification_registrar_.Add(this, content::NOTIFICATION_NAV_LIST_PRUNED, |
252 NotificationService::AllSources()); | 253 NotificationService::AllSources()); |
253 notification_registrar_.Add(this, NotificationType::NAV_ENTRY_CHANGED, | 254 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_CHANGED, |
254 NotificationService::AllSources()); | 255 NotificationService::AllSources()); |
255 notification_registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, | 256 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
256 NotificationService::AllSources()); | 257 NotificationService::AllSources()); |
257 notification_registrar_.Add(this, NotificationType::BROWSER_OPENED, | 258 notification_registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, |
258 NotificationService::AllSources()); | 259 NotificationService::AllSources()); |
259 notification_registrar_.Add(this, | 260 notification_registrar_.Add(this, |
260 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, | 261 chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, |
261 NotificationService::AllSources()); | 262 NotificationService::AllSources()); |
262 } | 263 } |
263 | 264 |
264 void SessionChangeProcessor::StopObserving() { | 265 void SessionChangeProcessor::StopObserving() { |
265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
266 DCHECK(profile_); | 267 DCHECK(profile_); |
267 notification_registrar_.RemoveAll(); | 268 notification_registrar_.RemoveAll(); |
268 } | 269 } |
269 | 270 |
270 } // namespace browser_sync | 271 } // namespace browser_sync |
OLD | NEW |