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