[email protected] | cc7a544c | 2013-01-02 08:31:51 | [diff] [blame] | 1 | // Copyright 2012 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] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 8 | #ifndef SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_ |
| 9 | #define SYNC_NOTIFIER_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] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 18 | #include "jingle/notifier/base/notifier_options.h" |
[email protected] | cc7a544c | 2013-01-02 08:31:51 | [diff] [blame] | 19 | #include "sync/base/sync_export.h" |
[email protected] | 406203d | 2012-06-17 01:07:19 | [diff] [blame] | 20 | #include "sync/internal_api/public/util/weak_handle.h" |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 21 | #include "sync/notifier/invalidation_handler.h" |
[email protected] | 46e43ee | 2012-05-18 19:24:41 | [diff] [blame] | 22 | #include "sync/notifier/invalidation_state_tracker.h" |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 23 | #include "sync/notifier/invalidator.h" |
| 24 | #include "sync/notifier/invalidator_registrar.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] | cc7a544c | 2013-01-02 08:31:51 | [diff] [blame] | 39 | class SYNC_EXPORT_PRIVATE NonBlockingInvalidator |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 40 | : public Invalidator, |
| 41 | // InvalidationHandler to "observe" our Core via WeakHandle. |
| 42 | public InvalidationHandler { |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 43 | public: |
[email protected] | 46e43ee | 2012-05-18 19:24:41 | [diff] [blame] | 44 | // |invalidation_state_tracker| must be initialized. |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 45 | NonBlockingInvalidator( |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 46 | NetworkChannelCreator network_channel_creator, |
[email protected] | d551123 | 2013-03-28 01:34:54 | [diff] [blame] | 47 | const std::string& invalidator_client_id, |
[email protected] | a7b1639 | 2013-11-26 22:46:26 | [diff] [blame] | 48 | const UnackedInvalidationsMap& saved_invalidations, |
[email protected] | 8cdb689 | 2012-10-03 05:54:40 | [diff] [blame] | 49 | const std::string& invalidation_bootstrap_data, |
[email protected] | d45f0d9 | 2012-07-20 17:25:41 | [diff] [blame] | 50 | const WeakHandle<InvalidationStateTracker>& |
[email protected] | 46e43ee | 2012-05-18 19:24:41 | [diff] [blame] | 51 | invalidation_state_tracker, |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 52 | const std::string& client_info, |
| 53 | const scoped_refptr<net::URLRequestContextGetter>& |
| 54 | request_context_getter); |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 55 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 56 | virtual ~NonBlockingInvalidator(); |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 57 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 58 | // Invalidator implementation. |
| 59 | virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE; |
| 60 | virtual void UpdateRegisteredIds(InvalidationHandler* handler, |
[email protected] | d914f02 | 2012-07-27 02:02:00 | [diff] [blame] | 61 | const ObjectIdSet& ids) OVERRIDE; |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 62 | virtual void UnregisterHandler(InvalidationHandler* handler) OVERRIDE; |
[email protected] | 08a6f999 | 2012-09-07 19:19:16 | [diff] [blame] | 63 | virtual InvalidatorState GetInvalidatorState() const OVERRIDE; |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 64 | virtual void UpdateCredentials( |
[email protected] | 0a561205 | 2011-06-29 03:29:18 | [diff] [blame] | 65 | const std::string& email, const std::string& token) OVERRIDE; |
[email protected] | 5cb5b18 | 2014-03-18 00:32:39 | [diff] [blame] | 66 | virtual void RequestDetailedStatus( |
[email protected] | 40848a9 | 2014-03-24 22:41:02 | [diff] [blame^] | 67 | base::Callback<void(const base::DictionaryValue&)> callback) const |
| 68 | OVERRIDE; |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 69 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 70 | // InvalidationHandler implementation. |
[email protected] | 08a6f999 | 2012-09-07 19:19:16 | [diff] [blame] | 71 | virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE; |
| 72 | virtual void OnIncomingInvalidation( |
[email protected] | 0d0b59d | 2013-02-02 00:24:47 | [diff] [blame] | 73 | const ObjectIdInvalidationMap& invalidation_map) OVERRIDE; |
[email protected] | 9b0d66b | 2014-02-20 13:16:01 | [diff] [blame] | 74 | virtual std::string GetOwnerName() const OVERRIDE; |
[email protected] | b9908a24 | 2011-11-19 09:31:32 | [diff] [blame] | 75 | |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 76 | // Static functions to construct callback that creates network channel for |
| 77 | // SyncSystemResources. The goal is to pass network channel to invalidator at |
| 78 | // the same time not exposing channel specific parameters to invalidator and |
| 79 | // channel implementation to client of invalidator. |
| 80 | static NetworkChannelCreator MakePushClientChannelCreator( |
| 81 | const notifier::NotifierOptions& notifier_options); |
[email protected] | df006cbc | 2014-01-22 18:36:20 | [diff] [blame] | 82 | static NetworkChannelCreator MakeGCMNetworkChannelCreator( |
| 83 | scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 84 | scoped_ptr<GCMNetworkChannelDelegate> delegate); |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 85 | private: |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 86 | struct InitializeOptions; |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 87 | class Core; |
[email protected] | b9908a24 | 2011-11-19 09:31:32 | [diff] [blame] | 88 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 89 | InvalidatorRegistrar registrar_; |
[email protected] | b9908a24 | 2011-11-19 09:31:32 | [diff] [blame] | 90 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 91 | // The real guts of NonBlockingInvalidator, which allows this class to live |
| 92 | // completely on the parent thread. |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 93 | scoped_refptr<Core> core_; |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 94 | scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_; |
| 95 | scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
[email protected] | b9908a24 | 2011-11-19 09:31:32 | [diff] [blame] | 96 | |
[email protected] | 37d5b347 | 2013-10-10 16:20:36 | [diff] [blame] | 97 | base::WeakPtrFactory<NonBlockingInvalidator> weak_ptr_factory_; |
| 98 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 99 | DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidator); |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 100 | }; |
| 101 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 102 | } // namespace syncer |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 103 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 104 | #endif // SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_ |