| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_CORE_H_ | 5 #ifndef COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_CORE_H_ |
| 6 #define COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_CORE_H_ | 6 #define COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_CORE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/threading/thread_checker.h" |
| 17 #include "base/timer/timer.h" | 19 #include "base/timer/timer.h" |
| 18 #include "base/trace_event/memory_dump_provider.h" | 20 #include "base/trace_event/memory_dump_provider.h" |
| 19 #include "components/invalidation/public/invalidation.h" | 21 #include "components/invalidation/public/invalidation.h" |
| 20 #include "components/sync/base/cancelation_signal.h" | 22 #include "components/sync/base/cancelation_signal.h" |
| 21 #include "components/sync/base/system_encryptor.h" | 23 #include "components/sync/base/system_encryptor.h" |
| 22 #include "components/sync/driver/glue/sync_backend_host_impl.h" | 24 #include "components/sync/driver/glue/sync_backend_host_impl.h" |
| 23 #include "components/sync/engine/cycle/type_debug_info_observer.h" | 25 #include "components/sync/engine/cycle/type_debug_info_observer.h" |
| 24 #include "components/sync/engine/shutdown_reason.h" | 26 #include "components/sync/engine/shutdown_reason.h" |
| 25 #include "components/sync/engine/sync_encryption_handler.h" | 27 #include "components/sync/engine/sync_encryption_handler.h" |
| 26 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 27 | 29 |
| 28 namespace syncer { | 30 namespace syncer { |
| 29 | 31 |
| 30 class SyncBackendHostImpl; | 32 class SyncBackendHostImpl; |
| 31 | 33 |
| 32 // Utility struct for holding initialization options. | 34 // Utility struct for holding initialization options. |
| 33 struct DoInitializeOptions { | 35 struct DoInitializeOptions { |
| 34 DoInitializeOptions( | 36 DoInitializeOptions( |
| 35 base::MessageLoop* sync_loop, | 37 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner, |
| 36 SyncBackendRegistrar* registrar, | 38 SyncBackendRegistrar* registrar, |
| 37 const std::vector<scoped_refptr<ModelSafeWorker>>& workers, | 39 const std::vector<scoped_refptr<ModelSafeWorker>>& workers, |
| 38 const scoped_refptr<ExtensionsActivity>& extensions_activity, | 40 const scoped_refptr<ExtensionsActivity>& extensions_activity, |
| 39 const WeakHandle<JsEventHandler>& event_handler, | 41 const WeakHandle<JsEventHandler>& event_handler, |
| 40 const GURL& service_url, | 42 const GURL& service_url, |
| 41 const std::string& sync_user_agent, | 43 const std::string& sync_user_agent, |
| 42 std::unique_ptr<HttpPostProviderFactory> http_bridge_factory, | 44 std::unique_ptr<HttpPostProviderFactory> http_bridge_factory, |
| 43 const SyncCredentials& credentials, | 45 const SyncCredentials& credentials, |
| 44 const std::string& invalidator_client_id, | 46 const std::string& invalidator_client_id, |
| 45 std::unique_ptr<SyncManagerFactory> sync_manager_factory, | 47 std::unique_ptr<SyncManagerFactory> sync_manager_factory, |
| 46 bool delete_sync_data_folder, | 48 bool delete_sync_data_folder, |
| 47 bool enable_local_sync_backend, | 49 bool enable_local_sync_backend, |
| 48 const base::FilePath& local_sync_backend_folder, | 50 const base::FilePath& local_sync_backend_folder, |
| 49 const std::string& restored_key_for_bootstrapping, | 51 const std::string& restored_key_for_bootstrapping, |
| 50 const std::string& restored_keystore_key_for_bootstrapping, | 52 const std::string& restored_keystore_key_for_bootstrapping, |
| 51 std::unique_ptr<EngineComponentsFactory> engine_components_factory, | 53 std::unique_ptr<EngineComponentsFactory> engine_components_factory, |
| 52 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler, | 54 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler, |
| 53 const base::Closure& report_unrecoverable_error_function, | 55 const base::Closure& report_unrecoverable_error_function, |
| 54 std::unique_ptr<SyncEncryptionHandler::NigoriState> saved_nigori_state, | 56 std::unique_ptr<SyncEncryptionHandler::NigoriState> saved_nigori_state, |
| 55 const std::map<ModelType, int64_t>& invalidation_versions); | 57 const std::map<ModelType, int64_t>& invalidation_versions); |
| 56 ~DoInitializeOptions(); | 58 ~DoInitializeOptions(); |
| 57 | 59 |
| 58 base::MessageLoop* sync_loop; | 60 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner; |
| 59 SyncBackendRegistrar* registrar; | 61 SyncBackendRegistrar* registrar; |
| 60 std::vector<scoped_refptr<ModelSafeWorker>> workers; | 62 std::vector<scoped_refptr<ModelSafeWorker>> workers; |
| 61 scoped_refptr<ExtensionsActivity> extensions_activity; | 63 scoped_refptr<ExtensionsActivity> extensions_activity; |
| 62 WeakHandle<JsEventHandler> event_handler; | 64 WeakHandle<JsEventHandler> event_handler; |
| 63 GURL service_url; | 65 GURL service_url; |
| 64 std::string sync_user_agent; | 66 std::string sync_user_agent; |
| 65 // Overridden by tests. | 67 // Overridden by tests. |
| 66 std::unique_ptr<HttpPostProviderFactory> http_bridge_factory; | 68 std::unique_ptr<HttpPostProviderFactory> http_bridge_factory; |
| 67 SyncCredentials credentials; | 69 SyncCredentials credentials; |
| 68 const std::string invalidator_client_id; | 70 const std::string invalidator_client_id; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 94 | 96 |
| 95 class SyncBackendHostCore | 97 class SyncBackendHostCore |
| 96 : public base::RefCountedThreadSafe<SyncBackendHostCore>, | 98 : public base::RefCountedThreadSafe<SyncBackendHostCore>, |
| 97 public base::trace_event::MemoryDumpProvider, | 99 public base::trace_event::MemoryDumpProvider, |
| 98 public SyncEncryptionHandler::Observer, | 100 public SyncEncryptionHandler::Observer, |
| 99 public SyncManager::Observer, | 101 public SyncManager::Observer, |
| 100 public TypeDebugInfoObserver { | 102 public TypeDebugInfoObserver { |
| 101 public: | 103 public: |
| 102 SyncBackendHostCore(const std::string& name, | 104 SyncBackendHostCore(const std::string& name, |
| 103 const base::FilePath& sync_data_folder_path, | 105 const base::FilePath& sync_data_folder_path, |
| 104 bool has_sync_setup_completed, | |
| 105 const base::WeakPtr<SyncBackendHostImpl>& backend); | 106 const base::WeakPtr<SyncBackendHostImpl>& backend); |
| 106 | 107 |
| 107 // MemoryDumpProvider implementation. | 108 // MemoryDumpProvider implementation. |
| 108 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | 109 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
| 109 base::trace_event::ProcessMemoryDump* pmd) override; | 110 base::trace_event::ProcessMemoryDump* pmd) override; |
| 110 | 111 |
| 111 // SyncManager::Observer implementation. The Core just acts like an air | 112 // SyncManager::Observer implementation. The Core just acts like an air |
| 112 // traffic controller here, forwarding incoming messages to appropriate | 113 // traffic controller here, forwarding incoming messages to appropriate |
| 113 // landing threads. | 114 // landing threads. |
| 114 void OnSyncCycleCompleted(const SyncCycleSnapshot& snapshot) override; | 115 void OnSyncCycleCompleted(const SyncCycleSnapshot& snapshot) override; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 | 271 |
| 271 // Name used for debugging. | 272 // Name used for debugging. |
| 272 const std::string name_; | 273 const std::string name_; |
| 273 | 274 |
| 274 // Path of the folder that stores the sync data files. | 275 // Path of the folder that stores the sync data files. |
| 275 const base::FilePath sync_data_folder_path_; | 276 const base::FilePath sync_data_folder_path_; |
| 276 | 277 |
| 277 // Our parent SyncBackendHost. | 278 // Our parent SyncBackendHost. |
| 278 WeakHandle<SyncBackendHostImpl> host_; | 279 WeakHandle<SyncBackendHostImpl> host_; |
| 279 | 280 |
| 280 // The loop where all the sync backend operations happen. | |
| 281 // Non-null only between calls to DoInitialize() and ~Core(). | |
| 282 base::MessageLoop* sync_loop_; | |
| 283 | |
| 284 // Our parent's registrar (not owned). Non-null only between | 281 // Our parent's registrar (not owned). Non-null only between |
| 285 // calls to DoInitialize() and DoShutdown(). | 282 // calls to DoInitialize() and DoShutdown(). |
| 286 SyncBackendRegistrar* registrar_; | 283 SyncBackendRegistrar* registrar_ = nullptr; |
| 287 | 284 |
| 288 // The timer used to periodically call SaveChanges. | 285 // The timer used to periodically call SaveChanges. |
| 289 std::unique_ptr<base::RepeatingTimer> save_changes_timer_; | 286 std::unique_ptr<base::RepeatingTimer> save_changes_timer_; |
| 290 | 287 |
| 291 // Our encryptor, which uses Chrome's encryption functions. | 288 // Our encryptor, which uses Chrome's encryption functions. |
| 292 SystemEncryptor encryptor_; | 289 SystemEncryptor encryptor_; |
| 293 | 290 |
| 294 // The top-level syncapi entry point. Lives on the sync thread. | 291 // The top-level syncapi entry point. Lives on the sync thread. |
| 295 std::unique_ptr<SyncManager> sync_manager_; | 292 std::unique_ptr<SyncManager> sync_manager_; |
| 296 | 293 |
| 297 // Temporary holder of sync manager's initialization results. Set by | 294 // Temporary holder of sync manager's initialization results. Set by |
| 298 // OnInitializeComplete, and consumed when we pass it via OnBackendInitialized | 295 // OnInitializeComplete, and consumed when we pass it via OnBackendInitialized |
| 299 // in the final state of HandleInitializationSuccessOnFrontendLoop. | 296 // in the final state of HandleInitializationSuccessOnFrontendLoop. |
| 300 WeakHandle<JsBackend> js_backend_; | 297 WeakHandle<JsBackend> js_backend_; |
| 301 WeakHandle<DataTypeDebugInfoListener> debug_info_listener_; | 298 WeakHandle<DataTypeDebugInfoListener> debug_info_listener_; |
| 302 | 299 |
| 303 // These signals allow us to send requests to shut down the HttpBridgeFactory | 300 // These signals allow us to send requests to shut down the HttpBridgeFactory |
| 304 // and ServerConnectionManager without having to wait for those classes to | 301 // and ServerConnectionManager without having to wait for those classes to |
| 305 // finish initializing first. | 302 // finish initializing first. |
| 306 // | 303 // |
| 307 // See comments in SyncBackendHostCore::ShutdownOnUIThread() for more details. | 304 // See comments in SyncBackendHostCore::ShutdownOnUIThread() for more details. |
| 308 CancelationSignal release_request_context_signal_; | 305 CancelationSignal release_request_context_signal_; |
| 309 CancelationSignal stop_syncing_signal_; | 306 CancelationSignal stop_syncing_signal_; |
| 310 | 307 |
| 311 // Matches the value of SyncPref's IsFirstSetupComplete() flag at init time. | |
| 312 // Should not be used for anything except for UMAs and logging. | |
| 313 const bool has_sync_setup_completed_; | |
| 314 | |
| 315 // Set when we've been asked to forward sync protocol events to the frontend. | 308 // Set when we've been asked to forward sync protocol events to the frontend. |
| 316 bool forward_protocol_events_; | 309 bool forward_protocol_events_ = false; |
| 317 | 310 |
| 318 // Set when the forwarding of per-type debug counters is enabled. | 311 // Set when the forwarding of per-type debug counters is enabled. |
| 319 bool forward_type_info_; | 312 bool forward_type_info_ = false; |
| 320 | 313 |
| 321 // A map of data type -> invalidation version to track the most recently | 314 // A map of data type -> invalidation version to track the most recently |
| 322 // received invalidation version for each type. | 315 // received invalidation version for each type. |
| 323 // This allows dropping any invalidations with versions older than those | 316 // This allows dropping any invalidations with versions older than those |
| 324 // most recently received for that data type. | 317 // most recently received for that data type. |
| 325 std::map<ModelType, int64_t> last_invalidation_versions_; | 318 std::map<ModelType, int64_t> last_invalidation_versions_; |
| 326 | 319 |
| 320 // Checks that we are on the sync thread. |
| 321 base::ThreadChecker thread_checker_; |
| 322 |
| 327 base::WeakPtrFactory<SyncBackendHostCore> weak_ptr_factory_; | 323 base::WeakPtrFactory<SyncBackendHostCore> weak_ptr_factory_; |
| 328 | 324 |
| 329 DISALLOW_COPY_AND_ASSIGN(SyncBackendHostCore); | 325 DISALLOW_COPY_AND_ASSIGN(SyncBackendHostCore); |
| 330 }; | 326 }; |
| 331 | 327 |
| 332 } // namespace syncer | 328 } // namespace syncer |
| 333 | 329 |
| 334 #endif // COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_CORE_H_ | 330 #endif // COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_CORE_H_ |
| OLD | NEW |