| 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/metrics/histogram.h" | |
| 13 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 14 #include "components/data_use_measurement/core/data_use_user_data.h" | 13 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 15 #include "components/invalidation/public/invalidation_util.h" | 14 #include "components/invalidation/public/invalidation_util.h" |
| 16 #include "components/invalidation/public/object_id_invalidation_map.h" | 15 #include "components/invalidation/public/object_id_invalidation_map.h" |
| 17 #include "components/sync_driver/glue/sync_backend_registrar.h" | 16 #include "components/sync_driver/glue/sync_backend_registrar.h" |
| 18 #include "components/sync_driver/invalidation_adapter.h" | 17 #include "components/sync_driver/invalidation_adapter.h" |
| 19 #include "components/sync_driver/local_device_info_provider_impl.h" | 18 #include "components/sync_driver/local_device_info_provider_impl.h" |
| 20 #include "sync/internal_api/public/events/protocol_event.h" | 19 #include "sync/internal_api/public/events/protocol_event.h" |
| 21 #include "sync/internal_api/public/http_post_provider_factory.h" | 20 #include "sync/internal_api/public/http_post_provider_factory.h" |
| 22 #include "sync/internal_api/public/internal_components_factory.h" | 21 #include "sync/internal_api/public/internal_components_factory.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 40 namespace syncer { | 39 namespace syncer { |
| 41 class InternalComponentsFactory; | 40 class InternalComponentsFactory; |
| 42 } // namespace syncer | 41 } // namespace syncer |
| 43 | 42 |
| 44 namespace net { | 43 namespace net { |
| 45 class URLFetcher; | 44 class URLFetcher; |
| 46 } | 45 } |
| 47 | 46 |
| 48 namespace { | 47 namespace { |
| 49 | 48 |
| 50 // Enums for UMAs. | |
| 51 enum SyncBackendInitState { | |
| 52 SETUP_COMPLETED_FOUND_RESTORED_TYPES = 0, | |
| 53 SETUP_COMPLETED_NO_RESTORED_TYPES, | |
| 54 FIRST_SETUP_NO_RESTORED_TYPES, | |
| 55 FIRST_SETUP_RESTORED_TYPES, | |
| 56 SYNC_BACKEND_INIT_STATE_COUNT | |
| 57 }; | |
| 58 | |
| 59 void BindFetcherToDataTracker(net::URLFetcher* fetcher) { | 49 void BindFetcherToDataTracker(net::URLFetcher* fetcher) { |
| 60 data_use_measurement::DataUseUserData::AttachToFetcher( | 50 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 61 fetcher, data_use_measurement::DataUseUserData::SYNC); | 51 fetcher, data_use_measurement::DataUseUserData::SYNC); |
| 62 } | 52 } |
| 63 | 53 |
| 64 } // namespace | 54 } // namespace |
| 65 | 55 |
| 66 namespace browser_sync { | 56 namespace browser_sync { |
| 67 | 57 |
| 68 DoInitializeOptions::DoInitializeOptions( | 58 DoInitializeOptions::DoInitializeOptions( |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 // SaveChanges. | 171 // SaveChanges. |
| 182 sync_loop_->task_runner()->PostTask( | 172 sync_loop_->task_runner()->PostTask( |
| 183 FROM_HERE, base::Bind(&SyncBackendHostCore::StartSavingChanges, | 173 FROM_HERE, base::Bind(&SyncBackendHostCore::StartSavingChanges, |
| 184 weak_ptr_factory_.GetWeakPtr())); | 174 weak_ptr_factory_.GetWeakPtr())); |
| 185 | 175 |
| 186 // Hang on to these for a while longer. We're not ready to hand them back to | 176 // Hang on to these for a while longer. We're not ready to hand them back to |
| 187 // the UI thread yet. | 177 // the UI thread yet. |
| 188 js_backend_ = js_backend; | 178 js_backend_ = js_backend; |
| 189 debug_info_listener_ = debug_info_listener; | 179 debug_info_listener_ = debug_info_listener; |
| 190 | 180 |
| 191 // Track whether or not sync DB and preferences were in sync. | |
| 192 SyncBackendInitState backend_init_state; | |
| 193 if (has_sync_setup_completed_ && !restored_types.Empty()) { | |
| 194 backend_init_state = SETUP_COMPLETED_FOUND_RESTORED_TYPES; | |
| 195 } else if (has_sync_setup_completed_ && restored_types.Empty()) { | |
| 196 backend_init_state = SETUP_COMPLETED_NO_RESTORED_TYPES; | |
| 197 } else if (!has_sync_setup_completed_ && restored_types.Empty()) { | |
| 198 backend_init_state = FIRST_SETUP_NO_RESTORED_TYPES; | |
| 199 } else { // (!has_sync_setup_completed_ && !restored_types.Empty()) | |
| 200 backend_init_state = FIRST_SETUP_RESTORED_TYPES; | |
| 201 } | |
| 202 | |
| 203 UMA_HISTOGRAM_ENUMERATION("Sync.BackendInitializeRestoreState", | |
| 204 backend_init_state, | |
| 205 SYNC_BACKEND_INIT_STATE_COUNT); | |
| 206 | |
| 207 // Before proceeding any further, we need to download the control types and | 181 // Before proceeding any further, we need to download the control types and |
| 208 // purge any partial data (ie. data downloaded for a type that was on its way | 182 // purge any partial data (ie. data downloaded for a type that was on its way |
| 209 // to being initially synced, but didn't quite make it.). The following | 183 // to being initially synced, but didn't quite make it.). The following |
| 210 // configure cycle will take care of this. It depends on the registrar state | 184 // configure cycle will take care of this. It depends on the registrar state |
| 211 // which we initialize below to ensure that we don't perform any downloads if | 185 // which we initialize below to ensure that we don't perform any downloads if |
| 212 // all control types have already completed their initial sync. | 186 // all control types have already completed their initial sync. |
| 213 registrar_->SetInitialTypes(restored_types); | 187 registrar_->SetInitialTypes(restored_types); |
| 214 | 188 |
| 215 syncer::ConfigureReason reason = | 189 syncer::ConfigureReason reason = |
| 216 restored_types.Empty() ? | 190 restored_types.Empty() ? |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 | 762 |
| 789 void SyncBackendHostCore::ClearServerDataDone( | 763 void SyncBackendHostCore::ClearServerDataDone( |
| 790 const base::Closure& frontend_callback) { | 764 const base::Closure& frontend_callback) { |
| 791 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 765 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
| 792 host_.Call(FROM_HERE, &SyncBackendHostImpl::ClearServerDataDoneOnFrontendLoop, | 766 host_.Call(FROM_HERE, &SyncBackendHostImpl::ClearServerDataDoneOnFrontendLoop, |
| 793 frontend_callback); | 767 frontend_callback); |
| 794 } | 768 } |
| 795 | 769 |
| 796 | 770 |
| 797 } // namespace browser_sync | 771 } // namespace browser_sync |
| OLD | NEW |