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. 4 5 #ifndef SYNC_INTERNAL_API_SYNC_CORE_PROXY_IMPL_H_ 6 #define SYNC_INTERNAL_API_SYNC_CORE_PROXY_IMPL_H_ 7 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_core_proxy.h" 14 15 namespace syncer { 16 17 class SyncCore; 18 class NonBlockingTypeProcessor; 19 struct DataTypeState; 20 21 // Encapsulates a reference to the sync core and the thread it's running on. 22 // Used by sync's data types to connect with the sync core. 23 // 24 // It is epxected 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 SyncCoreProxyImpl : public SyncCoreProxy { 27 public: 28 SyncCoreProxyImpl( 29 scoped_refptr<base::SequencedTaskRunner> sync_task_runner, 30 base::WeakPtr<SyncCore> sync_core); 31 virtual ~SyncCoreProxyImpl(); 32 33 // Attempts to connect a non-blocking type to the sync core. 34 // 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. 38 // 39 // Must be called from the thread where the data type lives. 40 virtual void ConnectTypeToCore( 41 syncer::ModelType type, 42 const DataTypeState& data_type_state, 43 base::WeakPtr<NonBlockingTypeProcessor> type_processor) OVERRIDE; 44 45 // Disables syncing for the given type on the sync thread. 46 virtual void Disconnect(syncer::ModelType type) OVERRIDE; 47 48 virtual scoped_ptr<SyncCoreProxy> Clone() const OVERRIDE; 49 50 private: 51 // A SequencedTaskRunner representing the thread where the SyncCore lives. 52 scoped_refptr<base::SequencedTaskRunner> sync_task_runner_; 53 54 // The SyncCore this object is wrapping. 55 base::WeakPtr<SyncCore> sync_core_; 56 }; 57 58 } // namespace syncer 59 60 #endif // SYNC_INTERNAL_API_SYNC_CORE_PROXY_IMPL_H_ 61