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 #ifndef CHROME_BROWSER_SYNC_GLUE_CHROME_SYNC_NOTIFICATION_BRIDGE_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_CHROME_SYNC_NOTIFICATION_BRIDGE_H_ |
6 #define CHROME_BROWSER_SYNC_GLUE_CHROME_SYNC_NOTIFICATION_BRIDGE_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_CHROME_SYNC_NOTIFICATION_BRIDGE_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/observer_list_threadsafe.h" | 10 #include "base/observer_list_threadsafe.h" |
| 11 #include "base/synchronization/lock.h" |
11 #include "content/public/browser/notification_observer.h" | 12 #include "content/public/browser/notification_observer.h" |
12 #include "content/public/browser/notification_registrar.h" | 13 #include "content/public/browser/notification_registrar.h" |
13 #include "sync/internal_api/public/base/model_type.h" | 14 #include "sync/internal_api/public/base/model_type.h" |
| 15 #include "sync/notifier/invalidation_util.h" |
| 16 #include "sync/notifier/sync_notifier_helper.h" |
14 | 17 |
15 class Profile; | 18 class Profile; |
16 | 19 |
17 namespace syncer { | 20 namespace syncer { |
18 class SyncNotifierObserver; | 21 class SyncNotifierObserver; |
19 } // namespace | 22 } // namespace |
20 | 23 |
21 namespace browser_sync { | 24 namespace browser_sync { |
22 | 25 |
23 // A thread-safe bridge for chrome events that can trigger sync notifications. | 26 // A thread-safe bridge for chrome events that can trigger sync notifications. |
24 // Listens to NOTIFICATION_SYNC_REFRESH_LOCAL and | 27 // Listens to NOTIFICATION_SYNC_REFRESH_LOCAL and |
25 // NOTIFICATION_SYNC_REFRESH_REMOTE and triggers each observer's | 28 // NOTIFICATION_SYNC_REFRESH_REMOTE and triggers each observer's |
26 // OnIncomingNotification method on these notifications. | 29 // OnIncomingNotification method on these notifications. |
27 // Note: Notifications are expected to arrive on the UI thread, but observers | 30 // Note: Notifications are expected to arrive on the UI thread, but observers |
28 // may live on any thread. | 31 // may live on any thread. |
29 class ChromeSyncNotificationBridge : public content::NotificationObserver { | 32 class ChromeSyncNotificationBridge : public content::NotificationObserver { |
30 public: | 33 public: |
31 explicit ChromeSyncNotificationBridge(const Profile* profile); | 34 explicit ChromeSyncNotificationBridge(const Profile* profile); |
32 virtual ~ChromeSyncNotificationBridge(); | 35 virtual ~ChromeSyncNotificationBridge(); |
33 | 36 |
34 // Must be called on UI thread. | 37 // Must be called on UI thread. |
35 void UpdateEnabledTypes(const syncer::ModelTypeSet enabled_types); | 38 void UpdateEnabledTypes(const syncer::ModelTypeSet enabled_types); |
36 | 39 |
37 // These can be called on any thread. | 40 // These can be called on any thread. |
38 virtual void AddObserver(syncer::SyncNotifierObserver* observer); | 41 virtual void UpdateRegisteredIds(syncer::SyncNotifierObserver* handler, |
39 virtual void RemoveObserver(syncer::SyncNotifierObserver* observer); | 42 const syncer::ObjectIdSet& ids); |
40 | 43 |
41 // NotificationObserver implementation. Called on UI thread. | 44 // NotificationObserver implementation. Called on UI thread. |
42 virtual void Observe(int type, | 45 virtual void Observe(int type, |
43 const content::NotificationSource& source, | 46 const content::NotificationSource& source, |
44 const content::NotificationDetails& details) OVERRIDE; | 47 const content::NotificationDetails& details) OVERRIDE; |
45 | 48 |
46 private: | 49 private: |
47 content::NotificationRegistrar registrar_; | 50 content::NotificationRegistrar registrar_; |
48 syncer::ModelTypeSet enabled_types_; | 51 syncer::ModelTypeSet enabled_types_; |
49 | 52 syncer::SyncNotifierHelper helper_; |
50 // Because [Add/Remove]Observer can be called from any thread, we need a | 53 base::Lock helper_lock_; |
51 // thread-safe observerlist. | |
52 scoped_refptr<ObserverListThreadSafe<syncer::SyncNotifierObserver> > | |
53 observers_; | |
54 }; | 54 }; |
55 | 55 |
56 } // namespace browser_sync | 56 } // namespace browser_sync |
57 | 57 |
58 #endif // CHROME_BROWSER_SYNC_GLUE_CHROME_SYNC_NOTIFICATION_BRIDGE_H_ | 58 #endif // CHROME_BROWSER_SYNC_GLUE_CHROME_SYNC_NOTIFICATION_BRIDGE_H_ |
OLD | NEW |