OLD | NEW |
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/command_line.h" | 10 #include "base/command_line.h" |
10 #include "base/file_util.h" | 11 #include "base/file_util.h" |
11 #include "base/task.h" | 12 #include "base/task.h" |
12 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
14 #include "chrome/browser/browser_thread.h" | 15 #include "chrome/browser/browser_thread.h" |
15 #include "chrome/browser/net/gaia/token_service.h" | 16 #include "chrome/browser/net/gaia/token_service.h" |
16 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/sync/engine/syncapi.h" | 19 #include "chrome/browser/sync/engine/syncapi.h" |
(...skipping 24 matching lines...) Expand all Loading... |
43 using browser_sync::DataTypeController; | 44 using browser_sync::DataTypeController; |
44 typedef TokenService::TokenAvailableDetails TokenAvailableDetails; | 45 typedef TokenService::TokenAvailableDetails TokenAvailableDetails; |
45 | 46 |
46 typedef GoogleServiceAuthError AuthError; | 47 typedef GoogleServiceAuthError AuthError; |
47 | 48 |
48 namespace browser_sync { | 49 namespace browser_sync { |
49 | 50 |
50 using sessions::SyncSessionSnapshot; | 51 using sessions::SyncSessionSnapshot; |
51 using sync_api::SyncCredentials; | 52 using sync_api::SyncCredentials; |
52 | 53 |
53 SyncBackendHost::SyncBackendHost( | 54 SyncBackendHost::SyncBackendHost(SyncFrontend* frontend, Profile* profile) |
54 SyncFrontend* frontend, | 55 : core_(new Core(ALLOW_THIS_IN_INITIALIZER_LIST(this))), |
55 Profile* profile, | 56 core_thread_("Chrome_SyncCoreThread"), |
56 const FilePath& profile_path, | |
57 const DataTypeController::TypeMap& data_type_controllers) | |
58 : core_thread_("Chrome_SyncCoreThread"), | |
59 frontend_loop_(MessageLoop::current()), | 57 frontend_loop_(MessageLoop::current()), |
60 profile_(profile), | 58 profile_(profile), |
61 frontend_(frontend), | 59 frontend_(frontend), |
62 sync_data_folder_path_(profile_path.Append(kSyncDataFolderName)), | 60 sync_data_folder_path_( |
63 data_type_controllers_(data_type_controllers), | 61 profile_->GetPath().Append(kSyncDataFolderName)), |
64 last_auth_error_(AuthError::None()), | 62 last_auth_error_(AuthError::None()), |
65 syncapi_initialized_(false) { | 63 syncapi_initialized_(false) { |
66 | |
67 core_ = new Core(this); | |
68 } | 64 } |
69 | 65 |
70 SyncBackendHost::SyncBackendHost() | 66 SyncBackendHost::SyncBackendHost() |
71 : core_thread_("Chrome_SyncCoreThread"), | 67 : core_thread_("Chrome_SyncCoreThread"), |
72 frontend_loop_(MessageLoop::current()), | 68 frontend_loop_(MessageLoop::current()), |
73 profile_(NULL), | 69 profile_(NULL), |
74 frontend_(NULL), | 70 frontend_(NULL), |
75 last_auth_error_(AuthError::None()), | 71 last_auth_error_(AuthError::None()), |
76 syncapi_initialized_(false) { | 72 syncapi_initialized_(false) { |
77 } | 73 } |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 // If our state is not determined then we should not have the autofill | 311 // If our state is not determined then we should not have the autofill |
316 // profile node. | 312 // profile node. |
317 DCHECK(false); | 313 DCHECK(false); |
318 | 314 |
319 // just set it as not migrated. | 315 // just set it as not migrated. |
320 SetAutofillMigrationState(syncable::NOT_MIGRATED); | 316 SetAutofillMigrationState(syncable::NOT_MIGRATED); |
321 return; | 317 return; |
322 } | 318 } |
323 } | 319 } |
324 | 320 |
325 void SyncBackendHost::ConfigureDataTypes(const syncable::ModelTypeSet& types, | 321 void SyncBackendHost::ConfigureDataTypes( |
326 CancelableTask* ready_task) { | 322 const DataTypeController::TypeMap& data_type_controllers, |
| 323 const syncable::ModelTypeSet& types, |
| 324 CancelableTask* ready_task) { |
327 // Only one configure is allowed at a time. | 325 // Only one configure is allowed at a time. |
328 DCHECK(!configure_ready_task_.get()); | 326 DCHECK(!configure_ready_task_.get()); |
329 DCHECK(syncapi_initialized_); | 327 DCHECK(syncapi_initialized_); |
330 | 328 |
331 if (types.count(syncable::AUTOFILL_PROFILE) != 0) { | 329 if (types.count(syncable::AUTOFILL_PROFILE) != 0) { |
332 ConfigureAutofillMigration(); | 330 ConfigureAutofillMigration(); |
333 } | 331 } |
334 | 332 |
335 bool deleted_type = false; | 333 bool deleted_type = false; |
336 | 334 |
337 { | 335 { |
338 AutoLock lock(registrar_lock_); | 336 AutoLock lock(registrar_lock_); |
339 for (DataTypeController::TypeMap::const_iterator it = | 337 for (DataTypeController::TypeMap::const_iterator it = |
340 data_type_controllers_.begin(); | 338 data_type_controllers.begin(); |
341 it != data_type_controllers_.end(); ++it) { | 339 it != data_type_controllers.end(); ++it) { |
342 syncable::ModelType type = (*it).first; | 340 syncable::ModelType type = (*it).first; |
343 | 341 |
344 // If a type is not specified, remove it from the routing_info. | 342 // If a type is not specified, remove it from the routing_info. |
345 if (types.count(type) == 0) { | 343 if (types.count(type) == 0) { |
346 registrar_.routing_info.erase(type); | 344 registrar_.routing_info.erase(type); |
347 deleted_type = true; | 345 deleted_type = true; |
348 } else { | 346 } else { |
349 // Add a newly specified data type as GROUP_PASSIVE into the | 347 // Add a newly specified data type as GROUP_PASSIVE into the |
350 // routing_info, if it does not already exist. | 348 // routing_info, if it does not already exist. |
351 if (registrar_.routing_info.count(type) == 0) { | 349 if (registrar_.routing_info.count(type) == 0) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 NotificationService::NoDetails()); | 450 NotificationService::NoDetails()); |
453 } | 451 } |
454 | 452 |
455 void SyncBackendHost::Core::NotifyResumed() { | 453 void SyncBackendHost::Core::NotifyResumed() { |
456 NotificationService::current()->Notify(NotificationType::SYNC_RESUMED, | 454 NotificationService::current()->Notify(NotificationType::SYNC_RESUMED, |
457 NotificationService::AllSources(), | 455 NotificationService::AllSources(), |
458 NotificationService::NoDetails()); | 456 NotificationService::NoDetails()); |
459 } | 457 } |
460 | 458 |
461 void SyncBackendHost::Core::NotifyPassphraseRequired(bool for_decryption) { | 459 void SyncBackendHost::Core::NotifyPassphraseRequired(bool for_decryption) { |
462 NotificationService::current()->Notify( | 460 if (!host_ || !host_->frontend_) |
463 NotificationType::SYNC_PASSPHRASE_REQUIRED, | 461 return; |
464 Source<SyncBackendHost>(host_), | 462 |
465 Details<bool>(&for_decryption)); | 463 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); |
| 464 |
| 465 host_->frontend_->OnPassphraseRequired(for_decryption); |
466 } | 466 } |
467 | 467 |
468 void SyncBackendHost::Core::NotifyPassphraseAccepted( | 468 void SyncBackendHost::Core::NotifyPassphraseAccepted( |
469 const std::string& bootstrap_token) { | 469 const std::string& bootstrap_token) { |
470 if (!host_) | 470 if (!host_ || !host_->frontend_) |
471 return; | 471 return; |
| 472 |
| 473 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); |
| 474 |
472 host_->PersistEncryptionBootstrapToken(bootstrap_token); | 475 host_->PersistEncryptionBootstrapToken(bootstrap_token); |
473 NotificationService::current()->Notify( | 476 host_->frontend_->OnPassphraseAccepted(); |
474 NotificationType::SYNC_PASSPHRASE_ACCEPTED, | |
475 Source<SyncBackendHost>(host_), | |
476 NotificationService::NoDetails()); | |
477 } | 477 } |
478 | 478 |
479 void SyncBackendHost::Core::NotifyUpdatedToken(const std::string& token) { | 479 void SyncBackendHost::Core::NotifyUpdatedToken(const std::string& token) { |
480 if (!host_) | 480 if (!host_) |
481 return; | 481 return; |
482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
483 TokenAvailableDetails details(GaiaConstants::kSyncService, token); | 483 TokenAvailableDetails details(GaiaConstants::kSyncService, token); |
484 NotificationService::current()->Notify( | 484 NotificationService::current()->Notify( |
485 NotificationType::TOKEN_UPDATED, | 485 NotificationType::TOKEN_UPDATED, |
486 NotificationService::AllSources(), | 486 NotificationService::AllSources(), |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 } | 893 } |
894 | 894 |
895 void SyncBackendHost::Core::DeleteSyncDataFolder() { | 895 void SyncBackendHost::Core::DeleteSyncDataFolder() { |
896 if (file_util::DirectoryExists(host_->sync_data_folder_path())) { | 896 if (file_util::DirectoryExists(host_->sync_data_folder_path())) { |
897 if (!file_util::Delete(host_->sync_data_folder_path(), true)) | 897 if (!file_util::Delete(host_->sync_data_folder_path(), true)) |
898 LOG(DFATAL) << "Could not delete the Sync Data folder."; | 898 LOG(DFATAL) << "Could not delete the Sync Data folder."; |
899 } | 899 } |
900 } | 900 } |
901 | 901 |
902 } // namespace browser_sync | 902 } // namespace browser_sync |
OLD | NEW |