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" |
21 #include "sync/notifier/sync_notifier_observer.h" | 22 #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). | |
32 class NonBlockingInvalidationNotifier | 30 class NonBlockingInvalidationNotifier |
33 : public SyncNotifier, | 31 : public SyncNotifier, |
34 // SyncNotifierObserver to "observe" our Core via WeakHandle. | 32 // SyncNotifierObserver to "observe" our Core via WeakHandle. |
35 public SyncNotifierObserver { | 33 public SyncNotifierObserver { |
36 public: | 34 public: |
37 // |invalidation_state_tracker| must be initialized. | 35 // |invalidation_state_tracker| must be initialized. |
38 NonBlockingInvalidationNotifier( | 36 NonBlockingInvalidationNotifier( |
39 const notifier::NotifierOptions& notifier_options, | 37 const notifier::NotifierOptions& notifier_options, |
40 const InvalidationVersionMap& initial_max_invalidation_versions, | 38 const InvalidationVersionMap& initial_max_invalidation_versions, |
41 const std::string& initial_invalidation_state, | 39 const std::string& initial_invalidation_state, |
42 const WeakHandle<InvalidationStateTracker>& | 40 const WeakHandle<InvalidationStateTracker>& |
43 invalidation_state_tracker, | 41 invalidation_state_tracker, |
44 const std::string& client_info); | 42 const std::string& client_info); |
45 | 43 |
46 virtual ~NonBlockingInvalidationNotifier(); | 44 virtual ~NonBlockingInvalidationNotifier(); |
47 | 45 |
48 // SyncNotifier implementation. | 46 // SyncNotifier implementation. |
49 virtual void RegisterHandler(SyncNotifierObserver* handler) OVERRIDE; | |
50 virtual void UpdateRegisteredIds(SyncNotifierObserver* handler, | 47 virtual void UpdateRegisteredIds(SyncNotifierObserver* handler, |
51 const ObjectIdSet& ids) OVERRIDE; | 48 const ObjectIdSet& ids) OVERRIDE; |
52 virtual void UnregisterHandler(SyncNotifierObserver* handler) OVERRIDE; | |
53 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; | 49 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; |
54 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; | 50 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; |
55 virtual void UpdateCredentials( | 51 virtual void UpdateCredentials( |
56 const std::string& email, const std::string& token) OVERRIDE; | 52 const std::string& email, const std::string& token) OVERRIDE; |
57 virtual void SendNotification(ModelTypeSet changed_types) OVERRIDE; | 53 virtual void SendNotification(ModelTypeSet changed_types) OVERRIDE; |
58 | 54 |
59 // SyncNotifierObserver implementation. | 55 // SyncNotifierObserver implementation. |
60 virtual void OnNotificationsEnabled() OVERRIDE; | 56 virtual void OnNotificationsEnabled() OVERRIDE; |
61 virtual void OnNotificationsDisabled( | 57 virtual void OnNotificationsDisabled( |
62 NotificationsDisabledReason reason) OVERRIDE; | 58 NotificationsDisabledReason reason) OVERRIDE; |
63 virtual void OnIncomingNotification( | 59 virtual void OnIncomingNotification( |
64 const ObjectIdPayloadMap& id_payloads, | 60 const ObjectIdPayloadMap& id_payloads, |
65 IncomingNotificationSource source) OVERRIDE; | 61 IncomingNotificationSource source) OVERRIDE; |
66 | 62 |
67 private: | 63 private: |
68 class Core; | 64 class Core; |
69 | 65 |
70 base::WeakPtrFactory<NonBlockingInvalidationNotifier> weak_ptr_factory_; | 66 base::WeakPtrFactory<NonBlockingInvalidationNotifier> weak_ptr_factory_; |
71 | 67 |
72 SyncNotifierRegistrar registrar_; | 68 SyncNotifierHelper helper_; |
73 | 69 |
74 // The real guts of NonBlockingInvalidationNotifier, which allows | 70 // The real guts of NonBlockingInvalidationNotifier, which allows |
75 // this class to live completely on the parent thread. | 71 // this class to live completely on the parent thread. |
76 scoped_refptr<Core> core_; | 72 scoped_refptr<Core> core_; |
77 scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_; | 73 scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_; |
78 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 74 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
79 | 75 |
80 DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidationNotifier); | 76 DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidationNotifier); |
81 }; | 77 }; |
82 | 78 |
83 } // namespace syncer | 79 } // namespace syncer |
84 | 80 |
85 #endif // SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ | 81 #endif // SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ |
OLD | NEW |