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 // An implementation of SyncNotifier that wraps InvalidationNotifier | 5 // An implementation of SyncNotifier that wraps InvalidationNotifier |
6 // on its own thread. | 6 // on its own thread. |
7 | 7 |
8 #ifndef SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ | 8 #ifndef SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ |
9 #define SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ | 9 #define SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "jingle/notifier/base/notifier_options.h" | 17 #include "jingle/notifier/base/notifier_options.h" |
18 #include "sync/internal_api/public/util/weak_handle.h" | 18 #include "sync/internal_api/public/util/weak_handle.h" |
19 #include "sync/notifier/invalidation_state_tracker.h" | 19 #include "sync/notifier/invalidation_state_tracker.h" |
20 #include "sync/notifier/sync_notifier.h" | 20 #include "sync/notifier/sync_notifier.h" |
21 #include "sync/notifier/sync_notifier_helper.h" | |
22 #include "sync/notifier/sync_notifier_observer.h" | 21 #include "sync/notifier/sync_notifier_observer.h" |
| 22 #include "sync/notifier/sync_notifier_registrar.h" |
23 | 23 |
24 namespace base { | 24 namespace base { |
25 class SingleThreadTaskRunner; | 25 class SingleThreadTaskRunner; |
26 } // namespace base | 26 } // namespace base |
27 | 27 |
28 namespace syncer { | 28 namespace syncer { |
29 | 29 |
| 30 // TODO(akalin): Generalize to NonBlockingSyncNotifier |
| 31 // (http://crbug.com/140409). |
30 class NonBlockingInvalidationNotifier | 32 class NonBlockingInvalidationNotifier |
31 : public SyncNotifier, | 33 : public SyncNotifier, |
32 // SyncNotifierObserver to "observe" our Core via WeakHandle. | 34 // SyncNotifierObserver to "observe" our Core via WeakHandle. |
33 public SyncNotifierObserver { | 35 public SyncNotifierObserver { |
34 public: | 36 public: |
35 // |invalidation_state_tracker| must be initialized. | 37 // |invalidation_state_tracker| must be initialized. |
36 NonBlockingInvalidationNotifier( | 38 NonBlockingInvalidationNotifier( |
37 const notifier::NotifierOptions& notifier_options, | 39 const notifier::NotifierOptions& notifier_options, |
38 const InvalidationVersionMap& initial_max_invalidation_versions, | 40 const InvalidationVersionMap& initial_max_invalidation_versions, |
39 const std::string& initial_invalidation_state, | 41 const std::string& initial_invalidation_state, |
40 const WeakHandle<InvalidationStateTracker>& | 42 const WeakHandle<InvalidationStateTracker>& |
41 invalidation_state_tracker, | 43 invalidation_state_tracker, |
42 const std::string& client_info); | 44 const std::string& client_info); |
43 | 45 |
44 virtual ~NonBlockingInvalidationNotifier(); | 46 virtual ~NonBlockingInvalidationNotifier(); |
45 | 47 |
46 // SyncNotifier implementation. | 48 // SyncNotifier implementation. |
| 49 virtual void RegisterHandler(SyncNotifierObserver* handler) OVERRIDE; |
47 virtual void UpdateRegisteredIds(SyncNotifierObserver* handler, | 50 virtual void UpdateRegisteredIds(SyncNotifierObserver* handler, |
48 const ObjectIdSet& ids) OVERRIDE; | 51 const ObjectIdSet& ids) OVERRIDE; |
| 52 virtual void UnregisterHandler(SyncNotifierObserver* handler) OVERRIDE; |
49 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; | 53 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; |
50 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; | 54 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; |
51 virtual void UpdateCredentials( | 55 virtual void UpdateCredentials( |
52 const std::string& email, const std::string& token) OVERRIDE; | 56 const std::string& email, const std::string& token) OVERRIDE; |
53 virtual void SendNotification(ModelTypeSet changed_types) OVERRIDE; | 57 virtual void SendNotification(ModelTypeSet changed_types) OVERRIDE; |
54 | 58 |
55 // SyncNotifierObserver implementation. | 59 // SyncNotifierObserver implementation. |
56 virtual void OnNotificationsEnabled() OVERRIDE; | 60 virtual void OnNotificationsEnabled() OVERRIDE; |
57 virtual void OnNotificationsDisabled( | 61 virtual void OnNotificationsDisabled( |
58 NotificationsDisabledReason reason) OVERRIDE; | 62 NotificationsDisabledReason reason) OVERRIDE; |
59 virtual void OnIncomingNotification( | 63 virtual void OnIncomingNotification( |
60 const ObjectIdPayloadMap& id_payloads, | 64 const ObjectIdPayloadMap& id_payloads, |
61 IncomingNotificationSource source) OVERRIDE; | 65 IncomingNotificationSource source) OVERRIDE; |
62 | 66 |
63 private: | 67 private: |
64 class Core; | 68 class Core; |
65 | 69 |
66 base::WeakPtrFactory<NonBlockingInvalidationNotifier> weak_ptr_factory_; | 70 base::WeakPtrFactory<NonBlockingInvalidationNotifier> weak_ptr_factory_; |
67 | 71 |
68 SyncNotifierHelper helper_; | 72 SyncNotifierRegistrar registrar_; |
69 | 73 |
70 // The real guts of NonBlockingInvalidationNotifier, which allows | 74 // The real guts of NonBlockingInvalidationNotifier, which allows |
71 // this class to live completely on the parent thread. | 75 // this class to live completely on the parent thread. |
72 scoped_refptr<Core> core_; | 76 scoped_refptr<Core> core_; |
73 scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_; | 77 scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_; |
74 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 78 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
75 | 79 |
76 DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidationNotifier); | 80 DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidationNotifier); |
77 }; | 81 }; |
78 | 82 |
79 } // namespace syncer | 83 } // namespace syncer |
80 | 84 |
81 #endif // SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ | 85 #endif // SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ |
OLD | NEW |