| 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 <memory> |
| 9 |
| 9 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 10 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
| 11 #include "sync/base/sync_export.h" | 12 #include "sync/base/sync_export.h" |
| 12 #include "sync/internal_api/public/base/model_type.h" | 13 #include "sync/internal_api/public/base/model_type.h" |
| 13 #include "sync/internal_api/public/sync_context_proxy.h" | 14 #include "sync/internal_api/public/sync_context_proxy.h" |
| 14 | 15 |
| 15 namespace syncer_v2 { | 16 namespace syncer_v2 { |
| 16 class SyncContext; | 17 class SyncContext; |
| 17 | 18 |
| 18 // Encapsulates a reference to the sync context and the thread it's running on. | 19 // Encapsulates a reference to the sync context and the thread it's running on. |
| 19 // Used by sync's data types to connect with the sync context. | 20 // Used by sync's data types to connect with the sync context. |
| 20 // | 21 // |
| 21 // It is expected that this object will be copied to and used on many different | 22 // It is expected that this object will be copied to and used on many different |
| 22 // threads. It is small and safe to pass by value. | 23 // threads. It is small and safe to pass by value. |
| 23 class SYNC_EXPORT SyncContextProxyImpl : public SyncContextProxy { | 24 class SYNC_EXPORT SyncContextProxyImpl : public SyncContextProxy { |
| 24 public: | 25 public: |
| 25 SyncContextProxyImpl( | 26 SyncContextProxyImpl( |
| 26 const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner, | 27 const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner, |
| 27 const base::WeakPtr<SyncContext>& sync_context); | 28 const base::WeakPtr<SyncContext>& sync_context); |
| 28 ~SyncContextProxyImpl() override; | 29 ~SyncContextProxyImpl() override; |
| 29 | 30 |
| 30 // Attempts to connect a non-blocking type to the sync context. | 31 // Attempts to connect a non-blocking type to the sync context. |
| 31 // | 32 // |
| 32 // This may fail under some unusual circumstances, like shutdown. Due to the | 33 // This may fail under some unusual circumstances, like shutdown. Due to the |
| 33 // nature of WeakPtrs and cross-thread communication, the caller will be | 34 // nature of WeakPtrs and cross-thread communication, the caller will be |
| 34 // unable to distinguish a slow success from failure. | 35 // unable to distinguish a slow success from failure. |
| 35 void ConnectTypeToSync( | 36 void ConnectTypeToSync( |
| 36 syncer::ModelType type, | 37 syncer::ModelType type, |
| 37 scoped_ptr<ActivationContext> activation_context) override; | 38 std::unique_ptr<ActivationContext> activation_context) override; |
| 38 | 39 |
| 39 // Disables syncing for the given type on the sync thread. | 40 // Disables syncing for the given type on the sync thread. |
| 40 void Disconnect(syncer::ModelType type) override; | 41 void Disconnect(syncer::ModelType type) override; |
| 41 | 42 |
| 42 scoped_ptr<SyncContextProxy> Clone() const override; | 43 std::unique_ptr<SyncContextProxy> Clone() const override; |
| 43 | 44 |
| 44 private: | 45 private: |
| 45 // A SequencedTaskRunner representing the thread where the SyncContext lives. | 46 // A SequencedTaskRunner representing the thread where the SyncContext lives. |
| 46 scoped_refptr<base::SequencedTaskRunner> sync_task_runner_; | 47 scoped_refptr<base::SequencedTaskRunner> sync_task_runner_; |
| 47 | 48 |
| 48 // The SyncContext this object is wrapping. | 49 // The SyncContext this object is wrapping. |
| 49 base::WeakPtr<SyncContext> sync_context_; | 50 base::WeakPtr<SyncContext> sync_context_; |
| 50 }; | 51 }; |
| 51 | 52 |
| 52 } // namespace syncer_v2 | 53 } // namespace syncer_v2 |
| 53 | 54 |
| 54 #endif // SYNC_INTERNAL_API_SYNC_CONTEXT_PROXY_IMPL_H_ | 55 #endif // SYNC_INTERNAL_API_SYNC_CONTEXT_PROXY_IMPL_H_ |
| OLD | NEW |