| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser_sync/profile_sync_service.h" | 5 #include "components/browser_sync/profile_sync_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <cstddef> | 9 #include <cstddef> |
| 10 #include <map> | 10 #include <map> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
| 15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 17 #include "base/feature_list.h" | 17 #include "base/feature_list.h" |
| 18 #include "base/files/file_util.h" | 18 #include "base/files/file_util.h" |
| 19 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 #include "base/memory/ptr_util.h" | 20 #include "base/memory/ptr_util.h" |
| 21 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
| 22 #include "base/metrics/histogram.h" | 22 #include "base/metrics/histogram.h" |
| 23 #include "base/path_service.h" | |
| 24 #include "base/profiler/scoped_tracker.h" | 23 #include "base/profiler/scoped_tracker.h" |
| 25 #include "base/single_thread_task_runner.h" | 24 #include "base/single_thread_task_runner.h" |
| 26 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
| 27 #include "base/threading/thread_restrictions.h" | 26 #include "base/threading/thread_restrictions.h" |
| 28 #include "base/threading/thread_task_runner_handle.h" | 27 #include "base/threading/thread_task_runner_handle.h" |
| 29 #include "components/autofill/core/common/autofill_pref_names.h" | 28 #include "components/autofill/core/common/autofill_pref_names.h" |
| 30 #include "components/browser_sync/browser_sync_switches.h" | 29 #include "components/browser_sync/browser_sync_switches.h" |
| 31 #include "components/history/core/browser/typed_url_data_type_controller.h" | 30 #include "components/history/core/browser/typed_url_data_type_controller.h" |
| 32 #include "components/invalidation/impl/invalidation_prefs.h" | 31 #include "components/invalidation/impl/invalidation_prefs.h" |
| 33 #include "components/invalidation/public/invalidation_service.h" | 32 #include "components/invalidation/public/invalidation_service.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 using syncer::SyncCredentials; | 111 using syncer::SyncCredentials; |
| 113 using syncer::SyncProtocolError; | 112 using syncer::SyncProtocolError; |
| 114 using syncer::WeakHandle; | 113 using syncer::WeakHandle; |
| 115 | 114 |
| 116 namespace browser_sync { | 115 namespace browser_sync { |
| 117 | 116 |
| 118 typedef GoogleServiceAuthError AuthError; | 117 typedef GoogleServiceAuthError AuthError; |
| 119 | 118 |
| 120 const char kSyncUnrecoverableErrorHistogram[] = "Sync.UnrecoverableErrors"; | 119 const char kSyncUnrecoverableErrorHistogram[] = "Sync.UnrecoverableErrors"; |
| 121 | 120 |
| 122 const base::FilePath::StringType kLoopbackServerBackendFilename = | |
| 123 FILE_PATH_LITERAL("profile.pb"); | |
| 124 | |
| 125 const net::BackoffEntry::Policy kRequestAccessTokenBackoffPolicy = { | 121 const net::BackoffEntry::Policy kRequestAccessTokenBackoffPolicy = { |
| 126 // Number of initial errors (in sequence) to ignore before applying | 122 // Number of initial errors (in sequence) to ignore before applying |
| 127 // exponential back-off rules. | 123 // exponential back-off rules. |
| 128 0, | 124 0, |
| 129 | 125 |
| 130 // Initial delay for exponential back-off in ms. | 126 // Initial delay for exponential back-off in ms. |
| 131 2000, | 127 2000, |
| 132 | 128 |
| 133 // Factor by which the waiting time will be multiplied. | 129 // Factor by which the waiting time will be multiplied. |
| 134 2, | 130 2, |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 if (!backend_) { | 495 if (!backend_) { |
| 500 NOTREACHED(); | 496 NOTREACHED(); |
| 501 return; | 497 return; |
| 502 } | 498 } |
| 503 | 499 |
| 504 SyncCredentials credentials = GetCredentials(); | 500 SyncCredentials credentials = GetCredentials(); |
| 505 | 501 |
| 506 if (delete_stale_data) | 502 if (delete_stale_data) |
| 507 ClearStaleErrors(); | 503 ClearStaleErrors(); |
| 508 | 504 |
| 509 bool enable_local_sync_backend = false; | |
| 510 base::FilePath local_sync_backend_folder; | |
| 511 #if defined(OS_WIN) | |
| 512 enable_local_sync_backend = base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 513 switches::kEnableLocalSyncBackend); | |
| 514 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 515 switches::kLocalSyncBackendDir)) { | |
| 516 local_sync_backend_folder = | |
| 517 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( | |
| 518 switches::kLocalSyncBackendDir); | |
| 519 } else { | |
| 520 // TODO(pastarmovj): Add DIR_ROAMING_USER_DATA to PathService to simplify | |
| 521 // this code and move the logic in its right place. See crbug/657810. | |
| 522 CHECK( | |
| 523 base::PathService::Get(base::DIR_APP_DATA, &local_sync_backend_folder)); | |
| 524 local_sync_backend_folder = | |
| 525 local_sync_backend_folder.Append(FILE_PATH_LITERAL("Chrome/User Data")); | |
| 526 } | |
| 527 // This code as it is now will assume the same profile order is present on all | |
| 528 // machines, which is not a given. It is to be defined if only the Default | |
| 529 // profile should get this treatment or all profile as is the case now. The | |
| 530 // solution for now will be to assume profiles are created in the same order | |
| 531 // on all machines and in the future decide if only the Default one should be | |
| 532 // considered roamed. | |
| 533 local_sync_backend_folder = | |
| 534 local_sync_backend_folder.Append(base_directory_.BaseName()); | |
| 535 local_sync_backend_folder = | |
| 536 local_sync_backend_folder.Append(kLoopbackServerBackendFilename); | |
| 537 #endif // defined(OS_WIN) | |
| 538 | |
| 539 SyncBackendHost::HttpPostProviderFactoryGetter | 505 SyncBackendHost::HttpPostProviderFactoryGetter |
| 540 http_post_provider_factory_getter = | 506 http_post_provider_factory_getter = |
| 541 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory, | 507 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory, |
| 542 base::Unretained(network_resources_.get()), | 508 base::Unretained(network_resources_.get()), |
| 543 url_request_context_, network_time_update_callback_); | 509 url_request_context_, network_time_update_callback_); |
| 544 | 510 |
| 545 backend_->Initialize( | 511 backend_->Initialize( |
| 546 this, std::move(sync_thread_), db_thread_, file_thread_, | 512 this, std::move(sync_thread_), db_thread_, file_thread_, |
| 547 GetJsEventHandler(), sync_service_url_, local_device_->GetSyncUserAgent(), | 513 GetJsEventHandler(), sync_service_url_, local_device_->GetSyncUserAgent(), |
| 548 credentials, delete_stale_data, enable_local_sync_backend, | 514 credentials, delete_stale_data, |
| 549 local_sync_backend_folder, std::unique_ptr<syncer::SyncManagerFactory>( | 515 std::unique_ptr<syncer::SyncManagerFactory>( |
| 550 new syncer::SyncManagerFactory()), | 516 new syncer::SyncManagerFactory()), |
| 551 MakeWeakHandle(sync_enabled_weak_factory_.GetWeakPtr()), | 517 MakeWeakHandle(sync_enabled_weak_factory_.GetWeakPtr()), |
| 552 base::Bind(syncer::ReportUnrecoverableError, channel_), | 518 base::Bind(syncer::ReportUnrecoverableError, channel_), |
| 553 http_post_provider_factory_getter, std::move(saved_nigori_state_)); | 519 http_post_provider_factory_getter, std::move(saved_nigori_state_)); |
| 554 } | 520 } |
| 555 | 521 |
| 556 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { | 522 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { |
| 557 if (encryption_pending()) | 523 if (encryption_pending()) |
| 558 return true; | 524 return true; |
| 559 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes(); | 525 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes(); |
| 560 const syncer::ModelTypeSet encrypted_types = GetEncryptedDataTypes(); | 526 const syncer::ModelTypeSet encrypted_types = GetEncryptedDataTypes(); |
| (...skipping 1969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2530 | 2496 |
| 2531 DCHECK(startup_controller_->IsSetupInProgress()); | 2497 DCHECK(startup_controller_->IsSetupInProgress()); |
| 2532 startup_controller_->SetSetupInProgress(false); | 2498 startup_controller_->SetSetupInProgress(false); |
| 2533 | 2499 |
| 2534 if (IsBackendInitialized()) | 2500 if (IsBackendInitialized()) |
| 2535 ReconfigureDatatypeManager(); | 2501 ReconfigureDatatypeManager(); |
| 2536 NotifyObservers(); | 2502 NotifyObservers(); |
| 2537 } | 2503 } |
| 2538 | 2504 |
| 2539 } // namespace browser_sync | 2505 } // namespace browser_sync |
| OLD | NEW |