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/api/sync_error.h" | 15 #include "chrome/browser/sync/api/sync_error.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/internal_api/change_record.h" | 17 #include "chrome/browser/sync/internal_api/change_record.h" |
18 #include "chrome/browser/sync/internal_api/read_node.h" | 18 #include "chrome/browser/sync/internal_api/read_node.h" |
19 #include "chrome/browser/sync/profile_sync_service.h" | 19 #include "chrome/browser/sync/profile_sync_service.h" |
20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
21 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
22 #include "content/browser/tab_contents/navigation_controller.h" | 22 #include "content/browser/tab_contents/navigation_controller.h" |
23 #include "content/browser/tab_contents/tab_contents.h" | 23 #include "content/browser/tab_contents/tab_contents.h" |
24 #include "content/common/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
25 #include "content/public/browser/notification_details.h" | 25 #include "content/public/browser/notification_details.h" |
26 #include "content/public/browser/notification_source.h" | 26 #include "content/public/browser/notification_source.h" |
27 | 27 |
28 namespace browser_sync { | 28 namespace browser_sync { |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 // Extract the source SyncedTabDelegate from a NotificationSource originating | 32 // Extract the source SyncedTabDelegate from a NotificationSource originating |
33 // from a NavigationController, if it exists. Returns |NULL| otherwise. | 33 // from a NavigationController, if it exists. Returns |NULL| otherwise. |
34 SyncedTabDelegate* ExtractSyncedTabDelegate( | 34 SyncedTabDelegate* ExtractSyncedTabDelegate( |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 LOG(WARNING) << "Dropping modification to local session."; | 263 LOG(WARNING) << "Dropping modification to local session."; |
264 StartObserving(); | 264 StartObserving(); |
265 return; | 265 return; |
266 } | 266 } |
267 const base::Time& mtime = sync_node.GetModificationTime(); | 267 const base::Time& mtime = sync_node.GetModificationTime(); |
268 // The model associator handles foreign session updates and adds the same. | 268 // The model associator handles foreign session updates and adds the same. |
269 session_model_associator_->AssociateForeignSpecifics(specifics, mtime); | 269 session_model_associator_->AssociateForeignSpecifics(specifics, mtime); |
270 } | 270 } |
271 | 271 |
272 // Notify foreign session handlers that there are new sessions. | 272 // Notify foreign session handlers that there are new sessions. |
273 NotificationService::current()->Notify( | 273 content::NotificationService::current()->Notify( |
274 chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED, | 274 chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED, |
275 content::Source<Profile>(profile_), | 275 content::Source<Profile>(profile_), |
276 NotificationService::NoDetails()); | 276 content::NotificationService::NoDetails()); |
277 | 277 |
278 StartObserving(); | 278 StartObserving(); |
279 } | 279 } |
280 | 280 |
281 void SessionChangeProcessor::StartImpl(Profile* profile) { | 281 void SessionChangeProcessor::StartImpl(Profile* profile) { |
282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
283 DCHECK(profile); | 283 DCHECK(profile); |
284 DCHECK(profile_ == NULL); | 284 DCHECK(profile_ == NULL); |
285 profile_ = profile; | 285 profile_ = profile; |
286 StartObserving(); | 286 StartObserving(); |
287 } | 287 } |
288 | 288 |
289 void SessionChangeProcessor::StopImpl() { | 289 void SessionChangeProcessor::StopImpl() { |
290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
291 StopObserving(); | 291 StopObserving(); |
292 profile_ = NULL; | 292 profile_ = NULL; |
293 } | 293 } |
294 | 294 |
295 void SessionChangeProcessor::StartObserving() { | 295 void SessionChangeProcessor::StartObserving() { |
296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
297 DCHECK(profile_); | 297 DCHECK(profile_); |
298 notification_registrar_.Add(this, content::NOTIFICATION_TAB_PARENTED, | 298 notification_registrar_.Add(this, content::NOTIFICATION_TAB_PARENTED, |
299 NotificationService::AllSources()); | 299 content::NotificationService::AllSources()); |
300 notification_registrar_.Add(this, content::NOTIFICATION_TAB_CLOSED, | 300 notification_registrar_.Add(this, content::NOTIFICATION_TAB_CLOSED, |
301 NotificationService::AllSources()); | 301 content::NotificationService::AllSources()); |
302 notification_registrar_.Add(this, content::NOTIFICATION_NAV_LIST_PRUNED, | 302 notification_registrar_.Add(this, content::NOTIFICATION_NAV_LIST_PRUNED, |
303 NotificationService::AllSources()); | 303 content::NotificationService::AllSources()); |
304 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_CHANGED, | 304 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_CHANGED, |
305 NotificationService::AllSources()); | 305 content::NotificationService::AllSources()); |
306 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 306 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
307 NotificationService::AllSources()); | 307 content::NotificationService::AllSources()); |
308 notification_registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, | 308 notification_registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, |
309 NotificationService::AllBrowserContextsAndSources()); | 309 content::NotificationService::AllBrowserContextsAndSources()); |
310 notification_registrar_.Add(this, | 310 notification_registrar_.Add(this, |
311 chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, | 311 chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, |
312 NotificationService::AllSources()); | 312 content::NotificationService::AllSources()); |
313 notification_registrar_.Add(this, | 313 notification_registrar_.Add(this, |
314 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 314 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
315 NotificationService::AllBrowserContextsAndSources()); | 315 content::NotificationService::AllBrowserContextsAndSources()); |
316 } | 316 } |
317 | 317 |
318 void SessionChangeProcessor::StopObserving() { | 318 void SessionChangeProcessor::StopObserving() { |
319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
320 DCHECK(profile_); | 320 DCHECK(profile_); |
321 notification_registrar_.RemoveAll(); | 321 notification_registrar_.RemoveAll(); |
322 } | 322 } |
323 | 323 |
324 } // namespace browser_sync | 324 } // namespace browser_sync |
OLD | NEW |