Adding myself to authors file
[chromium-blink-merge.git] / sync / internal_api / sync_context_proxy_impl.h
blob2bd6ba6ac370150290a09110e5627c7f08f68e0b
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef SYNC_INTERNAL_API_SYNC_CONTEXT_PROXY_IMPL_H_
6 #define SYNC_INTERNAL_API_SYNC_CONTEXT_PROXY_IMPL_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/sequenced_task_runner.h"
11 #include "sync/base/sync_export.h"
12 #include "sync/internal_api/public/base/model_type.h"
13 #include "sync/internal_api/public/sync_context_proxy.h"
15 namespace syncer {
17 class SyncContext;
18 class ModelTypeSyncProxyImpl;
19 struct DataTypeState;
21 // Encapsulates a reference to the sync context and the thread it's running on.
22 // Used by sync's data types to connect with the sync context.
24 // It is expected that this object will be copied to and used on many different
25 // threads. It is small and safe to pass by value.
26 class SYNC_EXPORT_PRIVATE SyncContextProxyImpl : public SyncContextProxy {
27 public:
28 SyncContextProxyImpl(
29 const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner,
30 const base::WeakPtr<SyncContext>& sync_context);
31 ~SyncContextProxyImpl() override;
33 // Attempts to connect a non-blocking type to the sync context.
35 // This may fail under some unusual circumstances, like shutdown. Due to the
36 // nature of WeakPtrs and cross-thread communication, the caller will be
37 // unable to distinguish a slow success from failure.
39 // Must be called from the thread where the data type lives.
40 void ConnectTypeToSync(
41 syncer::ModelType type,
42 const DataTypeState& data_type_state,
43 const UpdateResponseDataList& pending_updates,
44 const base::WeakPtr<ModelTypeSyncProxyImpl>& sync_proxy_impl) override;
46 // Disables syncing for the given type on the sync thread.
47 void Disconnect(syncer::ModelType type) override;
49 scoped_ptr<SyncContextProxy> Clone() const override;
51 private:
52 // A SequencedTaskRunner representing the thread where the SyncContext lives.
53 scoped_refptr<base::SequencedTaskRunner> sync_task_runner_;
55 // The SyncContext this object is wrapping.
56 base::WeakPtr<SyncContext> sync_context_;
59 } // namespace syncer
61 #endif // SYNC_INTERNAL_API_SYNC_CONTEXT_PROXY_IMPL_H_