[email protected] | 24c9ee5 | 2014-06-02 22:17:50 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | // |
| 5 | // An implementation of SyncNotifier that wraps InvalidationNotifier |
| 6 | // on its own thread. |
| 7 | |
[email protected] | 4482877 | 2014-06-06 02:56:52 | [diff] [blame] | 8 | #ifndef COMPONENTS_INVALIDATION_NON_BLOCKING_INVALIDATOR_H_ |
| 9 | #define COMPONENTS_INVALIDATION_NON_BLOCKING_INVALIDATOR_H_ |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 10 | |
| 11 | #include <string> |
| 12 | |
| 13 | #include "base/basictypes.h" |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 14 | #include "base/callback.h" |
[email protected] | 0a561205 | 2011-06-29 03:29:18 | [diff] [blame] | 15 | #include "base/compiler_specific.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 16 | #include "base/memory/ref_counted.h" |
[email protected] | b9908a24 | 2011-11-19 09:31:32 | [diff] [blame] | 17 | #include "base/memory/weak_ptr.h" |
[email protected] | 4482877 | 2014-06-06 02:56:52 | [diff] [blame] | 18 | #include "components/invalidation/invalidation_export.h" |
[email protected] | 001bbfdc | 2014-07-17 19:28:46 | [diff] [blame] | 19 | #include "components/invalidation/invalidation_state_tracker.h" |
| 20 | #include "components/invalidation/invalidator.h" |
[email protected] | 4482877 | 2014-06-06 02:56:52 | [diff] [blame] | 21 | #include "components/invalidation/invalidator_registrar.h" |
[email protected] | 51766bf | 2014-07-24 01:13:47 | [diff] [blame] | 22 | #include "components/invalidation/invalidator_state.h" |
[email protected] | 001bbfdc | 2014-07-17 19:28:46 | [diff] [blame] | 23 | #include "components/invalidation/unacked_invalidation_set.h" |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 24 | #include "jingle/notifier/base/notifier_options.h" |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 25 | |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 26 | namespace base { |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 27 | class SingleThreadTaskRunner; |
| 28 | } // namespace base |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 29 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 30 | namespace syncer { |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 31 | class SyncNetworkChannel; |
[email protected] | df006cbc | 2014-01-22 18:36:20 | [diff] [blame] | 32 | class GCMNetworkChannelDelegate; |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 33 | |
| 34 | // Callback type for function that creates SyncNetworkChannel. This function |
| 35 | // gets passed into NonBlockingInvalidator constructor. |
| 36 | typedef base::Callback<scoped_ptr<SyncNetworkChannel>(void)> |
| 37 | NetworkChannelCreator; |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 38 | |
[email protected] | 4482877 | 2014-06-06 02:56:52 | [diff] [blame] | 39 | class INVALIDATION_EXPORT_PRIVATE NonBlockingInvalidator |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 40 | : public Invalidator, |
[email protected] | 3ee8ec7 | 2014-04-16 21:38:50 | [diff] [blame] | 41 | public InvalidationStateTracker { |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 42 | public: |
[email protected] | 3ee8ec7 | 2014-04-16 21:38:50 | [diff] [blame] | 43 | // |invalidation_state_tracker| must be initialized and must outlive |this|. |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 44 | NonBlockingInvalidator( |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 45 | NetworkChannelCreator network_channel_creator, |
[email protected] | d551123 | 2013-03-28 01:34:54 | [diff] [blame] | 46 | const std::string& invalidator_client_id, |
[email protected] | a7b1639 | 2013-11-26 22:46:26 | [diff] [blame] | 47 | const UnackedInvalidationsMap& saved_invalidations, |
[email protected] | 8cdb689 | 2012-10-03 05:54:40 | [diff] [blame] | 48 | const std::string& invalidation_bootstrap_data, |
[email protected] | 3ee8ec7 | 2014-04-16 21:38:50 | [diff] [blame] | 49 | InvalidationStateTracker* invalidation_state_tracker, |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 50 | const std::string& client_info, |
| 51 | const scoped_refptr<net::URLRequestContextGetter>& |
| 52 | request_context_getter); |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 53 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 54 | virtual ~NonBlockingInvalidator(); |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 55 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 56 | // Invalidator implementation. |
| 57 | virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE; |
| 58 | virtual void UpdateRegisteredIds(InvalidationHandler* handler, |
[email protected] | d914f02 | 2012-07-27 02:02:00 | [diff] [blame] | 59 | const ObjectIdSet& ids) OVERRIDE; |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 60 | virtual void UnregisterHandler(InvalidationHandler* handler) OVERRIDE; |
[email protected] | 08a6f999 | 2012-09-07 19:19:16 | [diff] [blame] | 61 | virtual InvalidatorState GetInvalidatorState() const OVERRIDE; |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 62 | virtual void UpdateCredentials( |
[email protected] | 0a561205 | 2011-06-29 03:29:18 | [diff] [blame] | 63 | const std::string& email, const std::string& token) OVERRIDE; |
[email protected] | 5cb5b18 | 2014-03-18 00:32:39 | [diff] [blame] | 64 | virtual void RequestDetailedStatus( |
[email protected] | 40848a9 | 2014-03-24 22:41:02 | [diff] [blame] | 65 | base::Callback<void(const base::DictionaryValue&)> callback) const |
| 66 | OVERRIDE; |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 67 | |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 68 | // Static functions to construct callback that creates network channel for |
| 69 | // SyncSystemResources. The goal is to pass network channel to invalidator at |
| 70 | // the same time not exposing channel specific parameters to invalidator and |
| 71 | // channel implementation to client of invalidator. |
| 72 | static NetworkChannelCreator MakePushClientChannelCreator( |
| 73 | const notifier::NotifierOptions& notifier_options); |
[email protected] | df006cbc | 2014-01-22 18:36:20 | [diff] [blame] | 74 | static NetworkChannelCreator MakeGCMNetworkChannelCreator( |
| 75 | scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 76 | scoped_ptr<GCMNetworkChannelDelegate> delegate); |
[email protected] | 3ee8ec7 | 2014-04-16 21:38:50 | [diff] [blame] | 77 | |
| 78 | // These methods are forwarded to the invalidation_state_tracker_. |
| 79 | virtual void ClearAndSetNewClientId(const std::string& data) OVERRIDE; |
| 80 | virtual std::string GetInvalidatorClientId() const OVERRIDE; |
| 81 | virtual void SetBootstrapData(const std::string& data) OVERRIDE; |
| 82 | virtual std::string GetBootstrapData() const OVERRIDE; |
| 83 | virtual void SetSavedInvalidations( |
| 84 | const UnackedInvalidationsMap& states) OVERRIDE; |
| 85 | virtual UnackedInvalidationsMap GetSavedInvalidations() const OVERRIDE; |
| 86 | virtual void Clear() OVERRIDE; |
| 87 | |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 88 | private: |
[email protected] | 3ee8ec7 | 2014-04-16 21:38:50 | [diff] [blame] | 89 | void OnInvalidatorStateChange(InvalidatorState state); |
| 90 | void OnIncomingInvalidation(const ObjectIdInvalidationMap& invalidation_map); |
| 91 | std::string GetOwnerName() const; |
| 92 | |
| 93 | friend class NonBlockingInvalidatorTestDelegate; |
| 94 | |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 95 | struct InitializeOptions; |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 96 | class Core; |
[email protected] | b9908a24 | 2011-11-19 09:31:32 | [diff] [blame] | 97 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 98 | InvalidatorRegistrar registrar_; |
[email protected] | 3ee8ec7 | 2014-04-16 21:38:50 | [diff] [blame] | 99 | InvalidationStateTracker* invalidation_state_tracker_; |
[email protected] | b9908a24 | 2011-11-19 09:31:32 | [diff] [blame] | 100 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 101 | // The real guts of NonBlockingInvalidator, which allows this class to live |
| 102 | // completely on the parent thread. |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 103 | scoped_refptr<Core> core_; |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 104 | scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_; |
| 105 | scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
[email protected] | b9908a24 | 2011-11-19 09:31:32 | [diff] [blame] | 106 | |
[email protected] | 37d5b347 | 2013-10-10 16:20:36 | [diff] [blame] | 107 | base::WeakPtrFactory<NonBlockingInvalidator> weak_ptr_factory_; |
| 108 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 109 | DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidator); |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 110 | }; |
| 111 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 112 | } // namespace syncer |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 113 | |
[email protected] | 4482877 | 2014-06-06 02:56:52 | [diff] [blame] | 114 | #endif // COMPONENTS_INVALIDATION_NON_BLOCKING_INVALIDATOR_H_ |