Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(871)

Side by Side Diff: components/sync/driver/glue/sync_backend_host_core.cc

Issue 2559123002: [Sync] SyncEngine refactor part 2: SyncServiceBase. (Closed)
Patch Set: Address comments. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 data_use_measurement::DataUseUserData::AttachToFetcher( 48 data_use_measurement::DataUseUserData::AttachToFetcher(
49 fetcher, data_use_measurement::DataUseUserData::SYNC); 49 fetcher, data_use_measurement::DataUseUserData::SYNC);
50 } 50 }
51 51
52 } // namespace 52 } // namespace
53 53
54 namespace syncer { 54 namespace syncer {
55 55
56 class EngineComponentsFactory; 56 class EngineComponentsFactory;
57 57
58 DoInitializeOptions::DoInitializeOptions(
59 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner,
60 SyncBackendRegistrar* registrar,
61 const std::vector<scoped_refptr<ModelSafeWorker>>& workers,
62 const scoped_refptr<ExtensionsActivity>& extensions_activity,
63 const WeakHandle<JsEventHandler>& event_handler,
64 const GURL& service_url,
65 const std::string& sync_user_agent,
66 std::unique_ptr<HttpPostProviderFactory> http_bridge_factory,
67 const SyncCredentials& credentials,
68 const std::string& invalidator_client_id,
69 std::unique_ptr<SyncManagerFactory> sync_manager_factory,
70 bool delete_sync_data_folder,
71 bool enable_local_sync_backend,
72 const base::FilePath& local_sync_backend_folder,
73 const std::string& restored_key_for_bootstrapping,
74 const std::string& restored_keystore_key_for_bootstrapping,
75 std::unique_ptr<EngineComponentsFactory> engine_components_factory,
76 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler,
77 const base::Closure& report_unrecoverable_error_function,
78 std::unique_ptr<SyncEncryptionHandler::NigoriState> saved_nigori_state,
79 const std::map<ModelType, int64_t>& invalidation_versions)
80 : sync_task_runner(std::move(sync_task_runner)),
81 registrar(registrar),
82 workers(workers),
83 extensions_activity(extensions_activity),
84 event_handler(event_handler),
85 service_url(service_url),
86 sync_user_agent(sync_user_agent),
87 http_bridge_factory(std::move(http_bridge_factory)),
88 credentials(credentials),
89 invalidator_client_id(invalidator_client_id),
90 sync_manager_factory(std::move(sync_manager_factory)),
91 delete_sync_data_folder(delete_sync_data_folder),
92 enable_local_sync_backend(enable_local_sync_backend),
93 local_sync_backend_folder(local_sync_backend_folder),
94 restored_key_for_bootstrapping(restored_key_for_bootstrapping),
95 restored_keystore_key_for_bootstrapping(
96 restored_keystore_key_for_bootstrapping),
97 engine_components_factory(std::move(engine_components_factory)),
98 unrecoverable_error_handler(unrecoverable_error_handler),
99 report_unrecoverable_error_function(report_unrecoverable_error_function),
100 saved_nigori_state(std::move(saved_nigori_state)),
101 invalidation_versions(invalidation_versions) {}
102
103 DoInitializeOptions::~DoInitializeOptions() {}
104
105 SyncBackendHostCore::SyncBackendHostCore( 58 SyncBackendHostCore::SyncBackendHostCore(
106 const std::string& name, 59 const std::string& name,
107 const base::FilePath& sync_data_folder_path, 60 const base::FilePath& sync_data_folder_path,
108 const base::WeakPtr<SyncBackendHostImpl>& backend) 61 const base::WeakPtr<SyncBackendHostImpl>& backend)
109 : name_(name), 62 : name_(name),
110 sync_data_folder_path_(sync_data_folder_path), 63 sync_data_folder_path_(sync_data_folder_path),
111 host_(backend), 64 host_(backend),
112 weak_ptr_factory_(this) { 65 weak_ptr_factory_(this) {
113 DCHECK(backend.get()); 66 DCHECK(backend.get());
114 // This is constructed on the UI thread but used from the sync thread. 67 // This is constructed on the UI thread but used from the sync thread.
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 if (!invalidation.is_unknown_version()) 312 if (!invalidation.is_unknown_version())
360 last_invalidation_versions_[type] = invalidation.version(); 313 last_invalidation_versions_[type] = invalidation.version();
361 } 314 }
362 } 315 }
363 } 316 }
364 317
365 host_.Call(FROM_HERE, &SyncBackendHostImpl::UpdateInvalidationVersions, 318 host_.Call(FROM_HERE, &SyncBackendHostImpl::UpdateInvalidationVersions,
366 last_invalidation_versions_); 319 last_invalidation_versions_);
367 } 320 }
368 321
369 void SyncBackendHostCore::DoInitialize( 322 void SyncBackendHostCore::DoInitialize(SyncEngine::InitParams params) {
370 std::unique_ptr<DoInitializeOptions> options) {
371 DCHECK(thread_checker_.CalledOnValidThread()); 323 DCHECK(thread_checker_.CalledOnValidThread());
372 324
373 // Finish initializing the HttpBridgeFactory. We do this here because
374 // building the user agent may block on some platforms.
375 options->http_bridge_factory->Init(options->sync_user_agent,
376 base::Bind(&BindFetcherToDataTracker));
377
378 // Blow away the partial or corrupt sync data folder before doing any more 325 // Blow away the partial or corrupt sync data folder before doing any more
379 // initialization, if necessary. 326 // initialization, if necessary.
380 if (options->delete_sync_data_folder) { 327 if (params.delete_sync_data_folder) {
381 DeleteSyncDataFolder(); 328 DeleteSyncDataFolder();
382 } 329 }
383 330
384 // Make sure that the directory exists before initializing the backend. 331 // Make sure that the directory exists before initializing the backend.
385 // If it already exists, this will do no harm. 332 // If it already exists, this will do no harm.
386 if (!base::CreateDirectory(sync_data_folder_path_)) { 333 if (!base::CreateDirectory(sync_data_folder_path_)) {
387 DLOG(FATAL) << "Sync Data directory creation failed."; 334 DLOG(FATAL) << "Sync Data directory creation failed.";
388 } 335 }
389 336
390 // Load the previously persisted set of invalidation versions into memory. 337 // Load the previously persisted set of invalidation versions into memory.
391 last_invalidation_versions_ = options->invalidation_versions; 338 last_invalidation_versions_ = params.invalidation_versions;
392 339
393 DCHECK(!registrar_); 340 DCHECK(!registrar_);
394 registrar_ = options->registrar; 341 registrar_ = std::move(params.registrar);
395 DCHECK(registrar_); 342 DCHECK(registrar_);
396 343
397 sync_manager_ = options->sync_manager_factory->CreateSyncManager(name_); 344 sync_manager_ = params.sync_manager_factory->CreateSyncManager(name_);
398 sync_manager_->AddObserver(this); 345 sync_manager_->AddObserver(this);
399 346
400 SyncManager::InitArgs args; 347 SyncManager::InitArgs args;
401 args.database_location = sync_data_folder_path_; 348 args.database_location = sync_data_folder_path_;
402 args.event_handler = options->event_handler; 349 args.event_handler = params.event_handler;
403 args.service_url = options->service_url; 350 args.service_url = params.service_url;
404 args.enable_local_sync_backend = options->enable_local_sync_backend; 351 args.enable_local_sync_backend = params.enable_local_sync_backend;
405 args.local_sync_backend_folder = options->local_sync_backend_folder; 352 args.local_sync_backend_folder = params.local_sync_backend_folder;
406 args.post_factory = std::move(options->http_bridge_factory); 353 args.post_factory =
407 args.workers = options->workers; 354 params.http_factory_getter.Run(&release_request_context_signal_);
408 args.extensions_activity = options->extensions_activity.get(); 355 // Finish initializing the HttpBridgeFactory. We do this here because
409 args.change_delegate = options->registrar; // as SyncManager::ChangeDelegate 356 // building the user agent may block on some platforms.
410 args.credentials = options->credentials; 357 args.post_factory->Init(params.sync_user_agent,
411 args.invalidator_client_id = options->invalidator_client_id; 358 base::Bind(&BindFetcherToDataTracker));
412 args.restored_key_for_bootstrapping = options->restored_key_for_bootstrapping; 359 registrar_->GetWorkers(&args.workers);
360 args.extensions_activity = params.extensions_activity.get();
361 args.change_delegate = registrar_.get(); // as SyncManager::ChangeDelegate
362 args.credentials = params.credentials;
363 args.invalidator_client_id = params.invalidator_client_id;
364 args.restored_key_for_bootstrapping = params.restored_key_for_bootstrapping;
413 args.restored_keystore_key_for_bootstrapping = 365 args.restored_keystore_key_for_bootstrapping =
414 options->restored_keystore_key_for_bootstrapping; 366 params.restored_keystore_key_for_bootstrapping;
415 args.engine_components_factory = 367 args.engine_components_factory = std::move(params.engine_components_factory);
416 std::move(options->engine_components_factory);
417 args.encryptor = &encryptor_; 368 args.encryptor = &encryptor_;
418 args.unrecoverable_error_handler = options->unrecoverable_error_handler; 369 args.unrecoverable_error_handler = params.unrecoverable_error_handler;
419 args.report_unrecoverable_error_function = 370 args.report_unrecoverable_error_function =
420 options->report_unrecoverable_error_function; 371 params.report_unrecoverable_error_function;
421 args.cancelation_signal = &stop_syncing_signal_; 372 args.cancelation_signal = &stop_syncing_signal_;
422 args.saved_nigori_state = std::move(options->saved_nigori_state); 373 args.saved_nigori_state = std::move(params.saved_nigori_state);
423 sync_manager_->Init(&args); 374 sync_manager_->Init(&args);
424 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( 375 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
425 this, "SyncDirectory", base::ThreadTaskRunnerHandle::Get()); 376 this, "SyncDirectory", base::ThreadTaskRunnerHandle::Get());
426 } 377 }
427 378
428 void SyncBackendHostCore::DoUpdateCredentials( 379 void SyncBackendHostCore::DoUpdateCredentials(
429 const SyncCredentials& credentials) { 380 const SyncCredentials& credentials) {
430 DCHECK(thread_checker_.CalledOnValidThread()); 381 DCHECK(thread_checker_.CalledOnValidThread());
431 // UpdateCredentials can be called during backend initialization, possibly 382 // UpdateCredentials can be called during backend initialization, possibly
432 // when backend initialization has failed but hasn't notified the UI thread 383 // when backend initialization has failed but hasn't notified the UI thread
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 } 639 }
689 640
690 void SyncBackendHostCore::ClearServerDataDone( 641 void SyncBackendHostCore::ClearServerDataDone(
691 const base::Closure& frontend_callback) { 642 const base::Closure& frontend_callback) {
692 DCHECK(thread_checker_.CalledOnValidThread()); 643 DCHECK(thread_checker_.CalledOnValidThread());
693 host_.Call(FROM_HERE, &SyncBackendHostImpl::ClearServerDataDoneOnFrontendLoop, 644 host_.Call(FROM_HERE, &SyncBackendHostImpl::ClearServerDataDoneOnFrontendLoop,
694 frontend_callback); 645 frontend_callback);
695 } 646 }
696 647
697 } // namespace syncer 648 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/driver/glue/sync_backend_host_core.h ('k') | components/sync/driver/glue/sync_backend_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698