blob: ab19ce1b54dd9fa2df4b5fb95a774dbc84459c27 [file] [log] [blame]
[email protected]24c9ee52014-06-02 22:17:501// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]0a80fed2011-03-24 22:31:482// 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]44828772014-06-06 02:56:528#ifndef COMPONENTS_INVALIDATION_NON_BLOCKING_INVALIDATOR_H_
9#define COMPONENTS_INVALIDATION_NON_BLOCKING_INVALIDATOR_H_
[email protected]0a80fed2011-03-24 22:31:4810
11#include <string>
12
13#include "base/basictypes.h"
[email protected]04a830a2014-01-04 02:48:5114#include "base/callback.h"
[email protected]0a5612052011-06-29 03:29:1815#include "base/compiler_specific.h"
[email protected]3b63f8f42011-03-28 01:54:1516#include "base/memory/ref_counted.h"
[email protected]b9908a242011-11-19 09:31:3217#include "base/memory/weak_ptr.h"
[email protected]44828772014-06-06 02:56:5218#include "components/invalidation/invalidation_export.h"
[email protected]001bbfdc2014-07-17 19:28:4619#include "components/invalidation/invalidation_state_tracker.h"
20#include "components/invalidation/invalidator.h"
[email protected]44828772014-06-06 02:56:5221#include "components/invalidation/invalidator_registrar.h"
[email protected]51766bf2014-07-24 01:13:4722#include "components/invalidation/invalidator_state.h"
[email protected]001bbfdc2014-07-17 19:28:4623#include "components/invalidation/unacked_invalidation_set.h"
[email protected]942e2022011-04-07 22:27:4324#include "jingle/notifier/base/notifier_options.h"
[email protected]0a80fed2011-03-24 22:31:4825
[email protected]942e2022011-04-07 22:27:4326namespace base {
[email protected]4969b0122012-06-16 01:58:2827class SingleThreadTaskRunner;
28} // namespace base
[email protected]0a80fed2011-03-24 22:31:4829
[email protected]65f173552012-06-28 22:43:5830namespace syncer {
[email protected]04a830a2014-01-04 02:48:5131class SyncNetworkChannel;
[email protected]df006cbc2014-01-22 18:36:2032class GCMNetworkChannelDelegate;
[email protected]04a830a2014-01-04 02:48:5133
34// Callback type for function that creates SyncNetworkChannel. This function
35// gets passed into NonBlockingInvalidator constructor.
36typedef base::Callback<scoped_ptr<SyncNetworkChannel>(void)>
37 NetworkChannelCreator;
[email protected]0a80fed2011-03-24 22:31:4838
[email protected]44828772014-06-06 02:56:5239class INVALIDATION_EXPORT_PRIVATE NonBlockingInvalidator
[email protected]a329cb82012-08-28 03:17:5840 : public Invalidator,
[email protected]3ee8ec72014-04-16 21:38:5041 public InvalidationStateTracker {
[email protected]0a80fed2011-03-24 22:31:4842 public:
[email protected]3ee8ec72014-04-16 21:38:5043 // |invalidation_state_tracker| must be initialized and must outlive |this|.
[email protected]a329cb82012-08-28 03:17:5844 NonBlockingInvalidator(
[email protected]04a830a2014-01-04 02:48:5145 NetworkChannelCreator network_channel_creator,
[email protected]d5511232013-03-28 01:34:5446 const std::string& invalidator_client_id,
[email protected]a7b16392013-11-26 22:46:2647 const UnackedInvalidationsMap& saved_invalidations,
[email protected]8cdb6892012-10-03 05:54:4048 const std::string& invalidation_bootstrap_data,
[email protected]3ee8ec72014-04-16 21:38:5049 InvalidationStateTracker* invalidation_state_tracker,
[email protected]04a830a2014-01-04 02:48:5150 const std::string& client_info,
51 const scoped_refptr<net::URLRequestContextGetter>&
52 request_context_getter);
[email protected]0a80fed2011-03-24 22:31:4853
[email protected]a329cb82012-08-28 03:17:5854 virtual ~NonBlockingInvalidator();
[email protected]0a80fed2011-03-24 22:31:4855
[email protected]a329cb82012-08-28 03:17:5856 // Invalidator implementation.
57 virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE;
58 virtual void UpdateRegisteredIds(InvalidationHandler* handler,
[email protected]d914f022012-07-27 02:02:0059 const ObjectIdSet& ids) OVERRIDE;
[email protected]a329cb82012-08-28 03:17:5860 virtual void UnregisterHandler(InvalidationHandler* handler) OVERRIDE;
[email protected]08a6f9992012-09-07 19:19:1661 virtual InvalidatorState GetInvalidatorState() const OVERRIDE;
[email protected]0a80fed2011-03-24 22:31:4862 virtual void UpdateCredentials(
[email protected]0a5612052011-06-29 03:29:1863 const std::string& email, const std::string& token) OVERRIDE;
[email protected]5cb5b182014-03-18 00:32:3964 virtual void RequestDetailedStatus(
[email protected]40848a92014-03-24 22:41:0265 base::Callback<void(const base::DictionaryValue&)> callback) const
66 OVERRIDE;
[email protected]0a80fed2011-03-24 22:31:4867
[email protected]04a830a2014-01-04 02:48:5168 // 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]df006cbc2014-01-22 18:36:2074 static NetworkChannelCreator MakeGCMNetworkChannelCreator(
75 scoped_refptr<net::URLRequestContextGetter> request_context_getter,
76 scoped_ptr<GCMNetworkChannelDelegate> delegate);
[email protected]3ee8ec72014-04-16 21:38:5077
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]0a80fed2011-03-24 22:31:4888 private:
[email protected]3ee8ec72014-04-16 21:38:5089 void OnInvalidatorStateChange(InvalidatorState state);
90 void OnIncomingInvalidation(const ObjectIdInvalidationMap& invalidation_map);
91 std::string GetOwnerName() const;
92
93 friend class NonBlockingInvalidatorTestDelegate;
94
[email protected]04a830a2014-01-04 02:48:5195 struct InitializeOptions;
[email protected]942e2022011-04-07 22:27:4396 class Core;
[email protected]b9908a242011-11-19 09:31:3297
[email protected]a329cb82012-08-28 03:17:5898 InvalidatorRegistrar registrar_;
[email protected]3ee8ec72014-04-16 21:38:5099 InvalidationStateTracker* invalidation_state_tracker_;
[email protected]b9908a242011-11-19 09:31:32100
[email protected]a329cb82012-08-28 03:17:58101 // The real guts of NonBlockingInvalidator, which allows this class to live
102 // completely on the parent thread.
[email protected]942e2022011-04-07 22:27:43103 scoped_refptr<Core> core_;
[email protected]4969b0122012-06-16 01:58:28104 scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_;
105 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
[email protected]b9908a242011-11-19 09:31:32106
[email protected]37d5b3472013-10-10 16:20:36107 base::WeakPtrFactory<NonBlockingInvalidator> weak_ptr_factory_;
108
[email protected]a329cb82012-08-28 03:17:58109 DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidator);
[email protected]0a80fed2011-03-24 22:31:48110};
111
[email protected]65f173552012-06-28 22:43:58112} // namespace syncer
[email protected]0a80fed2011-03-24 22:31:48113
[email protected]44828772014-06-06 02:56:52114#endif // COMPONENTS_INVALIDATION_NON_BLOCKING_INVALIDATOR_H_