| 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 #include "components/sync/driver/glue/sync_backend_host_core.h" | 5 #include "components/sync/driver/glue/sync_backend_host_core.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "base/trace_event/memory_dump_manager.h" | 15 #include "base/trace_event/memory_dump_manager.h" |
| 15 #include "components/data_use_measurement/core/data_use_user_data.h" | 16 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 16 #include "components/invalidation/public/invalidation_util.h" | 17 #include "components/invalidation/public/invalidation_util.h" |
| 17 #include "components/invalidation/public/object_id_invalidation_map.h" | 18 #include "components/invalidation/public/object_id_invalidation_map.h" |
| 18 #include "components/sync/base/invalidation_adapter.h" | 19 #include "components/sync/base/invalidation_adapter.h" |
| 19 #include "components/sync/device_info/local_device_info_provider_impl.h" | 20 #include "components/sync/device_info/local_device_info_provider_impl.h" |
| 20 #include "components/sync/driver/glue/sync_backend_registrar.h" | 21 #include "components/sync/driver/glue/sync_backend_registrar.h" |
| 21 #include "components/sync/engine/cycle/commit_counters.h" | 22 #include "components/sync/engine/cycle/commit_counters.h" |
| 22 #include "components/sync/engine/cycle/status_counters.h" | 23 #include "components/sync/engine/cycle/status_counters.h" |
| 23 #include "components/sync/engine/cycle/sync_cycle_snapshot.h" | 24 #include "components/sync/engine/cycle/sync_cycle_snapshot.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 48 fetcher, data_use_measurement::DataUseUserData::SYNC); | 49 fetcher, data_use_measurement::DataUseUserData::SYNC); |
| 49 } | 50 } |
| 50 | 51 |
| 51 } // namespace | 52 } // namespace |
| 52 | 53 |
| 53 namespace syncer { | 54 namespace syncer { |
| 54 | 55 |
| 55 class EngineComponentsFactory; | 56 class EngineComponentsFactory; |
| 56 | 57 |
| 57 DoInitializeOptions::DoInitializeOptions( | 58 DoInitializeOptions::DoInitializeOptions( |
| 58 base::MessageLoop* sync_loop, | 59 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner, |
| 59 SyncBackendRegistrar* registrar, | 60 SyncBackendRegistrar* registrar, |
| 60 const std::vector<scoped_refptr<ModelSafeWorker>>& workers, | 61 const std::vector<scoped_refptr<ModelSafeWorker>>& workers, |
| 61 const scoped_refptr<ExtensionsActivity>& extensions_activity, | 62 const scoped_refptr<ExtensionsActivity>& extensions_activity, |
| 62 const WeakHandle<JsEventHandler>& event_handler, | 63 const WeakHandle<JsEventHandler>& event_handler, |
| 63 const GURL& service_url, | 64 const GURL& service_url, |
| 64 const std::string& sync_user_agent, | 65 const std::string& sync_user_agent, |
| 65 std::unique_ptr<HttpPostProviderFactory> http_bridge_factory, | 66 std::unique_ptr<HttpPostProviderFactory> http_bridge_factory, |
| 66 const SyncCredentials& credentials, | 67 const SyncCredentials& credentials, |
| 67 const std::string& invalidator_client_id, | 68 const std::string& invalidator_client_id, |
| 68 std::unique_ptr<SyncManagerFactory> sync_manager_factory, | 69 std::unique_ptr<SyncManagerFactory> sync_manager_factory, |
| 69 bool delete_sync_data_folder, | 70 bool delete_sync_data_folder, |
| 70 bool enable_local_sync_backend, | 71 bool enable_local_sync_backend, |
| 71 const base::FilePath& local_sync_backend_folder, | 72 const base::FilePath& local_sync_backend_folder, |
| 72 const std::string& restored_key_for_bootstrapping, | 73 const std::string& restored_key_for_bootstrapping, |
| 73 const std::string& restored_keystore_key_for_bootstrapping, | 74 const std::string& restored_keystore_key_for_bootstrapping, |
| 74 std::unique_ptr<EngineComponentsFactory> engine_components_factory, | 75 std::unique_ptr<EngineComponentsFactory> engine_components_factory, |
| 75 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler, | 76 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler, |
| 76 const base::Closure& report_unrecoverable_error_function, | 77 const base::Closure& report_unrecoverable_error_function, |
| 77 std::unique_ptr<SyncEncryptionHandler::NigoriState> saved_nigori_state, | 78 std::unique_ptr<SyncEncryptionHandler::NigoriState> saved_nigori_state, |
| 78 const std::map<ModelType, int64_t>& invalidation_versions) | 79 const std::map<ModelType, int64_t>& invalidation_versions) |
| 79 : sync_loop(sync_loop), | 80 : sync_task_runner(std::move(sync_task_runner)), |
| 80 registrar(registrar), | 81 registrar(registrar), |
| 81 workers(workers), | 82 workers(workers), |
| 82 extensions_activity(extensions_activity), | 83 extensions_activity(extensions_activity), |
| 83 event_handler(event_handler), | 84 event_handler(event_handler), |
| 84 service_url(service_url), | 85 service_url(service_url), |
| 85 sync_user_agent(sync_user_agent), | 86 sync_user_agent(sync_user_agent), |
| 86 http_bridge_factory(std::move(http_bridge_factory)), | 87 http_bridge_factory(std::move(http_bridge_factory)), |
| 87 credentials(credentials), | 88 credentials(credentials), |
| 88 invalidator_client_id(invalidator_client_id), | 89 invalidator_client_id(invalidator_client_id), |
| 89 sync_manager_factory(std::move(sync_manager_factory)), | 90 sync_manager_factory(std::move(sync_manager_factory)), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 104 DoConfigureSyncerTypes::DoConfigureSyncerTypes() {} | 105 DoConfigureSyncerTypes::DoConfigureSyncerTypes() {} |
| 105 | 106 |
| 106 DoConfigureSyncerTypes::DoConfigureSyncerTypes( | 107 DoConfigureSyncerTypes::DoConfigureSyncerTypes( |
| 107 const DoConfigureSyncerTypes& other) = default; | 108 const DoConfigureSyncerTypes& other) = default; |
| 108 | 109 |
| 109 DoConfigureSyncerTypes::~DoConfigureSyncerTypes() {} | 110 DoConfigureSyncerTypes::~DoConfigureSyncerTypes() {} |
| 110 | 111 |
| 111 SyncBackendHostCore::SyncBackendHostCore( | 112 SyncBackendHostCore::SyncBackendHostCore( |
| 112 const std::string& name, | 113 const std::string& name, |
| 113 const base::FilePath& sync_data_folder_path, | 114 const base::FilePath& sync_data_folder_path, |
| 114 bool has_sync_setup_completed, | |
| 115 const base::WeakPtr<SyncBackendHostImpl>& backend) | 115 const base::WeakPtr<SyncBackendHostImpl>& backend) |
| 116 : name_(name), | 116 : name_(name), |
| 117 sync_data_folder_path_(sync_data_folder_path), | 117 sync_data_folder_path_(sync_data_folder_path), |
| 118 host_(backend), | 118 host_(backend), |
| 119 sync_loop_(nullptr), | |
| 120 registrar_(nullptr), | |
| 121 has_sync_setup_completed_(has_sync_setup_completed), | |
| 122 forward_protocol_events_(false), | |
| 123 forward_type_info_(false), | |
| 124 weak_ptr_factory_(this) { | 119 weak_ptr_factory_(this) { |
| 125 DCHECK(backend.get()); | 120 DCHECK(backend.get()); |
| 121 // This is constructed on the UI thread but used from the sync thread. |
| 122 thread_checker_.DetachFromThread(); |
| 126 } | 123 } |
| 127 | 124 |
| 128 SyncBackendHostCore::~SyncBackendHostCore() { | 125 SyncBackendHostCore::~SyncBackendHostCore() { |
| 129 DCHECK(!sync_manager_.get()); | 126 DCHECK(!sync_manager_.get()); |
| 130 } | 127 } |
| 131 | 128 |
| 132 bool SyncBackendHostCore::OnMemoryDump( | 129 bool SyncBackendHostCore::OnMemoryDump( |
| 133 const base::trace_event::MemoryDumpArgs& args, | 130 const base::trace_event::MemoryDumpArgs& args, |
| 134 base::trace_event::ProcessMemoryDump* pmd) { | 131 base::trace_event::ProcessMemoryDump* pmd) { |
| 135 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 132 DCHECK(thread_checker_.CalledOnValidThread()); |
| 136 if (!sync_manager_) | 133 if (!sync_manager_) |
| 137 return false; | 134 return false; |
| 138 sync_manager_->OnMemoryDump(pmd); | 135 sync_manager_->OnMemoryDump(pmd); |
| 139 return true; | 136 return true; |
| 140 } | 137 } |
| 141 | 138 |
| 142 void SyncBackendHostCore::OnSyncCycleCompleted( | 139 void SyncBackendHostCore::OnSyncCycleCompleted( |
| 143 const SyncCycleSnapshot& snapshot) { | 140 const SyncCycleSnapshot& snapshot) { |
| 144 if (!sync_loop_) | 141 DCHECK(thread_checker_.CalledOnValidThread()); |
| 145 return; | |
| 146 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | |
| 147 | |
| 148 host_.Call(FROM_HERE, | 142 host_.Call(FROM_HERE, |
| 149 &SyncBackendHostImpl::HandleSyncCycleCompletedOnFrontendLoop, | 143 &SyncBackendHostImpl::HandleSyncCycleCompletedOnFrontendLoop, |
| 150 snapshot); | 144 snapshot); |
| 151 } | 145 } |
| 152 | 146 |
| 153 void SyncBackendHostCore::DoRefreshTypes(ModelTypeSet types) { | 147 void SyncBackendHostCore::DoRefreshTypes(ModelTypeSet types) { |
| 154 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 148 DCHECK(thread_checker_.CalledOnValidThread()); |
| 155 sync_manager_->RefreshTypes(types); | 149 sync_manager_->RefreshTypes(types); |
| 156 } | 150 } |
| 157 | 151 |
| 158 void SyncBackendHostCore::OnInitializationComplete( | 152 void SyncBackendHostCore::OnInitializationComplete( |
| 159 const WeakHandle<JsBackend>& js_backend, | 153 const WeakHandle<JsBackend>& js_backend, |
| 160 const WeakHandle<DataTypeDebugInfoListener>& debug_info_listener, | 154 const WeakHandle<DataTypeDebugInfoListener>& debug_info_listener, |
| 161 bool success, | 155 bool success, |
| 162 const ModelTypeSet restored_types) { | 156 const ModelTypeSet restored_types) { |
| 163 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 157 DCHECK(thread_checker_.CalledOnValidThread()); |
| 164 | 158 |
| 165 if (!success) { | 159 if (!success) { |
| 166 DoDestroySyncManager(STOP_SYNC); | 160 DoDestroySyncManager(STOP_SYNC); |
| 167 host_.Call(FROM_HERE, | 161 host_.Call(FROM_HERE, |
| 168 &SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop); | 162 &SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop); |
| 169 return; | 163 return; |
| 170 } | 164 } |
| 171 | 165 |
| 172 // Register for encryption related changes now. We have to do this before | 166 // Register for encryption related changes now. We have to do this before |
| 173 // the initializing downloading control types or initializing the encryption | 167 // the initializing downloading control types or initializing the encryption |
| 174 // handler in order to receive notifications triggered during encryption | 168 // handler in order to receive notifications triggered during encryption |
| 175 // startup. | 169 // startup. |
| 176 sync_manager_->GetEncryptionHandler()->AddObserver(this); | 170 sync_manager_->GetEncryptionHandler()->AddObserver(this); |
| 177 | 171 |
| 178 // Sync manager initialization is complete, so we can schedule recurring | 172 // Sync manager initialization is complete, so we can schedule recurring |
| 179 // SaveChanges. | 173 // SaveChanges. |
| 180 sync_loop_->task_runner()->PostTask( | 174 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 181 FROM_HERE, base::Bind(&SyncBackendHostCore::StartSavingChanges, | 175 FROM_HERE, base::Bind(&SyncBackendHostCore::StartSavingChanges, |
| 182 weak_ptr_factory_.GetWeakPtr())); | 176 weak_ptr_factory_.GetWeakPtr())); |
| 183 | 177 |
| 184 // Hang on to these for a while longer. We're not ready to hand them back to | 178 // Hang on to these for a while longer. We're not ready to hand them back to |
| 185 // the UI thread yet. | 179 // the UI thread yet. |
| 186 js_backend_ = js_backend; | 180 js_backend_ = js_backend; |
| 187 debug_info_listener_ = debug_info_listener; | 181 debug_info_listener_ = debug_info_listener; |
| 188 | 182 |
| 189 // Before proceeding any further, we need to download the control types and | 183 // Before proceeding any further, we need to download the control types and |
| 190 // purge any partial data (ie. data downloaded for a type that was on its way | 184 // purge any partial data (ie. data downloaded for a type that was on its way |
| (...skipping 19 matching lines...) Expand all Loading... |
| 210 | 204 |
| 211 sync_manager_->ConfigureSyncer( | 205 sync_manager_->ConfigureSyncer( |
| 212 reason, new_control_types, types_to_purge, ModelTypeSet(), ModelTypeSet(), | 206 reason, new_control_types, types_to_purge, ModelTypeSet(), ModelTypeSet(), |
| 213 routing_info, | 207 routing_info, |
| 214 base::Bind(&SyncBackendHostCore::DoInitialProcessControlTypes, | 208 base::Bind(&SyncBackendHostCore::DoInitialProcessControlTypes, |
| 215 weak_ptr_factory_.GetWeakPtr()), | 209 weak_ptr_factory_.GetWeakPtr()), |
| 216 base::Closure()); | 210 base::Closure()); |
| 217 } | 211 } |
| 218 | 212 |
| 219 void SyncBackendHostCore::OnConnectionStatusChange(ConnectionStatus status) { | 213 void SyncBackendHostCore::OnConnectionStatusChange(ConnectionStatus status) { |
| 220 if (!sync_loop_) | 214 DCHECK(thread_checker_.CalledOnValidThread()); |
| 221 return; | |
| 222 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | |
| 223 host_.Call(FROM_HERE, | 215 host_.Call(FROM_HERE, |
| 224 &SyncBackendHostImpl::HandleConnectionStatusChangeOnFrontendLoop, | 216 &SyncBackendHostImpl::HandleConnectionStatusChangeOnFrontendLoop, |
| 225 status); | 217 status); |
| 226 } | 218 } |
| 227 | 219 |
| 228 void SyncBackendHostCore::OnPassphraseRequired( | 220 void SyncBackendHostCore::OnPassphraseRequired( |
| 229 PassphraseRequiredReason reason, | 221 PassphraseRequiredReason reason, |
| 230 const sync_pb::EncryptedData& pending_keys) { | 222 const sync_pb::EncryptedData& pending_keys) { |
| 231 if (!sync_loop_) | 223 DCHECK(thread_checker_.CalledOnValidThread()); |
| 232 return; | |
| 233 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | |
| 234 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyPassphraseRequired, reason, | 224 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyPassphraseRequired, reason, |
| 235 pending_keys); | 225 pending_keys); |
| 236 } | 226 } |
| 237 | 227 |
| 238 void SyncBackendHostCore::OnPassphraseAccepted() { | 228 void SyncBackendHostCore::OnPassphraseAccepted() { |
| 239 if (!sync_loop_) | 229 DCHECK(thread_checker_.CalledOnValidThread()); |
| 240 return; | |
| 241 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | |
| 242 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyPassphraseAccepted); | 230 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyPassphraseAccepted); |
| 243 } | 231 } |
| 244 | 232 |
| 245 void SyncBackendHostCore::OnBootstrapTokenUpdated( | 233 void SyncBackendHostCore::OnBootstrapTokenUpdated( |
| 246 const std::string& bootstrap_token, | 234 const std::string& bootstrap_token, |
| 247 BootstrapTokenType type) { | 235 BootstrapTokenType type) { |
| 248 if (!sync_loop_) | 236 DCHECK(thread_checker_.CalledOnValidThread()); |
| 249 return; | |
| 250 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | |
| 251 host_.Call(FROM_HERE, &SyncBackendHostImpl::PersistEncryptionBootstrapToken, | 237 host_.Call(FROM_HERE, &SyncBackendHostImpl::PersistEncryptionBootstrapToken, |
| 252 bootstrap_token, type); | 238 bootstrap_token, type); |
| 253 } | 239 } |
| 254 | 240 |
| 255 void SyncBackendHostCore::OnEncryptedTypesChanged(ModelTypeSet encrypted_types, | 241 void SyncBackendHostCore::OnEncryptedTypesChanged(ModelTypeSet encrypted_types, |
| 256 bool encrypt_everything) { | 242 bool encrypt_everything) { |
| 257 if (!sync_loop_) | 243 DCHECK(thread_checker_.CalledOnValidThread()); |
| 258 return; | |
| 259 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | |
| 260 // NOTE: We're in a transaction. | 244 // NOTE: We're in a transaction. |
| 261 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyEncryptedTypesChanged, | 245 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyEncryptedTypesChanged, |
| 262 encrypted_types, encrypt_everything); | 246 encrypted_types, encrypt_everything); |
| 263 } | 247 } |
| 264 | 248 |
| 265 void SyncBackendHostCore::OnEncryptionComplete() { | 249 void SyncBackendHostCore::OnEncryptionComplete() { |
| 266 if (!sync_loop_) | 250 DCHECK(thread_checker_.CalledOnValidThread()); |
| 267 return; | |
| 268 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | |
| 269 // NOTE: We're in a transaction. | 251 // NOTE: We're in a transaction. |
| 270 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyEncryptionComplete); | 252 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyEncryptionComplete); |
| 271 } | 253 } |
| 272 | 254 |
| 273 void SyncBackendHostCore::OnCryptographerStateChanged( | 255 void SyncBackendHostCore::OnCryptographerStateChanged( |
| 274 Cryptographer* cryptographer) { | 256 Cryptographer* cryptographer) { |
| 257 DCHECK(thread_checker_.CalledOnValidThread()); |
| 275 // Do nothing. | 258 // Do nothing. |
| 276 } | 259 } |
| 277 | 260 |
| 278 void SyncBackendHostCore::OnPassphraseTypeChanged(PassphraseType type, | 261 void SyncBackendHostCore::OnPassphraseTypeChanged(PassphraseType type, |
| 279 base::Time passphrase_time) { | 262 base::Time passphrase_time) { |
| 263 DCHECK(thread_checker_.CalledOnValidThread()); |
| 280 host_.Call(FROM_HERE, | 264 host_.Call(FROM_HERE, |
| 281 &SyncBackendHostImpl::HandlePassphraseTypeChangedOnFrontendLoop, | 265 &SyncBackendHostImpl::HandlePassphraseTypeChangedOnFrontendLoop, |
| 282 type, passphrase_time); | 266 type, passphrase_time); |
| 283 } | 267 } |
| 284 | 268 |
| 285 void SyncBackendHostCore::OnLocalSetPassphraseEncryption( | 269 void SyncBackendHostCore::OnLocalSetPassphraseEncryption( |
| 286 const SyncEncryptionHandler::NigoriState& nigori_state) { | 270 const SyncEncryptionHandler::NigoriState& nigori_state) { |
| 271 DCHECK(thread_checker_.CalledOnValidThread()); |
| 287 host_.Call( | 272 host_.Call( |
| 288 FROM_HERE, | 273 FROM_HERE, |
| 289 &SyncBackendHostImpl::HandleLocalSetPassphraseEncryptionOnFrontendLoop, | 274 &SyncBackendHostImpl::HandleLocalSetPassphraseEncryptionOnFrontendLoop, |
| 290 nigori_state); | 275 nigori_state); |
| 291 } | 276 } |
| 292 | 277 |
| 293 void SyncBackendHostCore::OnCommitCountersUpdated( | 278 void SyncBackendHostCore::OnCommitCountersUpdated( |
| 294 ModelType type, | 279 ModelType type, |
| 295 const CommitCounters& counters) { | 280 const CommitCounters& counters) { |
| 281 DCHECK(thread_checker_.CalledOnValidThread()); |
| 296 host_.Call( | 282 host_.Call( |
| 297 FROM_HERE, | 283 FROM_HERE, |
| 298 &SyncBackendHostImpl::HandleDirectoryCommitCountersUpdatedOnFrontendLoop, | 284 &SyncBackendHostImpl::HandleDirectoryCommitCountersUpdatedOnFrontendLoop, |
| 299 type, counters); | 285 type, counters); |
| 300 } | 286 } |
| 301 | 287 |
| 302 void SyncBackendHostCore::OnUpdateCountersUpdated( | 288 void SyncBackendHostCore::OnUpdateCountersUpdated( |
| 303 ModelType type, | 289 ModelType type, |
| 304 const UpdateCounters& counters) { | 290 const UpdateCounters& counters) { |
| 291 DCHECK(thread_checker_.CalledOnValidThread()); |
| 305 host_.Call( | 292 host_.Call( |
| 306 FROM_HERE, | 293 FROM_HERE, |
| 307 &SyncBackendHostImpl::HandleDirectoryUpdateCountersUpdatedOnFrontendLoop, | 294 &SyncBackendHostImpl::HandleDirectoryUpdateCountersUpdatedOnFrontendLoop, |
| 308 type, counters); | 295 type, counters); |
| 309 } | 296 } |
| 310 | 297 |
| 311 void SyncBackendHostCore::OnStatusCountersUpdated( | 298 void SyncBackendHostCore::OnStatusCountersUpdated( |
| 312 ModelType type, | 299 ModelType type, |
| 313 const StatusCounters& counters) { | 300 const StatusCounters& counters) { |
| 301 DCHECK(thread_checker_.CalledOnValidThread()); |
| 314 host_.Call( | 302 host_.Call( |
| 315 FROM_HERE, | 303 FROM_HERE, |
| 316 &SyncBackendHostImpl::HandleDirectoryStatusCountersUpdatedOnFrontendLoop, | 304 &SyncBackendHostImpl::HandleDirectoryStatusCountersUpdatedOnFrontendLoop, |
| 317 type, counters); | 305 type, counters); |
| 318 } | 306 } |
| 319 | 307 |
| 320 void SyncBackendHostCore::OnActionableError( | 308 void SyncBackendHostCore::OnActionableError( |
| 321 const SyncProtocolError& sync_error) { | 309 const SyncProtocolError& sync_error) { |
| 322 if (!sync_loop_) | 310 DCHECK(thread_checker_.CalledOnValidThread()); |
| 323 return; | |
| 324 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | |
| 325 host_.Call(FROM_HERE, | 311 host_.Call(FROM_HERE, |
| 326 &SyncBackendHostImpl::HandleActionableErrorEventOnFrontendLoop, | 312 &SyncBackendHostImpl::HandleActionableErrorEventOnFrontendLoop, |
| 327 sync_error); | 313 sync_error); |
| 328 } | 314 } |
| 329 | 315 |
| 330 void SyncBackendHostCore::OnMigrationRequested(ModelTypeSet types) { | 316 void SyncBackendHostCore::OnMigrationRequested(ModelTypeSet types) { |
| 331 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 317 DCHECK(thread_checker_.CalledOnValidThread()); |
| 332 host_.Call(FROM_HERE, | 318 host_.Call(FROM_HERE, |
| 333 &SyncBackendHostImpl::HandleMigrationRequestedOnFrontendLoop, | 319 &SyncBackendHostImpl::HandleMigrationRequestedOnFrontendLoop, |
| 334 types); | 320 types); |
| 335 } | 321 } |
| 336 | 322 |
| 337 void SyncBackendHostCore::OnProtocolEvent(const ProtocolEvent& event) { | 323 void SyncBackendHostCore::OnProtocolEvent(const ProtocolEvent& event) { |
| 324 DCHECK(thread_checker_.CalledOnValidThread()); |
| 338 if (forward_protocol_events_) { | 325 if (forward_protocol_events_) { |
| 339 std::unique_ptr<ProtocolEvent> event_clone(event.Clone()); | 326 std::unique_ptr<ProtocolEvent> event_clone(event.Clone()); |
| 340 host_.Call(FROM_HERE, | 327 host_.Call(FROM_HERE, |
| 341 &SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop, | 328 &SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop, |
| 342 base::Passed(std::move(event_clone))); | 329 base::Passed(std::move(event_clone))); |
| 343 } | 330 } |
| 344 } | 331 } |
| 345 | 332 |
| 346 void SyncBackendHostCore::DoOnInvalidatorStateChange(InvalidatorState state) { | 333 void SyncBackendHostCore::DoOnInvalidatorStateChange(InvalidatorState state) { |
| 347 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 334 DCHECK(thread_checker_.CalledOnValidThread()); |
| 348 sync_manager_->SetInvalidatorEnabled(state == INVALIDATIONS_ENABLED); | 335 sync_manager_->SetInvalidatorEnabled(state == INVALIDATIONS_ENABLED); |
| 349 } | 336 } |
| 350 | 337 |
| 351 void SyncBackendHostCore::DoOnIncomingInvalidation( | 338 void SyncBackendHostCore::DoOnIncomingInvalidation( |
| 352 const ObjectIdInvalidationMap& invalidation_map) { | 339 const ObjectIdInvalidationMap& invalidation_map) { |
| 353 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 340 DCHECK(thread_checker_.CalledOnValidThread()); |
| 354 | 341 |
| 355 ObjectIdSet ids = invalidation_map.GetObjectIds(); | 342 ObjectIdSet ids = invalidation_map.GetObjectIds(); |
| 356 for (const invalidation::ObjectId& object_id : ids) { | 343 for (const invalidation::ObjectId& object_id : ids) { |
| 357 ModelType type; | 344 ModelType type; |
| 358 if (!NotificationTypeToRealModelType(object_id.name(), &type)) { | 345 if (!NotificationTypeToRealModelType(object_id.name(), &type)) { |
| 359 DLOG(WARNING) << "Notification has invalid id: " | 346 DLOG(WARNING) << "Notification has invalid id: " |
| 360 << ObjectIdToString(object_id); | 347 << ObjectIdToString(object_id); |
| 361 } else { | 348 } else { |
| 362 SingleObjectInvalidationSet invalidation_set = | 349 SingleObjectInvalidationSet invalidation_set = |
| 363 invalidation_map.ForObject(object_id); | 350 invalidation_map.ForObject(object_id); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 380 } | 367 } |
| 381 } | 368 } |
| 382 } | 369 } |
| 383 | 370 |
| 384 host_.Call(FROM_HERE, &SyncBackendHostImpl::UpdateInvalidationVersions, | 371 host_.Call(FROM_HERE, &SyncBackendHostImpl::UpdateInvalidationVersions, |
| 385 last_invalidation_versions_); | 372 last_invalidation_versions_); |
| 386 } | 373 } |
| 387 | 374 |
| 388 void SyncBackendHostCore::DoInitialize( | 375 void SyncBackendHostCore::DoInitialize( |
| 389 std::unique_ptr<DoInitializeOptions> options) { | 376 std::unique_ptr<DoInitializeOptions> options) { |
| 390 DCHECK(!sync_loop_); | 377 DCHECK(thread_checker_.CalledOnValidThread()); |
| 391 sync_loop_ = options->sync_loop; | |
| 392 DCHECK(sync_loop_); | |
| 393 | 378 |
| 394 // Finish initializing the HttpBridgeFactory. We do this here because | 379 // Finish initializing the HttpBridgeFactory. We do this here because |
| 395 // building the user agent may block on some platforms. | 380 // building the user agent may block on some platforms. |
| 396 options->http_bridge_factory->Init(options->sync_user_agent, | 381 options->http_bridge_factory->Init(options->sync_user_agent, |
| 397 base::Bind(&BindFetcherToDataTracker)); | 382 base::Bind(&BindFetcherToDataTracker)); |
| 398 | 383 |
| 399 // Blow away the partial or corrupt sync data folder before doing any more | 384 // Blow away the partial or corrupt sync data folder before doing any more |
| 400 // initialization, if necessary. | 385 // initialization, if necessary. |
| 401 if (options->delete_sync_data_folder) { | 386 if (options->delete_sync_data_folder) { |
| 402 DeleteSyncDataFolder(); | 387 DeleteSyncDataFolder(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 args.engine_components_factory = | 421 args.engine_components_factory = |
| 437 std::move(options->engine_components_factory); | 422 std::move(options->engine_components_factory); |
| 438 args.encryptor = &encryptor_; | 423 args.encryptor = &encryptor_; |
| 439 args.unrecoverable_error_handler = options->unrecoverable_error_handler; | 424 args.unrecoverable_error_handler = options->unrecoverable_error_handler; |
| 440 args.report_unrecoverable_error_function = | 425 args.report_unrecoverable_error_function = |
| 441 options->report_unrecoverable_error_function; | 426 options->report_unrecoverable_error_function; |
| 442 args.cancelation_signal = &stop_syncing_signal_; | 427 args.cancelation_signal = &stop_syncing_signal_; |
| 443 args.saved_nigori_state = std::move(options->saved_nigori_state); | 428 args.saved_nigori_state = std::move(options->saved_nigori_state); |
| 444 sync_manager_->Init(&args); | 429 sync_manager_->Init(&args); |
| 445 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | 430 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| 446 this, "SyncDirectory", sync_loop_->task_runner()); | 431 this, "SyncDirectory", base::ThreadTaskRunnerHandle::Get()); |
| 447 } | 432 } |
| 448 | 433 |
| 449 void SyncBackendHostCore::DoUpdateCredentials( | 434 void SyncBackendHostCore::DoUpdateCredentials( |
| 450 const SyncCredentials& credentials) { | 435 const SyncCredentials& credentials) { |
| 451 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 436 DCHECK(thread_checker_.CalledOnValidThread()); |
| 452 // UpdateCredentials can be called during backend initialization, possibly | 437 // UpdateCredentials can be called during backend initialization, possibly |
| 453 // when backend initialization has failed but hasn't notified the UI thread | 438 // when backend initialization has failed but hasn't notified the UI thread |
| 454 // yet. In that case, the sync manager may have been destroyed on the sync | 439 // yet. In that case, the sync manager may have been destroyed on the sync |
| 455 // thread before this task was executed, so we do nothing. | 440 // thread before this task was executed, so we do nothing. |
| 456 if (sync_manager_) { | 441 if (sync_manager_) { |
| 457 sync_manager_->UpdateCredentials(credentials); | 442 sync_manager_->UpdateCredentials(credentials); |
| 458 } | 443 } |
| 459 } | 444 } |
| 460 | 445 |
| 461 void SyncBackendHostCore::DoStartSyncing( | 446 void SyncBackendHostCore::DoStartSyncing( |
| 462 const ModelSafeRoutingInfo& routing_info, | 447 const ModelSafeRoutingInfo& routing_info, |
| 463 base::Time last_poll_time) { | 448 base::Time last_poll_time) { |
| 464 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 449 DCHECK(thread_checker_.CalledOnValidThread()); |
| 465 sync_manager_->StartSyncingNormally(routing_info, last_poll_time); | 450 sync_manager_->StartSyncingNormally(routing_info, last_poll_time); |
| 466 } | 451 } |
| 467 | 452 |
| 468 void SyncBackendHostCore::DoSetEncryptionPassphrase( | 453 void SyncBackendHostCore::DoSetEncryptionPassphrase( |
| 469 const std::string& passphrase, | 454 const std::string& passphrase, |
| 470 bool is_explicit) { | 455 bool is_explicit) { |
| 471 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 456 DCHECK(thread_checker_.CalledOnValidThread()); |
| 472 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase(passphrase, | 457 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase(passphrase, |
| 473 is_explicit); | 458 is_explicit); |
| 474 } | 459 } |
| 475 | 460 |
| 476 void SyncBackendHostCore::DoInitialProcessControlTypes() { | 461 void SyncBackendHostCore::DoInitialProcessControlTypes() { |
| 477 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 462 DCHECK(thread_checker_.CalledOnValidThread()); |
| 478 | 463 |
| 479 DVLOG(1) << "Initilalizing Control Types"; | 464 DVLOG(1) << "Initilalizing Control Types"; |
| 480 | 465 |
| 481 // Initialize encryption. | 466 // Initialize encryption. |
| 482 sync_manager_->GetEncryptionHandler()->Init(); | 467 sync_manager_->GetEncryptionHandler()->Init(); |
| 483 | 468 |
| 484 // Note: experiments are currently handled via SBH::AddExperimentalTypes, | 469 // Note: experiments are currently handled via SBH::AddExperimentalTypes, |
| 485 // which is called at the end of every sync cycle. | 470 // which is called at the end of every sync cycle. |
| 486 // TODO(zea): eventually add an experiment handler and initialize it here. | 471 // TODO(zea): eventually add an experiment handler and initialize it here. |
| 487 | 472 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 504 js_backend_, debug_info_listener_, | 489 js_backend_, debug_info_listener_, |
| 505 base::Passed(sync_manager_->GetModelTypeConnectorProxy()), | 490 base::Passed(sync_manager_->GetModelTypeConnectorProxy()), |
| 506 sync_manager_->cache_guid()); | 491 sync_manager_->cache_guid()); |
| 507 | 492 |
| 508 js_backend_.Reset(); | 493 js_backend_.Reset(); |
| 509 debug_info_listener_.Reset(); | 494 debug_info_listener_.Reset(); |
| 510 } | 495 } |
| 511 | 496 |
| 512 void SyncBackendHostCore::DoSetDecryptionPassphrase( | 497 void SyncBackendHostCore::DoSetDecryptionPassphrase( |
| 513 const std::string& passphrase) { | 498 const std::string& passphrase) { |
| 514 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 499 DCHECK(thread_checker_.CalledOnValidThread()); |
| 515 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase(passphrase); | 500 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase(passphrase); |
| 516 } | 501 } |
| 517 | 502 |
| 518 void SyncBackendHostCore::DoEnableEncryptEverything() { | 503 void SyncBackendHostCore::DoEnableEncryptEverything() { |
| 519 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 504 DCHECK(thread_checker_.CalledOnValidThread()); |
| 520 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything(); | 505 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything(); |
| 521 } | 506 } |
| 522 | 507 |
| 523 void SyncBackendHostCore::ShutdownOnUIThread() { | 508 void SyncBackendHostCore::ShutdownOnUIThread() { |
| 524 // This will cut short any blocking network tasks, cut short any in-progress | 509 // This will cut short any blocking network tasks, cut short any in-progress |
| 525 // sync cycles, and prevent the creation of new blocking network tasks and new | 510 // sync cycles, and prevent the creation of new blocking network tasks and new |
| 526 // sync cycles. If there was an in-progress network request, it would have | 511 // sync cycles. If there was an in-progress network request, it would have |
| 527 // had a reference to the RequestContextGetter. This reference will be | 512 // had a reference to the RequestContextGetter. This reference will be |
| 528 // dropped by the time this function returns. | 513 // dropped by the time this function returns. |
| 529 // | 514 // |
| 530 // It is safe to call this even if Sync's backend classes have not been | 515 // It is safe to call this even if Sync's backend classes have not been |
| 531 // initialized yet. Those classes will receive the message when the sync | 516 // initialized yet. Those classes will receive the message when the sync |
| 532 // thread finally getes around to constructing them. | 517 // thread finally getes around to constructing them. |
| 533 stop_syncing_signal_.Signal(); | 518 stop_syncing_signal_.Signal(); |
| 534 | 519 |
| 535 // This will drop the HttpBridgeFactory's reference to the | 520 // This will drop the HttpBridgeFactory's reference to the |
| 536 // RequestContextGetter. Once this has been called, the HttpBridgeFactory can | 521 // RequestContextGetter. Once this has been called, the HttpBridgeFactory can |
| 537 // no longer be used to create new HttpBridge instances. We can get away with | 522 // no longer be used to create new HttpBridge instances. We can get away with |
| 538 // this because the stop_syncing_signal_ has already been signalled, which | 523 // this because the stop_syncing_signal_ has already been signalled, which |
| 539 // guarantees that the ServerConnectionManager will no longer attempt to | 524 // guarantees that the ServerConnectionManager will no longer attempt to |
| 540 // create new connections. | 525 // create new connections. |
| 541 release_request_context_signal_.Signal(); | 526 release_request_context_signal_.Signal(); |
| 542 } | 527 } |
| 543 | 528 |
| 544 void SyncBackendHostCore::DoShutdown(ShutdownReason reason) { | 529 void SyncBackendHostCore::DoShutdown(ShutdownReason reason) { |
| 545 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 530 DCHECK(thread_checker_.CalledOnValidThread()); |
| 546 | 531 |
| 547 DoDestroySyncManager(reason); | 532 DoDestroySyncManager(reason); |
| 548 | 533 |
| 549 registrar_ = nullptr; | 534 registrar_ = nullptr; |
| 550 | 535 |
| 551 if (reason == DISABLE_SYNC) | 536 if (reason == DISABLE_SYNC) |
| 552 DeleteSyncDataFolder(); | 537 DeleteSyncDataFolder(); |
| 553 | 538 |
| 554 host_.Reset(); | 539 host_.Reset(); |
| 555 weak_ptr_factory_.InvalidateWeakPtrs(); | 540 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 556 } | 541 } |
| 557 | 542 |
| 558 void SyncBackendHostCore::DoDestroySyncManager(ShutdownReason reason) { | 543 void SyncBackendHostCore::DoDestroySyncManager(ShutdownReason reason) { |
| 559 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 544 DCHECK(thread_checker_.CalledOnValidThread()); |
| 560 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 545 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
| 561 this); | 546 this); |
| 562 if (sync_manager_) { | 547 if (sync_manager_) { |
| 563 DisableDirectoryTypeDebugInfoForwarding(); | 548 DisableDirectoryTypeDebugInfoForwarding(); |
| 564 save_changes_timer_.reset(); | 549 save_changes_timer_.reset(); |
| 565 sync_manager_->RemoveObserver(this); | 550 sync_manager_->RemoveObserver(this); |
| 566 sync_manager_->ShutdownOnSyncThread(reason); | 551 sync_manager_->ShutdownOnSyncThread(reason); |
| 567 sync_manager_.reset(); | 552 sync_manager_.reset(); |
| 568 } | 553 } |
| 569 } | 554 } |
| 570 | 555 |
| 571 void SyncBackendHostCore::DoConfigureSyncer( | 556 void SyncBackendHostCore::DoConfigureSyncer( |
| 572 ConfigureReason reason, | 557 ConfigureReason reason, |
| 573 const DoConfigureSyncerTypes& config_types, | 558 const DoConfigureSyncerTypes& config_types, |
| 574 const ModelSafeRoutingInfo routing_info, | 559 const ModelSafeRoutingInfo routing_info, |
| 575 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task, | 560 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task, |
| 576 const base::Closure& retry_callback) { | 561 const base::Closure& retry_callback) { |
| 577 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 562 DCHECK(thread_checker_.CalledOnValidThread()); |
| 578 DCHECK(!ready_task.is_null()); | 563 DCHECK(!ready_task.is_null()); |
| 579 DCHECK(!retry_callback.is_null()); | 564 DCHECK(!retry_callback.is_null()); |
| 580 base::Closure chained_ready_task(base::Bind( | 565 base::Closure chained_ready_task(base::Bind( |
| 581 &SyncBackendHostCore::DoFinishConfigureDataTypes, | 566 &SyncBackendHostCore::DoFinishConfigureDataTypes, |
| 582 weak_ptr_factory_.GetWeakPtr(), config_types.to_download, ready_task)); | 567 weak_ptr_factory_.GetWeakPtr(), config_types.to_download, ready_task)); |
| 583 base::Closure chained_retry_task( | 568 base::Closure chained_retry_task( |
| 584 base::Bind(&SyncBackendHostCore::DoRetryConfiguration, | 569 base::Bind(&SyncBackendHostCore::DoRetryConfiguration, |
| 585 weak_ptr_factory_.GetWeakPtr(), retry_callback)); | 570 weak_ptr_factory_.GetWeakPtr(), retry_callback)); |
| 586 sync_manager_->ConfigureSyncer(reason, config_types.to_download, | 571 sync_manager_->ConfigureSyncer(reason, config_types.to_download, |
| 587 config_types.to_purge, config_types.to_journal, | 572 config_types.to_purge, config_types.to_journal, |
| 588 config_types.to_unapply, routing_info, | 573 config_types.to_unapply, routing_info, |
| 589 chained_ready_task, chained_retry_task); | 574 chained_ready_task, chained_retry_task); |
| 590 } | 575 } |
| 591 | 576 |
| 592 void SyncBackendHostCore::DoFinishConfigureDataTypes( | 577 void SyncBackendHostCore::DoFinishConfigureDataTypes( |
| 593 ModelTypeSet types_to_config, | 578 ModelTypeSet types_to_config, |
| 594 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task) { | 579 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task) { |
| 595 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 580 DCHECK(thread_checker_.CalledOnValidThread()); |
| 596 | 581 |
| 597 // Update the enabled types for the bridge and sync manager. | 582 // Update the enabled types for the bridge and sync manager. |
| 598 ModelSafeRoutingInfo routing_info; | 583 ModelSafeRoutingInfo routing_info; |
| 599 registrar_->GetModelSafeRoutingInfo(&routing_info); | 584 registrar_->GetModelSafeRoutingInfo(&routing_info); |
| 600 ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); | 585 ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); |
| 601 enabled_types.RemoveAll(ProxyTypes()); | 586 enabled_types.RemoveAll(ProxyTypes()); |
| 602 | 587 |
| 603 const ModelTypeSet failed_configuration_types = | 588 const ModelTypeSet failed_configuration_types = |
| 604 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes()); | 589 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes()); |
| 605 const ModelTypeSet succeeded_configuration_types = | 590 const ModelTypeSet succeeded_configuration_types = |
| 606 Difference(types_to_config, failed_configuration_types); | 591 Difference(types_to_config, failed_configuration_types); |
| 607 host_.Call(FROM_HERE, | 592 host_.Call(FROM_HERE, |
| 608 &SyncBackendHostImpl::FinishConfigureDataTypesOnFrontendLoop, | 593 &SyncBackendHostImpl::FinishConfigureDataTypesOnFrontendLoop, |
| 609 enabled_types, succeeded_configuration_types, | 594 enabled_types, succeeded_configuration_types, |
| 610 failed_configuration_types, ready_task); | 595 failed_configuration_types, ready_task); |
| 611 } | 596 } |
| 612 | 597 |
| 613 void SyncBackendHostCore::DoRetryConfiguration( | 598 void SyncBackendHostCore::DoRetryConfiguration( |
| 614 const base::Closure& retry_callback) { | 599 const base::Closure& retry_callback) { |
| 615 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 600 DCHECK(thread_checker_.CalledOnValidThread()); |
| 616 host_.Call(FROM_HERE, &SyncBackendHostImpl::RetryConfigurationOnFrontendLoop, | 601 host_.Call(FROM_HERE, &SyncBackendHostImpl::RetryConfigurationOnFrontendLoop, |
| 617 retry_callback); | 602 retry_callback); |
| 618 } | 603 } |
| 619 | 604 |
| 620 void SyncBackendHostCore::SendBufferedProtocolEventsAndEnableForwarding() { | 605 void SyncBackendHostCore::SendBufferedProtocolEventsAndEnableForwarding() { |
| 621 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 606 DCHECK(thread_checker_.CalledOnValidThread()); |
| 622 forward_protocol_events_ = true; | 607 forward_protocol_events_ = true; |
| 623 | 608 |
| 624 if (sync_manager_) { | 609 if (sync_manager_) { |
| 625 // Grab our own copy of the buffered events. | 610 // Grab our own copy of the buffered events. |
| 626 // The buffer is not modified by this operation. | 611 // The buffer is not modified by this operation. |
| 627 std::vector<std::unique_ptr<ProtocolEvent>> buffered_events = | 612 std::vector<std::unique_ptr<ProtocolEvent>> buffered_events = |
| 628 sync_manager_->GetBufferedProtocolEvents(); | 613 sync_manager_->GetBufferedProtocolEvents(); |
| 629 | 614 |
| 630 // Send them all over the fence to the host. | 615 // Send them all over the fence to the host. |
| 631 for (auto& event : buffered_events) { | 616 for (auto& event : buffered_events) { |
| 632 host_.Call(FROM_HERE, | 617 host_.Call(FROM_HERE, |
| 633 &SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop, | 618 &SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop, |
| 634 base::Passed(std::move(event))); | 619 base::Passed(std::move(event))); |
| 635 } | 620 } |
| 636 } | 621 } |
| 637 } | 622 } |
| 638 | 623 |
| 639 void SyncBackendHostCore::DisableProtocolEventForwarding() { | 624 void SyncBackendHostCore::DisableProtocolEventForwarding() { |
| 625 DCHECK(thread_checker_.CalledOnValidThread()); |
| 640 forward_protocol_events_ = false; | 626 forward_protocol_events_ = false; |
| 641 } | 627 } |
| 642 | 628 |
| 643 void SyncBackendHostCore::EnableDirectoryTypeDebugInfoForwarding() { | 629 void SyncBackendHostCore::EnableDirectoryTypeDebugInfoForwarding() { |
| 630 DCHECK(thread_checker_.CalledOnValidThread()); |
| 644 DCHECK(sync_manager_); | 631 DCHECK(sync_manager_); |
| 645 | 632 |
| 646 forward_type_info_ = true; | 633 forward_type_info_ = true; |
| 647 | 634 |
| 648 if (!sync_manager_->HasDirectoryTypeDebugInfoObserver(this)) | 635 if (!sync_manager_->HasDirectoryTypeDebugInfoObserver(this)) |
| 649 sync_manager_->RegisterDirectoryTypeDebugInfoObserver(this); | 636 sync_manager_->RegisterDirectoryTypeDebugInfoObserver(this); |
| 650 sync_manager_->RequestEmitDebugInfo(); | 637 sync_manager_->RequestEmitDebugInfo(); |
| 651 } | 638 } |
| 652 | 639 |
| 653 void SyncBackendHostCore::DisableDirectoryTypeDebugInfoForwarding() { | 640 void SyncBackendHostCore::DisableDirectoryTypeDebugInfoForwarding() { |
| 641 DCHECK(thread_checker_.CalledOnValidThread()); |
| 654 DCHECK(sync_manager_); | 642 DCHECK(sync_manager_); |
| 655 | 643 |
| 656 if (!forward_type_info_) | 644 if (!forward_type_info_) |
| 657 return; | 645 return; |
| 658 | 646 |
| 659 forward_type_info_ = false; | 647 forward_type_info_ = false; |
| 660 | 648 |
| 661 if (sync_manager_->HasDirectoryTypeDebugInfoObserver(this)) | 649 if (sync_manager_->HasDirectoryTypeDebugInfoObserver(this)) |
| 662 sync_manager_->UnregisterDirectoryTypeDebugInfoObserver(this); | 650 sync_manager_->UnregisterDirectoryTypeDebugInfoObserver(this); |
| 663 } | 651 } |
| 664 | 652 |
| 665 void SyncBackendHostCore::DeleteSyncDataFolder() { | 653 void SyncBackendHostCore::DeleteSyncDataFolder() { |
| 666 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 654 DCHECK(thread_checker_.CalledOnValidThread()); |
| 667 if (base::DirectoryExists(sync_data_folder_path_)) { | 655 if (base::DirectoryExists(sync_data_folder_path_)) { |
| 668 if (!base::DeleteFile(sync_data_folder_path_, true)) | 656 if (!base::DeleteFile(sync_data_folder_path_, true)) |
| 669 SLOG(DFATAL) << "Could not delete the Sync Data folder."; | 657 SLOG(DFATAL) << "Could not delete the Sync Data folder."; |
| 670 } | 658 } |
| 671 } | 659 } |
| 672 | 660 |
| 673 void SyncBackendHostCore::StartSavingChanges() { | 661 void SyncBackendHostCore::StartSavingChanges() { |
| 674 // We may already be shut down. | 662 DCHECK(thread_checker_.CalledOnValidThread()); |
| 675 if (!sync_loop_) | |
| 676 return; | |
| 677 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | |
| 678 DCHECK(!save_changes_timer_.get()); | 663 DCHECK(!save_changes_timer_.get()); |
| 679 save_changes_timer_ = base::MakeUnique<base::RepeatingTimer>(); | 664 save_changes_timer_ = base::MakeUnique<base::RepeatingTimer>(); |
| 680 save_changes_timer_->Start( | 665 save_changes_timer_->Start( |
| 681 FROM_HERE, base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds), | 666 FROM_HERE, base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds), |
| 682 this, &SyncBackendHostCore::SaveChanges); | 667 this, &SyncBackendHostCore::SaveChanges); |
| 683 } | 668 } |
| 684 | 669 |
| 685 void SyncBackendHostCore::SaveChanges() { | 670 void SyncBackendHostCore::SaveChanges() { |
| 686 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 671 DCHECK(thread_checker_.CalledOnValidThread()); |
| 687 sync_manager_->SaveChanges(); | 672 sync_manager_->SaveChanges(); |
| 688 } | 673 } |
| 689 | 674 |
| 690 void SyncBackendHostCore::DoClearServerData( | 675 void SyncBackendHostCore::DoClearServerData( |
| 691 const SyncManager::ClearServerDataCallback& frontend_callback) { | 676 const SyncManager::ClearServerDataCallback& frontend_callback) { |
| 692 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 677 DCHECK(thread_checker_.CalledOnValidThread()); |
| 693 const SyncManager::ClearServerDataCallback callback = | 678 const SyncManager::ClearServerDataCallback callback = |
| 694 base::Bind(&SyncBackendHostCore::ClearServerDataDone, | 679 base::Bind(&SyncBackendHostCore::ClearServerDataDone, |
| 695 weak_ptr_factory_.GetWeakPtr(), frontend_callback); | 680 weak_ptr_factory_.GetWeakPtr(), frontend_callback); |
| 696 sync_manager_->ClearServerData(callback); | 681 sync_manager_->ClearServerData(callback); |
| 697 } | 682 } |
| 698 | 683 |
| 699 void SyncBackendHostCore::DoOnCookieJarChanged(bool account_mismatch, | 684 void SyncBackendHostCore::DoOnCookieJarChanged(bool account_mismatch, |
| 700 bool empty_jar) { | 685 bool empty_jar) { |
| 701 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 686 DCHECK(thread_checker_.CalledOnValidThread()); |
| 702 sync_manager_->OnCookieJarChanged(account_mismatch, empty_jar); | 687 sync_manager_->OnCookieJarChanged(account_mismatch, empty_jar); |
| 703 } | 688 } |
| 704 | 689 |
| 705 void SyncBackendHostCore::ClearServerDataDone( | 690 void SyncBackendHostCore::ClearServerDataDone( |
| 706 const base::Closure& frontend_callback) { | 691 const base::Closure& frontend_callback) { |
| 707 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 692 DCHECK(thread_checker_.CalledOnValidThread()); |
| 708 host_.Call(FROM_HERE, &SyncBackendHostImpl::ClearServerDataDoneOnFrontendLoop, | 693 host_.Call(FROM_HERE, &SyncBackendHostImpl::ClearServerDataDoneOnFrontendLoop, |
| 709 frontend_callback); | 694 frontend_callback); |
| 710 } | 695 } |
| 711 | 696 |
| 712 } // namespace syncer | 697 } // namespace syncer |
| OLD | NEW |