summaryrefslogtreecommitdiffstats
path: root/sync/internal_api/sync_context_proxy_impl.h
blob: bde38e4a5edab2376ce35efd635d96488ed40d87 (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
// 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 SYNC_INTERNAL_API_SYNC_CONTEXT_PROXY_IMPL_H_
#define SYNC_INTERNAL_API_SYNC_CONTEXT_PROXY_IMPL_H_

#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/sequenced_task_runner.h"
#include "sync/base/sync_export.h"
#include "sync/internal_api/public/base/model_type.h"
#include "sync/internal_api/public/sync_context_proxy.h"

namespace syncer_v2 {
class SyncContext;

// Encapsulates a reference to the sync context and the thread it's running on.
// Used by sync's data types to connect with the sync context.
//
// It is expected that this object will be copied to and used on many different
// threads.  It is small and safe to pass by value.
class SYNC_EXPORT SyncContextProxyImpl : public SyncContextProxy {
 public:
  SyncContextProxyImpl(
      const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner,
      const base::WeakPtr<SyncContext>& sync_context);
  ~SyncContextProxyImpl() override;

  // Attempts to connect a non-blocking type to the sync context.
  //
  // This may fail under some unusual circumstances, like shutdown.  Due to the
  // nature of WeakPtrs and cross-thread communication, the caller will be
  // unable to distinguish a slow success from failure.
  void ConnectTypeToSync(
      syncer::ModelType type,
      scoped_ptr<ActivationContext> activation_context) override;

  // Disables syncing for the given type on the sync thread.
  void Disconnect(syncer::ModelType type) override;

  scoped_ptr<SyncContextProxy> Clone() const override;

 private:
  // A SequencedTaskRunner representing the thread where the SyncContext lives.
  scoped_refptr<base::SequencedTaskRunner> sync_task_runner_;

  // The SyncContext this object is wrapping.
  base::WeakPtr<SyncContext> sync_context_;
};

}  // namespace syncer_v2

#endif  // SYNC_INTERNAL_API_SYNC_CONTEXT_PROXY_IMPL_H_