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

Side by Side Diff: chrome/browser/sync/glue/sync_backend_host.cc

Issue 6375007: [Sync] Refactored ProfileSyncService and remove its backend() function (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add comment Created 9 years, 11 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 using browser_sync::DataTypeController; 44 using browser_sync::DataTypeController;
45 typedef TokenService::TokenAvailableDetails TokenAvailableDetails; 45 typedef TokenService::TokenAvailableDetails TokenAvailableDetails;
46 46
47 typedef GoogleServiceAuthError AuthError; 47 typedef GoogleServiceAuthError AuthError;
48 48
49 namespace browser_sync { 49 namespace browser_sync {
50 50
51 using sessions::SyncSessionSnapshot; 51 using sessions::SyncSessionSnapshot;
52 using sync_api::SyncCredentials; 52 using sync_api::SyncCredentials;
53 53
54 SyncBackendHost::SyncBackendHost(SyncFrontend* frontend, Profile* profile) 54 SyncBackendHost::SyncBackendHost(Profile* profile)
55 : core_(new Core(ALLOW_THIS_IN_INITIALIZER_LIST(this))), 55 : core_(new Core(ALLOW_THIS_IN_INITIALIZER_LIST(this))),
56 core_thread_("Chrome_SyncCoreThread"), 56 core_thread_("Chrome_SyncCoreThread"),
57 frontend_loop_(MessageLoop::current()), 57 frontend_loop_(MessageLoop::current()),
58 profile_(profile), 58 profile_(profile),
59 frontend_(frontend), 59 frontend_(NULL),
60 sync_data_folder_path_( 60 sync_data_folder_path_(
61 profile_->GetPath().Append(kSyncDataFolderName)), 61 profile_->GetPath().Append(kSyncDataFolderName)),
62 last_auth_error_(AuthError::None()), 62 last_auth_error_(AuthError::None()),
63 syncapi_initialized_(false) { 63 syncapi_initialized_(false) {
64 } 64 }
65 65
66 SyncBackendHost::SyncBackendHost() 66 SyncBackendHost::SyncBackendHost()
67 : core_thread_("Chrome_SyncCoreThread"), 67 : core_thread_("Chrome_SyncCoreThread"),
68 frontend_loop_(MessageLoop::current()), 68 frontend_loop_(MessageLoop::current()),
69 profile_(NULL), 69 profile_(NULL),
70 frontend_(NULL), 70 frontend_(NULL),
71 last_auth_error_(AuthError::None()), 71 last_auth_error_(AuthError::None()),
72 syncapi_initialized_(false) { 72 syncapi_initialized_(false) {
73 } 73 }
74 74
75 SyncBackendHost::~SyncBackendHost() { 75 SyncBackendHost::~SyncBackendHost() {
76 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; 76 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor.";
77 DCHECK(registrar_.workers.empty()); 77 DCHECK(registrar_.workers.empty());
78 } 78 }
79 79
80 void SyncBackendHost::Initialize( 80 void SyncBackendHost::Initialize(
81 SyncFrontend* frontend,
81 const GURL& sync_service_url, 82 const GURL& sync_service_url,
82 const syncable::ModelTypeSet& types, 83 const syncable::ModelTypeSet& types,
83 URLRequestContextGetter* baseline_context_getter, 84 URLRequestContextGetter* baseline_context_getter,
84 const SyncCredentials& credentials, 85 const SyncCredentials& credentials,
85 bool delete_sync_data_folder, 86 bool delete_sync_data_folder,
86 const notifier::NotifierOptions& notifier_options) { 87 const notifier::NotifierOptions& notifier_options) {
87 if (!core_thread_.Start()) 88 if (!core_thread_.Start())
88 return; 89 return;
89 90
91 frontend_ = frontend;
92 DCHECK(frontend);
93
90 // Create a worker for the UI thread and route bookmark changes to it. 94 // Create a worker for the UI thread and route bookmark changes to it.
91 // TODO(tim): Pull this into a method to reuse. For now we don't even 95 // TODO(tim): Pull this into a method to reuse. For now we don't even
92 // need to lock because we init before the syncapi exists and we tear down 96 // need to lock because we init before the syncapi exists and we tear down
93 // after the syncapi is destroyed. Make sure to NULL-check workers_ indices 97 // after the syncapi is destroyed. Make sure to NULL-check workers_ indices
94 // when a new type is synced as the worker may already exist and you just 98 // when a new type is synced as the worker may already exist and you just
95 // need to update routing_info_. 99 // need to update routing_info_.
96 registrar_.workers[GROUP_DB] = new DatabaseModelWorker(); 100 registrar_.workers[GROUP_DB] = new DatabaseModelWorker();
97 registrar_.workers[GROUP_UI] = new UIModelWorker(frontend_loop_); 101 registrar_.workers[GROUP_UI] = new UIModelWorker(frontend_loop_);
98 registrar_.workers[GROUP_PASSIVE] = new ModelSafeWorker(); 102 registrar_.workers[GROUP_PASSIVE] = new ModelSafeWorker();
99 103
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } 169 }
166 170
167 bool SyncBackendHost::IsUsingExplicitPassphrase() { 171 bool SyncBackendHost::IsUsingExplicitPassphrase() {
168 return IsNigoriEnabled() && syncapi_initialized_ && 172 return IsNigoriEnabled() && syncapi_initialized_ &&
169 core_->syncapi()->InitialSyncEndedForAllEnabledTypes() && 173 core_->syncapi()->InitialSyncEndedForAllEnabledTypes() &&
170 core_->syncapi()->IsUsingExplicitPassphrase(); 174 core_->syncapi()->IsUsingExplicitPassphrase();
171 } 175 }
172 176
173 bool SyncBackendHost::IsCryptographerReady() const { 177 bool SyncBackendHost::IsCryptographerReady() const {
174 return syncapi_initialized_ && 178 return syncapi_initialized_ &&
175 GetUserShareHandle()->dir_manager->cryptographer()->is_ready(); 179 GetUserShare()->dir_manager->cryptographer()->is_ready();
176 } 180 }
177 181
178 sync_api::HttpPostProviderFactory* SyncBackendHost::MakeHttpBridgeFactory( 182 sync_api::HttpPostProviderFactory* SyncBackendHost::MakeHttpBridgeFactory(
179 URLRequestContextGetter* getter) { 183 URLRequestContextGetter* getter) {
180 return new HttpBridgeFactory(getter); 184 return new HttpBridgeFactory(getter);
181 } 185 }
182 186
183 void SyncBackendHost::InitCore(const Core::DoInitializeOptions& options) { 187 void SyncBackendHost::InitCore(const Core::DoInitializeOptions& options) {
184 core_thread_.message_loop()->PostTask(FROM_HERE, 188 core_thread_.message_loop()->PostTask(FROM_HERE,
185 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoInitialize, 189 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoInitialize,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 } 281 }
278 282
279 void SyncBackendHost::SetAutofillMigrationDebugInfo( 283 void SyncBackendHost::SetAutofillMigrationDebugInfo(
280 syncable::AutofillMigrationDebugInfo::PropertyToSet property_to_set, 284 syncable::AutofillMigrationDebugInfo::PropertyToSet property_to_set,
281 const syncable::AutofillMigrationDebugInfo& info) { 285 const syncable::AutofillMigrationDebugInfo& info) {
282 return core_->syncapi()->SetAutofillMigrationDebugInfo(property_to_set, info); 286 return core_->syncapi()->SetAutofillMigrationDebugInfo(property_to_set, info);
283 } 287 }
284 288
285 void SyncBackendHost::ConfigureAutofillMigration() { 289 void SyncBackendHost::ConfigureAutofillMigration() {
286 if (GetAutofillMigrationState() == syncable::NOT_DETERMINED) { 290 if (GetAutofillMigrationState() == syncable::NOT_DETERMINED) {
287 sync_api::ReadTransaction trans(GetUserShareHandle()); 291 sync_api::ReadTransaction trans(GetUserShare());
288 sync_api::ReadNode autofil_root_node(&trans); 292 sync_api::ReadNode autofil_root_node(&trans);
289 293
290 // Check for the presence of autofill node. 294 // Check for the presence of autofill node.
291 if (!autofil_root_node.InitByTagLookup(browser_sync::kAutofillTag)) { 295 if (!autofil_root_node.InitByTagLookup(browser_sync::kAutofillTag)) {
292 SetAutofillMigrationState(syncable::INSUFFICIENT_INFO_TO_DETERMINE); 296 SetAutofillMigrationState(syncable::INSUFFICIENT_INFO_TO_DETERMINE);
293 return; 297 return;
294 } 298 }
295 299
296 // Check for children under autofill node. 300 // Check for children under autofill node.
297 if (autofil_root_node.GetFirstChildId() == static_cast<int64>(0)) { 301 if (autofil_root_node.GetFirstChildId() == static_cast<int64>(0)) {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 if (!host_) 484 if (!host_)
481 return; 485 return;
482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 486 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
483 TokenAvailableDetails details(GaiaConstants::kSyncService, token); 487 TokenAvailableDetails details(GaiaConstants::kSyncService, token);
484 NotificationService::current()->Notify( 488 NotificationService::current()->Notify(
485 NotificationType::TOKEN_UPDATED, 489 NotificationType::TOKEN_UPDATED,
486 NotificationService::AllSources(), 490 NotificationService::AllSources(),
487 Details<const TokenAvailableDetails>(&details)); 491 Details<const TokenAvailableDetails>(&details));
488 } 492 }
489 493
490 SyncBackendHost::UserShareHandle SyncBackendHost::GetUserShareHandle() const { 494 sync_api::UserShare* SyncBackendHost::GetUserShare() const {
491 DCHECK(syncapi_initialized_); 495 DCHECK(syncapi_initialized_);
492 return core_->syncapi()->GetUserShare(); 496 return core_->syncapi()->GetUserShare();
493 } 497 }
494 498
495 SyncBackendHost::Status SyncBackendHost::GetDetailedStatus() { 499 SyncBackendHost::Status SyncBackendHost::GetDetailedStatus() {
496 DCHECK(syncapi_initialized_); 500 DCHECK(syncapi_initialized_);
497 return core_->syncapi()->GetDetailedStatus(); 501 return core_->syncapi()->GetDetailedStatus();
498 } 502 }
499 503
500 SyncBackendHost::StatusSummary SyncBackendHost::GetStatusSummary() { 504 SyncBackendHost::StatusSummary SyncBackendHost::GetStatusSummary() {
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 } 897 }
894 898
895 void SyncBackendHost::Core::DeleteSyncDataFolder() { 899 void SyncBackendHost::Core::DeleteSyncDataFolder() {
896 if (file_util::DirectoryExists(host_->sync_data_folder_path())) { 900 if (file_util::DirectoryExists(host_->sync_data_folder_path())) {
897 if (!file_util::Delete(host_->sync_data_folder_path(), true)) 901 if (!file_util::Delete(host_->sync_data_folder_path(), true))
898 LOG(DFATAL) << "Could not delete the Sync Data folder."; 902 LOG(DFATAL) << "Could not delete the Sync Data folder.";
899 } 903 }
900 } 904 }
901 905
902 } // namespace browser_sync 906 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_host.h ('k') | chrome/browser/sync/glue/theme_model_associator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698