Chromium Code Reviews| 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 "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/bind.h" | |
| 8 #include "base/callback.h" | |
| 7 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 8 #include "base/location.h" | 10 #include "base/location.h" |
| 9 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 10 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 11 #include "chrome/browser/sync/glue/local_device_info_provider_impl.h" | 13 #include "chrome/browser/sync/glue/local_device_info_provider_impl.h" |
| 12 #include "chrome/browser/sync/glue/sync_backend_registrar.h" | 14 #include "chrome/browser/sync/glue/sync_backend_registrar.h" |
| 15 #include "components/data_use_measurement/core/data_use_user_data.h" | |
| 13 #include "components/invalidation/public/invalidation_util.h" | 16 #include "components/invalidation/public/invalidation_util.h" |
| 14 #include "components/invalidation/public/object_id_invalidation_map.h" | 17 #include "components/invalidation/public/object_id_invalidation_map.h" |
| 15 #include "components/sync_driver/invalidation_adapter.h" | 18 #include "components/sync_driver/invalidation_adapter.h" |
| 16 #include "sync/internal_api/public/events/protocol_event.h" | 19 #include "sync/internal_api/public/events/protocol_event.h" |
| 17 #include "sync/internal_api/public/http_post_provider_factory.h" | 20 #include "sync/internal_api/public/http_post_provider_factory.h" |
| 18 #include "sync/internal_api/public/internal_components_factory.h" | 21 #include "sync/internal_api/public/internal_components_factory.h" |
| 19 #include "sync/internal_api/public/sessions/commit_counters.h" | 22 #include "sync/internal_api/public/sessions/commit_counters.h" |
| 20 #include "sync/internal_api/public/sessions/status_counters.h" | 23 #include "sync/internal_api/public/sessions/status_counters.h" |
| 21 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" | 24 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" |
| 22 #include "sync/internal_api/public/sessions/update_counters.h" | 25 #include "sync/internal_api/public/sessions/update_counters.h" |
| 23 #include "sync/internal_api/public/sync_context_proxy.h" | 26 #include "sync/internal_api/public/sync_context_proxy.h" |
| 24 #include "sync/internal_api/public/sync_manager.h" | 27 #include "sync/internal_api/public/sync_manager.h" |
| 25 #include "sync/internal_api/public/sync_manager_factory.h" | 28 #include "sync/internal_api/public/sync_manager_factory.h" |
| 26 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 27 | 30 |
| 28 // Helper macros to log with the syncer thread name; useful when there | 31 // Helper macros to log with the syncer thread name; useful when there |
| 29 // are multiple syncers involved. | 32 // are multiple syncers involved. |
| 30 | 33 |
| 31 #define SLOG(severity) LOG(severity) << name_ << ": " | 34 #define SLOG(severity) LOG(severity) << name_ << ": " |
| 32 | 35 |
| 33 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " | 36 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " |
| 34 | 37 |
| 35 static const int kSaveChangesIntervalSeconds = 10; | 38 static const int kSaveChangesIntervalSeconds = 10; |
| 36 | 39 |
| 37 namespace syncer { | 40 namespace syncer { |
| 38 class InternalComponentsFactory; | 41 class InternalComponentsFactory; |
| 39 } // namespace syncer | 42 } |
| 43 // namespace syncer | |
|
amohammadkhan
2015/09/09 18:49:22
I'll move the comment up in next CL upload.
| |
| 44 | |
| 45 namespace net { | |
| 46 class URLFetcher; | |
| 47 } | |
| 40 | 48 |
| 41 namespace { | 49 namespace { |
| 42 | 50 |
| 43 // Enums for UMAs. | 51 // Enums for UMAs. |
| 44 enum SyncBackendInitState { | 52 enum SyncBackendInitState { |
| 45 SETUP_COMPLETED_FOUND_RESTORED_TYPES = 0, | 53 SETUP_COMPLETED_FOUND_RESTORED_TYPES = 0, |
| 46 SETUP_COMPLETED_NO_RESTORED_TYPES, | 54 SETUP_COMPLETED_NO_RESTORED_TYPES, |
| 47 FIRST_SETUP_NO_RESTORED_TYPES, | 55 FIRST_SETUP_NO_RESTORED_TYPES, |
| 48 FIRST_SETUP_RESTORED_TYPES, | 56 FIRST_SETUP_RESTORED_TYPES, |
| 49 SYNC_BACKEND_INIT_STATE_COUNT | 57 SYNC_BACKEND_INIT_STATE_COUNT |
| 50 }; | 58 }; |
| 51 | 59 |
| 60 void BindFetcherToDataTracker(net::URLFetcher* fetcher) { | |
| 61 data_use_measurement::DataUseUserData::AttachToFetcher( | |
| 62 fetcher, data_use_measurement::DataUseUserData::SYNC); | |
| 63 } | |
| 64 | |
| 52 } // namespace | 65 } // namespace |
| 53 | 66 |
| 54 namespace browser_sync { | 67 namespace browser_sync { |
| 55 | 68 |
| 56 DoInitializeOptions::DoInitializeOptions( | 69 DoInitializeOptions::DoInitializeOptions( |
| 57 base::MessageLoop* sync_loop, | 70 base::MessageLoop* sync_loop, |
| 58 SyncBackendRegistrar* registrar, | 71 SyncBackendRegistrar* registrar, |
| 59 const syncer::ModelSafeRoutingInfo& routing_info, | 72 const syncer::ModelSafeRoutingInfo& routing_info, |
| 60 const std::vector<scoped_refptr<syncer::ModelSafeWorker>>& workers, | 73 const std::vector<scoped_refptr<syncer::ModelSafeWorker>>& workers, |
| 61 const scoped_refptr<syncer::ExtensionsActivity>& extensions_activity, | 74 const scoped_refptr<syncer::ExtensionsActivity>& extensions_activity, |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 } | 431 } |
| 419 | 432 |
| 420 void SyncBackendHostCore::DoInitialize( | 433 void SyncBackendHostCore::DoInitialize( |
| 421 scoped_ptr<DoInitializeOptions> options) { | 434 scoped_ptr<DoInitializeOptions> options) { |
| 422 DCHECK(!sync_loop_); | 435 DCHECK(!sync_loop_); |
| 423 sync_loop_ = options->sync_loop; | 436 sync_loop_ = options->sync_loop; |
| 424 DCHECK(sync_loop_); | 437 DCHECK(sync_loop_); |
| 425 | 438 |
| 426 // Finish initializing the HttpBridgeFactory. We do this here because | 439 // Finish initializing the HttpBridgeFactory. We do this here because |
| 427 // building the user agent may block on some platforms. | 440 // building the user agent may block on some platforms. |
| 428 options->http_bridge_factory->Init(options->sync_user_agent); | 441 options->http_bridge_factory->Init(options->sync_user_agent, |
| 442 base::Bind(&BindFetcherToDataTracker)); | |
| 429 | 443 |
| 430 // Blow away the partial or corrupt sync data folder before doing any more | 444 // Blow away the partial or corrupt sync data folder before doing any more |
| 431 // initialization, if necessary. | 445 // initialization, if necessary. |
| 432 if (options->delete_sync_data_folder) { | 446 if (options->delete_sync_data_folder) { |
| 433 DeleteSyncDataFolder(); | 447 DeleteSyncDataFolder(); |
| 434 } | 448 } |
| 435 | 449 |
| 436 // Make sure that the directory exists before initializing the backend. | 450 // Make sure that the directory exists before initializing the backend. |
| 437 // If it already exists, this will do no harm. | 451 // If it already exists, this will do no harm. |
| 438 if (!base::CreateDirectory(sync_data_folder_path_)) { | 452 if (!base::CreateDirectory(sync_data_folder_path_)) { |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 770 | 784 |
| 771 void SyncBackendHostCore::ClearServerDataDone( | 785 void SyncBackendHostCore::ClearServerDataDone( |
| 772 const base::Closure& frontend_callback) { | 786 const base::Closure& frontend_callback) { |
| 773 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 787 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
| 774 host_.Call(FROM_HERE, &SyncBackendHostImpl::ClearServerDataDoneOnFrontendLoop, | 788 host_.Call(FROM_HERE, &SyncBackendHostImpl::ClearServerDataDoneOnFrontendLoop, |
| 775 frontend_callback); | 789 frontend_callback); |
| 776 } | 790 } |
| 777 | 791 |
| 778 | 792 |
| 779 } // namespace browser_sync | 793 } // namespace browser_sync |
| OLD | NEW |