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