Chromium Code Reviews| 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 "chrome/browser/sync/profile_sync_service.h" | 5 #include "chrome/browser/sync/profile_sync_service.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 #include "sync/internal_api/public/sync_encryption_handler.h" | 67 #include "sync/internal_api/public/sync_encryption_handler.h" |
| 68 #include "sync/internal_api/public/util/experiments.h" | 68 #include "sync/internal_api/public/util/experiments.h" |
| 69 #include "sync/internal_api/public/util/sync_string_conversions.h" | 69 #include "sync/internal_api/public/util/sync_string_conversions.h" |
| 70 #include "sync/js/js_arg_list.h" | 70 #include "sync/js/js_arg_list.h" |
| 71 #include "sync/js/js_event_details.h" | 71 #include "sync/js/js_event_details.h" |
| 72 #include "sync/notifier/invalidator_registrar.h" | 72 #include "sync/notifier/invalidator_registrar.h" |
| 73 #include "sync/notifier/invalidator_state.h" | 73 #include "sync/notifier/invalidator_state.h" |
| 74 #include "sync/util/cryptographer.h" | 74 #include "sync/util/cryptographer.h" |
| 75 #include "ui/base/l10n/l10n_util.h" | 75 #include "ui/base/l10n/l10n_util.h" |
| 76 | 76 |
| 77 #if defined(OS_ANDROID) | |
| 78 #include "sync/internal_api/public/read_transaction.h" | |
| 79 #endif | |
| 80 | |
| 77 using browser_sync::ChangeProcessor; | 81 using browser_sync::ChangeProcessor; |
| 78 using browser_sync::DataTypeController; | 82 using browser_sync::DataTypeController; |
| 79 using browser_sync::DataTypeManager; | 83 using browser_sync::DataTypeManager; |
| 80 using browser_sync::SyncBackendHost; | 84 using browser_sync::SyncBackendHost; |
| 81 using syncer::ModelType; | 85 using syncer::ModelType; |
| 82 using syncer::ModelTypeSet; | 86 using syncer::ModelTypeSet; |
| 83 using syncer::JsBackend; | 87 using syncer::JsBackend; |
| 84 using syncer::JsController; | 88 using syncer::JsController; |
| 85 using syncer::JsEventDetails; | 89 using syncer::JsEventDetails; |
| 86 using syncer::JsEventHandler; | 90 using syncer::JsEventHandler; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 // Sync is logged in if there is a non-empty authenticated username. | 182 // Sync is logged in if there is a non-empty authenticated username. |
| 179 return !signin_->GetAuthenticatedUsername().empty(); | 183 return !signin_->GetAuthenticatedUsername().empty(); |
| 180 } | 184 } |
| 181 | 185 |
| 182 bool ProfileSyncService::IsSyncTokenAvailable() { | 186 bool ProfileSyncService::IsSyncTokenAvailable() { |
| 183 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); | 187 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); |
| 184 if (!token_service) | 188 if (!token_service) |
| 185 return false; | 189 return false; |
| 186 return token_service->HasTokenForService(GaiaConstants::kSyncService); | 190 return token_service->HasTokenForService(GaiaConstants::kSyncService); |
| 187 } | 191 } |
| 192 #if defined(OS_ANDROID) | |
| 193 bool ProfileSyncService::IsPasswordSyncEnabledForAndroid() const { | |
|
Nicolas Zea
2013/01/18 00:05:11
This method isn't really about whether it is enabl
shashi
2013/01/18 02:06:31
Correct, thanks much better.
On 2013/01/18 00:05:1
| |
| 194 const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); | |
| 195 const syncer::ModelTypeSet preferred_types = | |
| 196 sync_prefs_.GetPreferredDataTypes(registered_types); | |
| 197 if (!preferred_types.Has(syncer::PASSWORDS)) | |
| 198 return false; | |
| 199 const syncer::PassphraseType passphraseType = GetPassphraseType(); | |
| 200 // On Android we do not want to prompt user to enter a passphrase except in | |
| 201 // case of custom passphrase, when we have no choice. | |
| 202 // We enable passwords always for CUSTOM_PASSPHRASE but for all other | |
| 203 // passphrase types we disable them till the cryptographer is ready. | |
| 204 syncer::ReadTransaction trans(FROM_HERE, GetUserShare()); | |
| 205 return (passphraseType == syncer::CUSTOM_PASSPHRASE | |
|
Nicolas Zea
2013/01/18 00:05:11
So, given that we already have logic to enable pas
shashi
2013/01/18 02:06:31
This is to deal with a corner case: User has a cus
Nicolas Zea
2013/01/18 22:55:13
Hmm, the IsEncryptedDatatypeEnabled method looks a
shashi
2013/01/18 23:20:52
IsEncryptedDatatypeEnabled uses PSS.GetPreferredDa
Nicolas Zea
2013/01/19 01:10:16
That sounds good.
Also, apparently the reason for
shashi
2013/01/23 21:25:24
Yes the function name is confusing :), GetEnabledP
| |
| 206 || IsCryptographerReady(&trans)); | |
| 207 } | |
| 208 #endif | |
| 188 | 209 |
| 189 void ProfileSyncService::Initialize() { | 210 void ProfileSyncService::Initialize() { |
| 190 DCHECK(!invalidator_registrar_.get()); | 211 DCHECK(!invalidator_registrar_.get()); |
| 191 invalidator_registrar_.reset(new syncer::InvalidatorRegistrar()); | 212 invalidator_registrar_.reset(new syncer::InvalidatorRegistrar()); |
| 192 | 213 |
| 193 InitSettings(); | 214 InitSettings(); |
| 194 | 215 |
| 195 // We clear this here (vs Shutdown) because we want to remember that an error | 216 // We clear this here (vs Shutdown) because we want to remember that an error |
| 196 // happened on shutdown so we can display details (message, location) about it | 217 // happened on shutdown so we can display details (message, location) about it |
| 197 // in about:sync. | 218 // in about:sync. |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 982 // consumed our cached passphrase. Clear it now. | 1003 // consumed our cached passphrase. Clear it now. |
| 983 if (!cached_passphrase_.empty()) | 1004 if (!cached_passphrase_.empty()) |
| 984 cached_passphrase_.clear(); | 1005 cached_passphrase_.clear(); |
| 985 | 1006 |
| 986 // Reset passphrase_required_reason_ since we know we no longer require the | 1007 // Reset passphrase_required_reason_ since we know we no longer require the |
| 987 // passphrase. We do this here rather than down in ResolvePassphraseRequired() | 1008 // passphrase. We do this here rather than down in ResolvePassphraseRequired() |
| 988 // because that can be called by OnPassphraseRequired() if no encrypted data | 1009 // because that can be called by OnPassphraseRequired() if no encrypted data |
| 989 // types are enabled, and we don't want to clobber the true passphrase error. | 1010 // types are enabled, and we don't want to clobber the true passphrase error. |
| 990 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED; | 1011 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED; |
| 991 | 1012 |
| 1013 #if defined(OS_ANDROID) | |
| 1014 // Re-enable passwords if we have disabled them. | |
| 1015 if (failed_datatypes_handler_.GetFailedTypes().Has(syncer::PASSWORDS) | |
| 1016 && IsPasswordSyncEnabledForAndroid()) { | |
|
Nicolas Zea
2013/01/18 00:05:11
move && operator to previous line
shashi
2013/01/18 02:06:31
Done.
| |
| 1017 syncer::ModelTypeSet preferredTypes = GetPreferredDataTypes(); | |
| 1018 preferredTypes.Put(syncer::PASSWORDS); | |
|
Nicolas Zea
2013/01/18 00:05:11
This shouldn't be necessary right? From what I rem
shashi
2013/01/18 02:06:31
PSS.GetPreferredDataTypes filters failed types, bu
Nicolas Zea
2013/01/18 22:55:13
I see. Yeah, I think clearing failed datatypes sho
| |
| 1019 OnUserChoseDatatypes(sync_prefs_.HasKeepEverythingSynced(), preferredTypes); | |
| 1020 return; | |
| 1021 } | |
| 1022 #endif | |
| 1023 | |
| 992 // Make sure the data types that depend on the passphrase are started at | 1024 // Make sure the data types that depend on the passphrase are started at |
| 993 // this time. | 1025 // this time. |
| 994 const syncer::ModelTypeSet types = GetPreferredDataTypes(); | 1026 const syncer::ModelTypeSet types = GetPreferredDataTypes(); |
| 995 | 1027 |
| 996 if (data_type_manager_.get()) { | 1028 if (data_type_manager_.get()) { |
| 997 // Unblock the data type manager if necessary. | 1029 // Unblock the data type manager if necessary. |
| 998 data_type_manager_->Configure(types, | 1030 data_type_manager_->Configure(types, |
| 999 syncer::CONFIGURE_REASON_RECONFIGURATION); | 1031 syncer::CONFIGURE_REASON_RECONFIGURATION); |
| 1000 } | 1032 } |
| 1001 | 1033 |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1444 | 1476 |
| 1445 // We create the migrator at the same time. | 1477 // We create the migrator at the same time. |
| 1446 migrator_.reset( | 1478 migrator_.reset( |
| 1447 new browser_sync::BackendMigrator( | 1479 new browser_sync::BackendMigrator( |
| 1448 profile_->GetDebugName(), GetUserShare(), | 1480 profile_->GetDebugName(), GetUserShare(), |
| 1449 this, data_type_manager_.get(), | 1481 this, data_type_manager_.get(), |
| 1450 base::Bind(&ProfileSyncService::StartSyncingWithServer, | 1482 base::Bind(&ProfileSyncService::StartSyncingWithServer, |
| 1451 base::Unretained(this)))); | 1483 base::Unretained(this)))); |
| 1452 } | 1484 } |
| 1453 | 1485 |
| 1486 #if defined(OS_ANDROID) | |
| 1487 if (GetPreferredDataTypes().Has(syncer::PASSWORDS) | |
| 1488 && !IsPasswordSyncEnabledForAndroid()) { | |
|
Nicolas Zea
2013/01/18 00:05:11
move && operator to previous line
shashi
2013/01/18 02:06:31
Done.
| |
| 1489 DisableBrokenDatatype(syncer::PASSWORDS, FROM_HERE, "Not supported."); | |
| 1490 } | |
| 1491 #endif | |
| 1492 | |
| 1454 const syncer::ModelTypeSet types = GetPreferredDataTypes(); | 1493 const syncer::ModelTypeSet types = GetPreferredDataTypes(); |
| 1455 if (IsPassphraseRequiredForDecryption()) { | 1494 if (IsPassphraseRequiredForDecryption()) { |
| 1456 // We need a passphrase still. We don't bother to attempt to configure | 1495 // We need a passphrase still. We don't bother to attempt to configure |
| 1457 // until we receive an OnPassphraseAccepted (which triggers a configure). | 1496 // until we receive an OnPassphraseAccepted (which triggers a configure). |
| 1458 DVLOG(1) << "ProfileSyncService::ConfigureDataTypeManager bailing out " | 1497 DVLOG(1) << "ProfileSyncService::ConfigureDataTypeManager bailing out " |
| 1459 << "because a passphrase required"; | 1498 << "because a passphrase required"; |
| 1460 NotifyObservers(); | 1499 NotifyObservers(); |
| 1461 return; | 1500 return; |
| 1462 } | 1501 } |
| 1463 syncer::ConfigureReason reason = syncer::CONFIGURE_REASON_UNKNOWN; | 1502 syncer::ConfigureReason reason = syncer::CONFIGURE_REASON_UNKNOWN; |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1913 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru. | 1952 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru. |
| 1914 ProfileSyncService* old_this = this; | 1953 ProfileSyncService* old_this = this; |
| 1915 this->~ProfileSyncService(); | 1954 this->~ProfileSyncService(); |
| 1916 new(old_this) ProfileSyncService( | 1955 new(old_this) ProfileSyncService( |
| 1917 new ProfileSyncComponentsFactoryImpl(profile, | 1956 new ProfileSyncComponentsFactoryImpl(profile, |
| 1918 CommandLine::ForCurrentProcess()), | 1957 CommandLine::ForCurrentProcess()), |
| 1919 profile, | 1958 profile, |
| 1920 signin, | 1959 signin, |
| 1921 behavior); | 1960 behavior); |
| 1922 } | 1961 } |
| OLD | NEW |