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

Side by Side Diff: chrome/browser/sync/glue/sync_backend_host_core.cc

Issue 566623003: Refactor syncable DEVICE_INFO type from ChangeProcessor to SyncableService - part 3. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More CR feedback addressed in DeviceInfoSyncService. Created 6 years, 3 months 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 "chrome/browser/sync/glue/sync_backend_host_core.h" 5 #include "chrome/browser/sync/glue/sync_backend_host_core.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "chrome/browser/sync/glue/device_info.h" 9 #include "chrome/browser/sync/glue/device_info.h"
10 #include "chrome/browser/sync/glue/invalidation_adapter.h" 10 #include "chrome/browser/sync/glue/invalidation_adapter.h"
11 #include "chrome/browser/sync/glue/sync_backend_registrar.h" 11 #include "chrome/browser/sync/glue/sync_backend_registrar.h"
12 #include "chrome/browser/sync/glue/synced_device_tracker.h"
13 #include "chrome/common/chrome_version_info.h" 12 #include "chrome/common/chrome_version_info.h"
14 #include "components/invalidation/invalidation_util.h" 13 #include "components/invalidation/invalidation_util.h"
15 #include "components/invalidation/object_id_invalidation_map.h" 14 #include "components/invalidation/object_id_invalidation_map.h"
16 #include "sync/internal_api/public/events/protocol_event.h" 15 #include "sync/internal_api/public/events/protocol_event.h"
17 #include "sync/internal_api/public/http_post_provider_factory.h" 16 #include "sync/internal_api/public/http_post_provider_factory.h"
18 #include "sync/internal_api/public/internal_components_factory.h" 17 #include "sync/internal_api/public/internal_components_factory.h"
19 #include "sync/internal_api/public/sessions/commit_counters.h" 18 #include "sync/internal_api/public/sessions/commit_counters.h"
20 #include "sync/internal_api/public/sessions/status_counters.h" 19 #include "sync/internal_api/public/sessions/status_counters.h"
21 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" 20 #include "sync/internal_api/public/sessions/sync_session_snapshot.h"
22 #include "sync/internal_api/public/sessions/update_counters.h" 21 #include "sync/internal_api/public/sessions/update_counters.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 scoped_ptr<syncer::HttpPostProviderFactory> http_bridge_factory, 63 scoped_ptr<syncer::HttpPostProviderFactory> http_bridge_factory,
65 const syncer::SyncCredentials& credentials, 64 const syncer::SyncCredentials& credentials,
66 const std::string& invalidator_client_id, 65 const std::string& invalidator_client_id,
67 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory, 66 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory,
68 bool delete_sync_data_folder, 67 bool delete_sync_data_folder,
69 const std::string& restored_key_for_bootstrapping, 68 const std::string& restored_key_for_bootstrapping,
70 const std::string& restored_keystore_key_for_bootstrapping, 69 const std::string& restored_keystore_key_for_bootstrapping,
71 scoped_ptr<syncer::InternalComponentsFactory> internal_components_factory, 70 scoped_ptr<syncer::InternalComponentsFactory> internal_components_factory,
72 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler, 71 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler,
73 syncer::ReportUnrecoverableErrorFunction 72 syncer::ReportUnrecoverableErrorFunction
74 report_unrecoverable_error_function, 73 report_unrecoverable_error_function)
75 const std::string& signin_scoped_device_id)
76 : sync_loop(sync_loop), 74 : sync_loop(sync_loop),
77 registrar(registrar), 75 registrar(registrar),
78 routing_info(routing_info), 76 routing_info(routing_info),
79 workers(workers), 77 workers(workers),
80 extensions_activity(extensions_activity), 78 extensions_activity(extensions_activity),
81 event_handler(event_handler), 79 event_handler(event_handler),
82 service_url(service_url), 80 service_url(service_url),
83 http_bridge_factory(http_bridge_factory.Pass()), 81 http_bridge_factory(http_bridge_factory.Pass()),
84 credentials(credentials), 82 credentials(credentials),
85 invalidator_client_id(invalidator_client_id), 83 invalidator_client_id(invalidator_client_id),
86 sync_manager_factory(sync_manager_factory.Pass()), 84 sync_manager_factory(sync_manager_factory.Pass()),
87 delete_sync_data_folder(delete_sync_data_folder), 85 delete_sync_data_folder(delete_sync_data_folder),
88 restored_key_for_bootstrapping(restored_key_for_bootstrapping), 86 restored_key_for_bootstrapping(restored_key_for_bootstrapping),
89 restored_keystore_key_for_bootstrapping( 87 restored_keystore_key_for_bootstrapping(
90 restored_keystore_key_for_bootstrapping), 88 restored_keystore_key_for_bootstrapping),
91 internal_components_factory(internal_components_factory.Pass()), 89 internal_components_factory(internal_components_factory.Pass()),
92 unrecoverable_error_handler(unrecoverable_error_handler.Pass()), 90 unrecoverable_error_handler(unrecoverable_error_handler.Pass()),
93 report_unrecoverable_error_function(report_unrecoverable_error_function), 91 report_unrecoverable_error_function(report_unrecoverable_error_function) {
94 signin_scoped_device_id(signin_scoped_device_id) {
95 } 92 }
96 93
97 DoInitializeOptions::~DoInitializeOptions() {} 94 DoInitializeOptions::~DoInitializeOptions() {}
98 95
99 DoConfigureSyncerTypes::DoConfigureSyncerTypes() {} 96 DoConfigureSyncerTypes::DoConfigureSyncerTypes() {}
100 97
101 DoConfigureSyncerTypes::~DoConfigureSyncerTypes() {} 98 DoConfigureSyncerTypes::~DoConfigureSyncerTypes() {}
102 99
103 SyncBackendHostCore::SyncBackendHostCore( 100 SyncBackendHostCore::SyncBackendHostCore(
104 const std::string& name, 101 const std::string& name,
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 } 394 }
398 } 395 }
399 } 396 }
400 397
401 void SyncBackendHostCore::DoInitialize( 398 void SyncBackendHostCore::DoInitialize(
402 scoped_ptr<DoInitializeOptions> options) { 399 scoped_ptr<DoInitializeOptions> options) {
403 DCHECK(!sync_loop_); 400 DCHECK(!sync_loop_);
404 sync_loop_ = options->sync_loop; 401 sync_loop_ = options->sync_loop;
405 DCHECK(sync_loop_); 402 DCHECK(sync_loop_);
406 403
407 signin_scoped_device_id_ = options->signin_scoped_device_id;
408
409 // Finish initializing the HttpBridgeFactory. We do this here because 404 // Finish initializing the HttpBridgeFactory. We do this here because
410 // building the user agent may block on some platforms. 405 // building the user agent may block on some platforms.
411 chrome::VersionInfo version_info; 406 chrome::VersionInfo version_info;
412 options->http_bridge_factory->Init( 407 options->http_bridge_factory->Init(
413 DeviceInfo::MakeUserAgentForSyncApi(version_info)); 408 DeviceInfo::MakeUserAgentForSyncApi(version_info));
414 409
415 // Blow away the partial or corrupt sync data folder before doing any more 410 // Blow away the partial or corrupt sync data folder before doing any more
416 // initialization, if necessary. 411 // initialization, if necessary.
417 if (options->delete_sync_data_folder) { 412 if (options->delete_sync_data_folder) {
418 DeleteSyncDataFolder(); 413 DeleteSyncDataFolder();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } 497 }
503 498
504 if (!sync_manager_->InitialSyncEndedTypes().HasAll(syncer::ControlTypes())) { 499 if (!sync_manager_->InitialSyncEndedTypes().HasAll(syncer::ControlTypes())) {
505 LOG(ERROR) << "Failed to download control types"; 500 LOG(ERROR) << "Failed to download control types";
506 host_.Call( 501 host_.Call(
507 FROM_HERE, 502 FROM_HERE,
508 &SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop); 503 &SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop);
509 return; 504 return;
510 } 505 }
511 506
512 // Initialize device info. This is asynchronous on some platforms, so we
513 // provide a callback for when it finishes.
514 synced_device_tracker_.reset(
515 new SyncedDeviceTracker(sync_manager_->GetUserShare(),
516 sync_manager_->cache_guid()));
517 synced_device_tracker_->InitLocalDeviceInfo(
518 signin_scoped_device_id_,
519 base::Bind(&SyncBackendHostCore::DoFinishInitialProcessControlTypes,
520 weak_ptr_factory_.GetWeakPtr()));
521 }
522
523 void SyncBackendHostCore::DoFinishInitialProcessControlTypes() {
524 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
525
526 registrar_->ActivateDataType(syncer::DEVICE_INFO,
527 syncer::GROUP_PASSIVE,
528 synced_device_tracker_.get(),
529 sync_manager_->GetUserShare());
530
531 host_.Call(FROM_HERE, 507 host_.Call(FROM_HERE,
532 &SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop, 508 &SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop,
533 js_backend_, 509 js_backend_,
534 debug_info_listener_, 510 debug_info_listener_,
535 sync_manager_->GetSyncContextProxy(), 511 sync_manager_->GetSyncContextProxy(),
536 sync_manager_->cache_guid()); 512 sync_manager_->cache_guid());
537 513
538 js_backend_.Reset(); 514 js_backend_.Reset();
539 debug_info_listener_.Reset(); 515 debug_info_listener_.Reset();
540 } 516 }
(...skipping 27 matching lines...) Expand all
568 // no longer be used to create new HttpBridge instances. We can get away with 544 // no longer be used to create new HttpBridge instances. We can get away with
569 // this because the stop_syncing_signal_ has already been signalled, which 545 // this because the stop_syncing_signal_ has already been signalled, which
570 // guarantees that the ServerConnectionManager will no longer attempt to 546 // guarantees that the ServerConnectionManager will no longer attempt to
571 // create new connections. 547 // create new connections.
572 release_request_context_signal_.Signal(); 548 release_request_context_signal_.Signal();
573 } 549 }
574 550
575 void SyncBackendHostCore::DoShutdown(syncer::ShutdownReason reason) { 551 void SyncBackendHostCore::DoShutdown(syncer::ShutdownReason reason) {
576 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); 552 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
577 553
578 // It's safe to do this even if the type was never activated.
579 registrar_->DeactivateDataType(syncer::DEVICE_INFO);
580 synced_device_tracker_.reset();
581
582 DoDestroySyncManager(reason); 554 DoDestroySyncManager(reason);
583 555
584 registrar_ = NULL; 556 registrar_ = NULL;
585 557
586 if (reason == syncer::DISABLE_SYNC) 558 if (reason == syncer::DISABLE_SYNC)
587 DeleteSyncDataFolder(); 559 DeleteSyncDataFolder();
588 560
589 host_.Reset(); 561 host_.Reset();
590 weak_ptr_factory_.InvalidateWeakPtrs(); 562 weak_ptr_factory_.InvalidateWeakPtrs();
591 } 563 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds), 728 base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds),
757 this, &SyncBackendHostCore::SaveChanges); 729 this, &SyncBackendHostCore::SaveChanges);
758 } 730 }
759 731
760 void SyncBackendHostCore::SaveChanges() { 732 void SyncBackendHostCore::SaveChanges() {
761 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); 733 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
762 sync_manager_->SaveChanges(); 734 sync_manager_->SaveChanges();
763 } 735 }
764 736
765 } // namespace browser_sync 737 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_host_core.h ('k') | chrome/browser/sync/glue/sync_backend_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698