blob: 47bd216f9d2a82a75c54f76839b3ec848f2d31bd [file] [log] [blame]
[email protected]cc7a544c2013-01-02 08:31:511// Copyright 2012 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]a329cb82012-08-28 03:17:588#ifndef SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_
9#define SYNC_NOTIFIER_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]942e2022011-04-07 22:27:4318#include "jingle/notifier/base/notifier_options.h"
[email protected]cc7a544c2013-01-02 08:31:5119#include "sync/base/sync_export.h"
[email protected]406203d2012-06-17 01:07:1920#include "sync/internal_api/public/util/weak_handle.h"
[email protected]a329cb82012-08-28 03:17:5821#include "sync/notifier/invalidation_handler.h"
[email protected]46e43ee2012-05-18 19:24:4122#include "sync/notifier/invalidation_state_tracker.h"
[email protected]a329cb82012-08-28 03:17:5823#include "sync/notifier/invalidator.h"
24#include "sync/notifier/invalidator_registrar.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]cc7a544c2013-01-02 08:31:5139class SYNC_EXPORT_PRIVATE NonBlockingInvalidator
[email protected]a329cb82012-08-28 03:17:5840 : public Invalidator,
41 // InvalidationHandler to "observe" our Core via WeakHandle.
42 public InvalidationHandler {
[email protected]0a80fed2011-03-24 22:31:4843 public:
[email protected]46e43ee2012-05-18 19:24:4144 // |invalidation_state_tracker| must be initialized.
[email protected]a329cb82012-08-28 03:17:5845 NonBlockingInvalidator(
[email protected]04a830a2014-01-04 02:48:5146 NetworkChannelCreator network_channel_creator,
[email protected]d5511232013-03-28 01:34:5447 const std::string& invalidator_client_id,
[email protected]a7b16392013-11-26 22:46:2648 const UnackedInvalidationsMap& saved_invalidations,
[email protected]8cdb6892012-10-03 05:54:4049 const std::string& invalidation_bootstrap_data,
[email protected]d45f0d92012-07-20 17:25:4150 const WeakHandle<InvalidationStateTracker>&
[email protected]46e43ee2012-05-18 19:24:4151 invalidation_state_tracker,
[email protected]04a830a2014-01-04 02:48:5152 const std::string& client_info,
53 const scoped_refptr<net::URLRequestContextGetter>&
54 request_context_getter);
[email protected]0a80fed2011-03-24 22:31:4855
[email protected]a329cb82012-08-28 03:17:5856 virtual ~NonBlockingInvalidator();
[email protected]0a80fed2011-03-24 22:31:4857
[email protected]a329cb82012-08-28 03:17:5858 // Invalidator implementation.
59 virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE;
60 virtual void UpdateRegisteredIds(InvalidationHandler* handler,
[email protected]d914f022012-07-27 02:02:0061 const ObjectIdSet& ids) OVERRIDE;
[email protected]a329cb82012-08-28 03:17:5862 virtual void UnregisterHandler(InvalidationHandler* handler) OVERRIDE;
[email protected]08a6f9992012-09-07 19:19:1663 virtual InvalidatorState GetInvalidatorState() const OVERRIDE;
[email protected]0a80fed2011-03-24 22:31:4864 virtual void UpdateCredentials(
[email protected]0a5612052011-06-29 03:29:1865 const std::string& email, const std::string& token) OVERRIDE;
[email protected]5cb5b182014-03-18 00:32:3966 virtual void RequestDetailedStatus(
[email protected]40848a92014-03-24 22:41:0267 base::Callback<void(const base::DictionaryValue&)> callback) const
68 OVERRIDE;
[email protected]0a80fed2011-03-24 22:31:4869
[email protected]a329cb82012-08-28 03:17:5870 // InvalidationHandler implementation.
[email protected]08a6f9992012-09-07 19:19:1671 virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE;
72 virtual void OnIncomingInvalidation(
[email protected]0d0b59d2013-02-02 00:24:4773 const ObjectIdInvalidationMap& invalidation_map) OVERRIDE;
[email protected]9b0d66b2014-02-20 13:16:0174 virtual std::string GetOwnerName() const OVERRIDE;
[email protected]b9908a242011-11-19 09:31:3275
[email protected]04a830a2014-01-04 02:48:5176 // 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]df006cbc2014-01-22 18:36:2082 static NetworkChannelCreator MakeGCMNetworkChannelCreator(
83 scoped_refptr<net::URLRequestContextGetter> request_context_getter,
84 scoped_ptr<GCMNetworkChannelDelegate> delegate);
[email protected]0a80fed2011-03-24 22:31:4885 private:
[email protected]04a830a2014-01-04 02:48:5186 struct InitializeOptions;
[email protected]942e2022011-04-07 22:27:4387 class Core;
[email protected]b9908a242011-11-19 09:31:3288
[email protected]a329cb82012-08-28 03:17:5889 InvalidatorRegistrar registrar_;
[email protected]b9908a242011-11-19 09:31:3290
[email protected]a329cb82012-08-28 03:17:5891 // The real guts of NonBlockingInvalidator, which allows this class to live
92 // completely on the parent thread.
[email protected]942e2022011-04-07 22:27:4393 scoped_refptr<Core> core_;
[email protected]4969b0122012-06-16 01:58:2894 scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_;
95 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
[email protected]b9908a242011-11-19 09:31:3296
[email protected]37d5b3472013-10-10 16:20:3697 base::WeakPtrFactory<NonBlockingInvalidator> weak_ptr_factory_;
98
[email protected]a329cb82012-08-28 03:17:5899 DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidator);
[email protected]0a80fed2011-03-24 22:31:48100};
101
[email protected]65f173552012-06-28 22:43:58102} // namespace syncer
[email protected]0a80fed2011-03-24 22:31:48103
[email protected]a329cb82012-08-28 03:17:58104#endif // SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_