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" |
23 #include "base/profiler/scoped_tracker.h" | 24 #include "base/profiler/scoped_tracker.h" |
24 #include "base/single_thread_task_runner.h" | 25 #include "base/single_thread_task_runner.h" |
25 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
26 #include "base/threading/thread_restrictions.h" | 27 #include "base/threading/thread_restrictions.h" |
27 #include "base/threading/thread_task_runner_handle.h" | 28 #include "base/threading/thread_task_runner_handle.h" |
28 #include "components/autofill/core/common/autofill_pref_names.h" | 29 #include "components/autofill/core/common/autofill_pref_names.h" |
29 #include "components/browser_sync/browser_sync_switches.h" | 30 #include "components/browser_sync/browser_sync_switches.h" |
30 #include "components/history/core/browser/typed_url_data_type_controller.h" | 31 #include "components/history/core/browser/typed_url_data_type_controller.h" |
31 #include "components/invalidation/impl/invalidation_prefs.h" | 32 #include "components/invalidation/impl/invalidation_prefs.h" |
32 #include "components/invalidation/public/invalidation_service.h" | 33 #include "components/invalidation/public/invalidation_service.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 using syncer::SyncCredentials; | 112 using syncer::SyncCredentials; |
112 using syncer::SyncProtocolError; | 113 using syncer::SyncProtocolError; |
113 using syncer::WeakHandle; | 114 using syncer::WeakHandle; |
114 | 115 |
115 namespace browser_sync { | 116 namespace browser_sync { |
116 | 117 |
117 typedef GoogleServiceAuthError AuthError; | 118 typedef GoogleServiceAuthError AuthError; |
118 | 119 |
119 const char kSyncUnrecoverableErrorHistogram[] = "Sync.UnrecoverableErrors"; | 120 const char kSyncUnrecoverableErrorHistogram[] = "Sync.UnrecoverableErrors"; |
120 | 121 |
| 122 const base::FilePath::StringType kLoopbackServerBackendFilename = |
| 123 FILE_PATH_LITERAL("profile.pb"); |
| 124 |
121 const net::BackoffEntry::Policy kRequestAccessTokenBackoffPolicy = { | 125 const net::BackoffEntry::Policy kRequestAccessTokenBackoffPolicy = { |
122 // Number of initial errors (in sequence) to ignore before applying | 126 // Number of initial errors (in sequence) to ignore before applying |
123 // exponential back-off rules. | 127 // exponential back-off rules. |
124 0, | 128 0, |
125 | 129 |
126 // Initial delay for exponential back-off in ms. | 130 // Initial delay for exponential back-off in ms. |
127 2000, | 131 2000, |
128 | 132 |
129 // Factor by which the waiting time will be multiplied. | 133 // Factor by which the waiting time will be multiplied. |
130 2, | 134 2, |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 if (!backend_) { | 499 if (!backend_) { |
496 NOTREACHED(); | 500 NOTREACHED(); |
497 return; | 501 return; |
498 } | 502 } |
499 | 503 |
500 SyncCredentials credentials = GetCredentials(); | 504 SyncCredentials credentials = GetCredentials(); |
501 | 505 |
502 if (delete_stale_data) | 506 if (delete_stale_data) |
503 ClearStaleErrors(); | 507 ClearStaleErrors(); |
504 | 508 |
| 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 |
505 SyncBackendHost::HttpPostProviderFactoryGetter | 539 SyncBackendHost::HttpPostProviderFactoryGetter |
506 http_post_provider_factory_getter = | 540 http_post_provider_factory_getter = |
507 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory, | 541 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory, |
508 base::Unretained(network_resources_.get()), | 542 base::Unretained(network_resources_.get()), |
509 url_request_context_, network_time_update_callback_); | 543 url_request_context_, network_time_update_callback_); |
510 | 544 |
511 backend_->Initialize( | 545 backend_->Initialize( |
512 this, std::move(sync_thread_), db_thread_, file_thread_, | 546 this, std::move(sync_thread_), db_thread_, file_thread_, |
513 GetJsEventHandler(), sync_service_url_, local_device_->GetSyncUserAgent(), | 547 GetJsEventHandler(), sync_service_url_, local_device_->GetSyncUserAgent(), |
514 credentials, delete_stale_data, | 548 credentials, delete_stale_data, enable_local_sync_backend, |
515 std::unique_ptr<syncer::SyncManagerFactory>( | 549 local_sync_backend_folder, std::unique_ptr<syncer::SyncManagerFactory>( |
516 new syncer::SyncManagerFactory()), | 550 new syncer::SyncManagerFactory()), |
517 MakeWeakHandle(sync_enabled_weak_factory_.GetWeakPtr()), | 551 MakeWeakHandle(sync_enabled_weak_factory_.GetWeakPtr()), |
518 base::Bind(syncer::ReportUnrecoverableError, channel_), | 552 base::Bind(syncer::ReportUnrecoverableError, channel_), |
519 http_post_provider_factory_getter, std::move(saved_nigori_state_)); | 553 http_post_provider_factory_getter, std::move(saved_nigori_state_)); |
520 } | 554 } |
521 | 555 |
522 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { | 556 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { |
523 if (encryption_pending()) | 557 if (encryption_pending()) |
524 return true; | 558 return true; |
525 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes(); | 559 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes(); |
526 const syncer::ModelTypeSet encrypted_types = GetEncryptedDataTypes(); | 560 const syncer::ModelTypeSet encrypted_types = GetEncryptedDataTypes(); |
(...skipping 1969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2496 | 2530 |
2497 DCHECK(startup_controller_->IsSetupInProgress()); | 2531 DCHECK(startup_controller_->IsSetupInProgress()); |
2498 startup_controller_->SetSetupInProgress(false); | 2532 startup_controller_->SetSetupInProgress(false); |
2499 | 2533 |
2500 if (IsBackendInitialized()) | 2534 if (IsBackendInitialized()) |
2501 ReconfigureDatatypeManager(); | 2535 ReconfigureDatatypeManager(); |
2502 NotifyObservers(); | 2536 NotifyObservers(); |
2503 } | 2537 } |
2504 | 2538 |
2505 } // namespace browser_sync | 2539 } // namespace browser_sync |
OLD | NEW |