summaryrefslogtreecommitdiffstats
path: root/components/sync_driver/non_blocking_data_type_manager.h
blob: acd6e5f30aa958c6d53000197305f08266b35384 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_SYNC_DRIVER_NON_BLOCKING_DATA_TYPE_MANAGER_H_
#define COMPONENTS_SYNC_DRIVER_NON_BLOCKING_DATA_TYPE_MANAGER_H_

#include "base/containers/scoped_ptr_map.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "sync/internal_api/public/base/model_type.h"

namespace base {
class SequencedTaskRunner;
}  // namespace base

namespace syncer_v2 {
class ModelTypeSyncProxyImpl;
class SyncContextProxy;
}  // namespace syncer_v2

namespace sync_driver {

class NonBlockingDataTypeController;

// Manages a set of NonBlockingDataTypeControllers.
//
// Each NonBlockingDataTypeController instance handles the logic around
// enabling and disabling sync for a particular non-blocking type.  This class
// manages all the controllers.
class NonBlockingDataTypeManager {
 public:
  NonBlockingDataTypeManager();
  ~NonBlockingDataTypeManager();

  // Declares |type| as a non-blocking type.  Should be done early
  // on during sync initialization.
  //
  // The |preferred| flag indicates whether or not this type should be synced.
  void RegisterType(syncer::ModelType type, bool preferred);

  // Connects the ModelTypeSyncProxyImpl and associated model type
  // thread to its NonBlockingDataTypeController on the UI thread.
  void InitializeType(
      syncer::ModelType type,
      const scoped_refptr<base::SequencedTaskRunner>& task_runner,
      const base::WeakPtr<syncer_v2::ModelTypeSyncProxyImpl>& type_sync_proxy);

  // Connects the sync backend, as represented by a SyncContextProxy, to the
  // NonBlockingDataTypeController on the UI thread.
  void ConnectSyncBackend(scoped_ptr<syncer_v2::SyncContextProxy> proxy);

  // Disconnects the sync backend from the UI thread.  Should be called
  // early on during shutdown, but the whole procedure is asynchronous so
  // there's not much downside to calling it later.
  void DisconnectSyncBackend();

  // Updates the set of types the user wants to have synced.
  void SetPreferredTypes(syncer::ModelTypeSet types);

  // Returns the list of all known non-blocking sync types that registered with
  // RegisterType.
  syncer::ModelTypeSet GetRegisteredTypes() const;

 private:
  typedef base::ScopedPtrMap<syncer::ModelType,
                             scoped_ptr<NonBlockingDataTypeController>>
      NonBlockingDataTypeControllerMap;

  // List of data type controllers for non-blocking types.
  NonBlockingDataTypeControllerMap non_blocking_data_type_controllers_;
};

}  // namespace sync_driver

#endif  // COMPONENTS_SYNC_DRIVER_NON_BLOCKING_DATA_TYPE_MANAGER_H_