OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_SYNC_NOTIFIER_CHROME_SYNC_NOTIFICATION_BRIDGE_H_ | |
6 #define CHROME_BROWSER_SYNC_NOTIFIER_CHROME_SYNC_NOTIFICATION_BRIDGE_H_ | |
7 | |
8 #include "base/compiler_specific.h" | |
9 #include "base/memory/ref_counted.h" | |
10 #include "base/observer_list_threadsafe.h" | |
11 #include "content/public/browser/notification_observer.h" | |
12 #include "content/public/browser/notification_registrar.h" | |
13 | |
14 class Profile; | |
15 | |
16 namespace sync_notifier { | |
17 | |
18 class SyncNotifierObserver; | |
19 | |
20 // A thread-safe bridge for chrome events that can trigger sync notifications. | |
21 // Currently only listens to NOTIFICATION_SYNC_REFRESH, triggering each | |
22 // observer's OnIncomingNotification method. Only the SESSIONS datatype is | |
23 // currently expected to be able to trigger this notification. | |
24 // Note: Notifications are expected to arrive on the UI thread, but observers | |
25 // may live on any thread. | |
26 class ChromeSyncNotificationBridge : public content::NotificationObserver { | |
27 public: | |
28 explicit ChromeSyncNotificationBridge(const Profile* profile); | |
29 virtual ~ChromeSyncNotificationBridge(); | |
30 | |
31 // These can be called on any thread. | |
32 virtual void AddObserver(SyncNotifierObserver* observer); | |
33 virtual void RemoveObserver(SyncNotifierObserver* observer); | |
34 | |
35 // NotificationObserver implementation. Called on UI thread. | |
36 virtual void Observe(int type, | |
37 const content::NotificationSource& source, | |
38 const content::NotificationDetails& details) OVERRIDE; | |
39 | |
40 private: | |
41 content::NotificationRegistrar registrar_; | |
42 | |
43 // Because [Add/Remove]Observer can be called from any thread, we need a | |
44 // thread-safe observerlist. | |
45 scoped_refptr<ObserverListThreadSafe<SyncNotifierObserver> > observers_; | |
46 }; | |
47 | |
48 } // namespace sync_notifier | |
49 | |
50 #endif // CHROME_BROWSER_SYNC_NOTIFIER_CHROME_SYNC_NOTIFICATION_BRIDGE_H_ | |
OLD | NEW |