Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: components/browser_sync/profile_sync_service.cc

Issue 2473613003: [Sync] Adds a new switch for enabling the new local server backend. (Closed)
Patch Set: Ifdef protect the variable. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 145
145 // Don't use initial delay unless the last request was an error. 146 // Don't use initial delay unless the last request was an error.
146 false, 147 false,
147 }; 148 };
148 149
149 static const base::FilePath::CharType kSyncDataFolderName[] = 150 static const base::FilePath::CharType kSyncDataFolderName[] =
150 FILE_PATH_LITERAL("Sync Data"); 151 FILE_PATH_LITERAL("Sync Data");
151 static const base::FilePath::CharType kLevelDBFolderName[] = 152 static const base::FilePath::CharType kLevelDBFolderName[] =
152 FILE_PATH_LITERAL("LevelDB"); 153 FILE_PATH_LITERAL("LevelDB");
153 154
155 #if defined(OS_WIN)
156 static const base::FilePath::CharType kLoopbackServerBackendFilename[] =
157 FILE_PATH_LITERAL("profile.pb");
158 #endif
159
154 namespace { 160 namespace {
155 161
156 // Perform the actual sync data folder deletion. 162 // Perform the actual sync data folder deletion.
157 // This should only be called on the sync thread. 163 // This should only be called on the sync thread.
158 void DeleteSyncDataFolder(const base::FilePath& directory_path) { 164 void DeleteSyncDataFolder(const base::FilePath& directory_path) {
159 if (base::DirectoryExists(directory_path)) { 165 if (base::DirectoryExists(directory_path)) {
160 if (!base::DeleteFile(directory_path, true)) 166 if (!base::DeleteFile(directory_path, true))
161 LOG(DFATAL) << "Could not delete the Sync Data folder."; 167 LOG(DFATAL) << "Could not delete the Sync Data folder.";
162 } 168 }
163 } 169 }
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 if (!backend_) { 501 if (!backend_) {
496 NOTREACHED(); 502 NOTREACHED();
497 return; 503 return;
498 } 504 }
499 505
500 SyncCredentials credentials = GetCredentials(); 506 SyncCredentials credentials = GetCredentials();
501 507
502 if (delete_stale_data) 508 if (delete_stale_data)
503 ClearStaleErrors(); 509 ClearStaleErrors();
504 510
511 bool enable_local_sync_backend = false;
512 base::FilePath local_sync_backend_folder;
513 #if defined(OS_WIN)
514 enable_local_sync_backend = base::CommandLine::ForCurrentProcess()->HasSwitch(
515 switches::kEnableLocalSyncBackend);
516 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
517 switches::kLocalSyncBackendDir)) {
518 local_sync_backend_folder =
519 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
520 switches::kLocalSyncBackendDir);
521 } else {
522 // TODO(pastarmovj): Add DIR_ROAMING_USER_DATA to PathService to simplify
523 // this code and move the logic in its right place. See crbug/657810.
524 CHECK(
525 base::PathService::Get(base::DIR_APP_DATA, &local_sync_backend_folder));
526 local_sync_backend_folder =
527 local_sync_backend_folder.Append(FILE_PATH_LITERAL("Chrome/User Data"));
528 }
529 // This code as it is now will assume the same profile order is present on all
530 // machines, which is not a given. It is to be defined if only the Default
531 // profile should get this treatment or all profile as is the case now. The
532 // solution for now will be to assume profiles are created in the same order
533 // on all machines and in the future decide if only the Default one should be
534 // considered roamed.
535 local_sync_backend_folder =
536 local_sync_backend_folder.Append(base_directory_.BaseName());
537 local_sync_backend_folder =
538 local_sync_backend_folder.Append(kLoopbackServerBackendFilename);
539 #endif // defined(OS_WIN)
540
505 SyncBackendHost::HttpPostProviderFactoryGetter 541 SyncBackendHost::HttpPostProviderFactoryGetter
506 http_post_provider_factory_getter = 542 http_post_provider_factory_getter =
507 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory, 543 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory,
508 base::Unretained(network_resources_.get()), 544 base::Unretained(network_resources_.get()),
509 url_request_context_, network_time_update_callback_); 545 url_request_context_, network_time_update_callback_);
510 546
511 backend_->Initialize( 547 backend_->Initialize(
512 this, std::move(sync_thread_), db_thread_, file_thread_, 548 this, std::move(sync_thread_), db_thread_, file_thread_,
513 GetJsEventHandler(), sync_service_url_, local_device_->GetSyncUserAgent(), 549 GetJsEventHandler(), sync_service_url_, local_device_->GetSyncUserAgent(),
514 credentials, delete_stale_data, 550 credentials, delete_stale_data, enable_local_sync_backend,
515 std::unique_ptr<syncer::SyncManagerFactory>( 551 local_sync_backend_folder, std::unique_ptr<syncer::SyncManagerFactory>(
516 new syncer::SyncManagerFactory()), 552 new syncer::SyncManagerFactory()),
517 MakeWeakHandle(sync_enabled_weak_factory_.GetWeakPtr()), 553 MakeWeakHandle(sync_enabled_weak_factory_.GetWeakPtr()),
518 base::Bind(syncer::ReportUnrecoverableError, channel_), 554 base::Bind(syncer::ReportUnrecoverableError, channel_),
519 http_post_provider_factory_getter, std::move(saved_nigori_state_)); 555 http_post_provider_factory_getter, std::move(saved_nigori_state_));
520 } 556 }
521 557
522 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { 558 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const {
523 if (encryption_pending()) 559 if (encryption_pending())
524 return true; 560 return true;
525 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes(); 561 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes();
526 const syncer::ModelTypeSet encrypted_types = GetEncryptedDataTypes(); 562 const syncer::ModelTypeSet encrypted_types = GetEncryptedDataTypes();
(...skipping 1969 matching lines...) Expand 10 before | Expand all | Expand 10 after
2496 2532
2497 DCHECK(startup_controller_->IsSetupInProgress()); 2533 DCHECK(startup_controller_->IsSetupInProgress());
2498 startup_controller_->SetSetupInProgress(false); 2534 startup_controller_->SetSetupInProgress(false);
2499 2535
2500 if (IsBackendInitialized()) 2536 if (IsBackendInitialized())
2501 ReconfigureDatatypeManager(); 2537 ReconfigureDatatypeManager();
2502 NotifyObservers(); 2538 NotifyObservers();
2503 } 2539 }
2504 2540
2505 } // namespace browser_sync 2541 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/browser_sync/browser_sync_switches.cc ('k') | components/browser_sync/profile_sync_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698