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_TEST_ENGINE_INJECTABLE_SYNC_CONTEXT_PROXY_H_ 6 #define SYNC_TEST_ENGINE_INJECTABLE_SYNC_CONTEXT_PROXY_H_ 7 8 #include "sync/internal_api/public/base/model_type.h" 9 #include "sync/internal_api/public/non_blocking_sync_common.h" 10 #include "sync/internal_api/public/sync_context_proxy.h" 11 12 namespace syncer { 13 14 struct DataTypeState; 15 class ModelTypeSyncProxyImpl; 16 class ModelTypeSyncWorker; 17 18 // A SyncContextProxy implementation that, when a connection request is made, 19 // initalizes a connection to a previously injected ModelTypeSyncProxyImpl. 20 class InjectableSyncContextProxy : public syncer::SyncContextProxy { 21 public: 22 explicit InjectableSyncContextProxy(ModelTypeSyncWorker* worker); 23 virtual ~InjectableSyncContextProxy(); 24 25 virtual void ConnectTypeToSync( 26 syncer::ModelType type, 27 const DataTypeState& data_type_state, 28 const UpdateResponseDataList& pending_updates, 29 const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& type_sync_proxy) 30 OVERRIDE; 31 virtual void Disconnect(syncer::ModelType type) OVERRIDE; 32 virtual scoped_ptr<SyncContextProxy> Clone() const OVERRIDE; 33 34 ModelTypeSyncWorker* GetWorker(); 35 36 private: 37 // A flag to ensure ConnectTypeToSync is called at most once. 38 bool is_worker_connected_; 39 40 // The ModelTypeSyncProxy's contract expects that it gets to own this object, 41 // so we can retain only a non-owned pointer to it. 42 // 43 // This is very unsafe, but we can get away with it since these tests are not 44 // exercising the proxy <-> worker connection code. 45 ModelTypeSyncWorker* worker_; 46 }; 47 48 } // namespace syncer 49 50 #endif // SYNC_TEST_ENGINE_INJECTABLE_SYNC_CONTEXT_PROXY_H_ 51