OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/chrome_sync_notification_bridge.h" | 5 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" |
6 | 6 |
7 #include "chrome/common/chrome_notification_types.h" | 7 #include "chrome/common/chrome_notification_types.h" |
8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
9 #include "content/public/browser/notification_service.h" | 9 #include "content/public/browser/notification_service.h" |
10 #include "sync/notifier/sync_notifier_observer.h" | 10 #include "sync/notifier/sync_notifier_observer.h" |
11 | 11 |
12 using content::BrowserThread; | 12 using content::BrowserThread; |
13 | 13 |
14 namespace browser_sync { | 14 namespace browser_sync { |
15 | 15 |
16 ChromeSyncNotificationBridge::ChromeSyncNotificationBridge( | 16 ChromeSyncNotificationBridge::ChromeSyncNotificationBridge( |
17 const Profile* profile) | 17 const Profile* profile) { |
18 : observers_( | |
19 new ObserverListThreadSafe<syncer::SyncNotifierObserver>()) { | |
20 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 18 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
21 DCHECK(profile); | 19 DCHECK(profile); |
22 registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, | 20 registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, |
23 content::Source<Profile>(profile)); | 21 content::Source<Profile>(profile)); |
24 registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, | 22 registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, |
25 content::Source<Profile>(profile)); | 23 content::Source<Profile>(profile)); |
26 } | 24 } |
27 | 25 |
28 ChromeSyncNotificationBridge::~ChromeSyncNotificationBridge() {} | 26 ChromeSyncNotificationBridge::~ChromeSyncNotificationBridge() {} |
29 | 27 |
30 void ChromeSyncNotificationBridge::UpdateEnabledTypes( | 28 void ChromeSyncNotificationBridge::UpdateEnabledTypes( |
31 const syncer::ModelTypeSet types) { | 29 const syncer::ModelTypeSet types) { |
32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
33 enabled_types_ = types; | 31 enabled_types_ = types; |
34 } | 32 } |
35 | 33 |
36 void ChromeSyncNotificationBridge::AddObserver( | 34 void ChromeSyncNotificationBridge::UpdateRegisteredIds( |
37 syncer::SyncNotifierObserver* observer) { | 35 syncer::SyncNotifierObserver* handler, |
38 observers_->AddObserver(observer); | 36 const syncer::ObjectIdSet& ids) { |
39 } | 37 base::AutoLock locker_(helper_lock_); |
40 | 38 helper_.UpdateRegisteredIds(handler, ids); |
41 void ChromeSyncNotificationBridge::RemoveObserver( | |
42 syncer::SyncNotifierObserver* observer) { | |
43 observers_->RemoveObserver(observer); | |
44 } | 39 } |
45 | 40 |
46 void ChromeSyncNotificationBridge::Observe( | 41 void ChromeSyncNotificationBridge::Observe( |
47 int type, | 42 int type, |
48 const content::NotificationSource& source, | 43 const content::NotificationSource& source, |
49 const content::NotificationDetails& details) { | 44 const content::NotificationDetails& details) { |
50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
51 | 46 |
52 syncer::IncomingNotificationSource notification_source; | 47 syncer::IncomingNotificationSource notification_source; |
53 if (type == chrome::NOTIFICATION_SYNC_REFRESH_LOCAL) { | 48 if (type == chrome::NOTIFICATION_SYNC_REFRESH_LOCAL) { |
54 notification_source = syncer::LOCAL_NOTIFICATION; | 49 notification_source = syncer::LOCAL_NOTIFICATION; |
55 } else if (type == chrome::NOTIFICATION_SYNC_REFRESH_REMOTE) { | 50 } else if (type == chrome::NOTIFICATION_SYNC_REFRESH_REMOTE) { |
56 notification_source = syncer::REMOTE_NOTIFICATION; | 51 notification_source = syncer::REMOTE_NOTIFICATION; |
57 } else { | 52 } else { |
58 NOTREACHED() << "Unexpected notification type:" << type; | 53 NOTREACHED() << "Unexpected notification type:" << type; |
59 return; | 54 return; |
60 } | 55 } |
61 | 56 |
62 content::Details<const syncer::ModelTypePayloadMap> | 57 content::Details<const syncer::ModelTypePayloadMap> |
63 payload_details(details); | 58 payload_details(details); |
64 syncer::ModelTypePayloadMap payload_map = *(payload_details.ptr()); | 59 syncer::ModelTypePayloadMap payload_map = *(payload_details.ptr()); |
65 | 60 |
66 if (payload_map.empty()) { | 61 if (payload_map.empty()) { |
67 // No model types to invalidate, invalidating all enabled types. | 62 // No model types to invalidate, invalidating all enabled types. |
68 payload_map = | 63 payload_map = |
69 syncer::ModelTypePayloadMapFromEnumSet(enabled_types_, std::string()); | 64 syncer::ModelTypePayloadMapFromEnumSet(enabled_types_, std::string()); |
70 } | 65 } |
71 | 66 |
72 observers_->Notify( | 67 base::AutoLock locker_(helper_lock_); |
73 &syncer::SyncNotifierObserver::OnIncomingNotification, | 68 helper_.DispatchInvalidationsToHandlers( |
akalin
2012/07/19 00:42:06
this won't work. the invalidations must happen on
dcheng
2012/07/19 18:31:05
I don't quite understand the issue. Why isn't it a
akalin
2012/07/19 23:07:26
ObserverListThreadSafe guarantees that notificatio
dcheng
2012/07/20 00:57:04
Ah. My fault for not looking at the implementation
| |
74 payload_map, notification_source); | 69 ModelTypePayloadMapToObjectIdPayloadMap(payload_map), |
70 notification_source); | |
75 } | 71 } |
76 | 72 |
77 } // namespace browser_sync | 73 } // namespace browser_sync |
OLD | NEW |