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/sync_driver/sync_prefs.h" | 5 #include "components/sync/driver/sync_prefs.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "components/pref_registry/pref_registry_syncable.h" | 12 #include "components/pref_registry/pref_registry_syncable.h" |
13 #include "components/prefs/pref_member.h" | 13 #include "components/prefs/pref_member.h" |
14 #include "components/prefs/pref_service.h" | 14 #include "components/prefs/pref_service.h" |
15 #include "components/sync_driver/pref_names.h" | 15 #include "components/sync/driver/pref_names.h" |
16 | 16 |
17 namespace sync_driver { | 17 namespace sync_driver { |
18 | 18 |
19 SyncPrefObserver::~SyncPrefObserver() {} | 19 SyncPrefObserver::~SyncPrefObserver() {} |
20 | 20 |
21 SyncPrefs::SyncPrefs(PrefService* pref_service) : pref_service_(pref_service) { | 21 SyncPrefs::SyncPrefs(PrefService* pref_service) : pref_service_(pref_service) { |
22 DCHECK(pref_service); | 22 DCHECK(pref_service); |
23 RegisterPrefGroups(); | 23 RegisterPrefGroups(); |
24 // Watch the preference that indicates sync is managed so we can take | 24 // Watch the preference that indicates sync is managed so we can take |
25 // appropriate action. | 25 // appropriate action. |
26 pref_sync_managed_.Init( | 26 pref_sync_managed_.Init( |
27 prefs::kSyncManaged, | 27 prefs::kSyncManaged, pref_service_, |
28 pref_service_, | |
29 base::Bind(&SyncPrefs::OnSyncManagedPrefChanged, base::Unretained(this))); | 28 base::Bind(&SyncPrefs::OnSyncManagedPrefChanged, base::Unretained(this))); |
30 } | 29 } |
31 | 30 |
32 SyncPrefs::SyncPrefs() : pref_service_(NULL) {} | 31 SyncPrefs::SyncPrefs() : pref_service_(NULL) {} |
33 | 32 |
34 SyncPrefs::~SyncPrefs() { DCHECK(CalledOnValidThread()); } | 33 SyncPrefs::~SyncPrefs() { |
| 34 DCHECK(CalledOnValidThread()); |
| 35 } |
35 | 36 |
36 // static | 37 // static |
37 void SyncPrefs::RegisterProfilePrefs( | 38 void SyncPrefs::RegisterProfilePrefs( |
38 user_prefs::PrefRegistrySyncable* registry) { | 39 user_prefs::PrefRegistrySyncable* registry) { |
39 registry->RegisterBooleanPref(prefs::kSyncFirstSetupComplete, false); | 40 registry->RegisterBooleanPref(prefs::kSyncFirstSetupComplete, false); |
40 registry->RegisterBooleanPref(prefs::kSyncSuppressStart, false); | 41 registry->RegisterBooleanPref(prefs::kSyncSuppressStart, false); |
41 registry->RegisterInt64Pref(prefs::kSyncLastSyncedTime, 0); | 42 registry->RegisterInt64Pref(prefs::kSyncLastSyncedTime, 0); |
42 registry->RegisterInt64Pref(prefs::kSyncLastPollTime, 0); | 43 registry->RegisterInt64Pref(prefs::kSyncLastPollTime, 0); |
43 registry->RegisterInt64Pref(prefs::kSyncFirstSyncTime, 0); | 44 registry->RegisterInt64Pref(prefs::kSyncFirstSyncTime, 0); |
44 | 45 |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 } | 334 } |
334 | 335 |
335 void SyncPrefs::SetSpareBootstrapToken(const std::string& token) { | 336 void SyncPrefs::SetSpareBootstrapToken(const std::string& token) { |
336 DCHECK(CalledOnValidThread()); | 337 DCHECK(CalledOnValidThread()); |
337 pref_service_->SetString(prefs::kSyncSpareBootstrapToken, token); | 338 pref_service_->SetString(prefs::kSyncSpareBootstrapToken, token); |
338 } | 339 } |
339 #endif | 340 #endif |
340 | 341 |
341 void SyncPrefs::OnSyncManagedPrefChanged() { | 342 void SyncPrefs::OnSyncManagedPrefChanged() { |
342 DCHECK(CalledOnValidThread()); | 343 DCHECK(CalledOnValidThread()); |
343 FOR_EACH_OBSERVER(SyncPrefObserver, | 344 FOR_EACH_OBSERVER(SyncPrefObserver, sync_pref_observers_, |
344 sync_pref_observers_, | |
345 OnSyncManagedPrefChange(*pref_sync_managed_)); | 345 OnSyncManagedPrefChange(*pref_sync_managed_)); |
346 } | 346 } |
347 | 347 |
348 void SyncPrefs::SetManagedForTest(bool is_managed) { | 348 void SyncPrefs::SetManagedForTest(bool is_managed) { |
349 DCHECK(CalledOnValidThread()); | 349 DCHECK(CalledOnValidThread()); |
350 pref_service_->SetBoolean(prefs::kSyncManaged, is_managed); | 350 pref_service_->SetBoolean(prefs::kSyncManaged, is_managed); |
351 } | 351 } |
352 | 352 |
353 void SyncPrefs::RegisterPrefGroups() { | 353 void SyncPrefs::RegisterPrefGroups() { |
354 pref_groups_[syncer::APPS].Put(syncer::APP_NOTIFICATIONS); | 354 pref_groups_[syncer::APPS].Put(syncer::APP_NOTIFICATIONS); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 return; | 428 return; |
429 | 429 |
430 pref_service_->SetBoolean(pref_name, is_preferred); | 430 pref_service_->SetBoolean(pref_name, is_preferred); |
431 } | 431 } |
432 | 432 |
433 syncer::ModelTypeSet SyncPrefs::ResolvePrefGroups( | 433 syncer::ModelTypeSet SyncPrefs::ResolvePrefGroups( |
434 syncer::ModelTypeSet registered_types, | 434 syncer::ModelTypeSet registered_types, |
435 syncer::ModelTypeSet types) const { | 435 syncer::ModelTypeSet types) const { |
436 syncer::ModelTypeSet types_with_groups = types; | 436 syncer::ModelTypeSet types_with_groups = types; |
437 for (PrefGroupsMap::const_iterator i = pref_groups_.begin(); | 437 for (PrefGroupsMap::const_iterator i = pref_groups_.begin(); |
438 i != pref_groups_.end(); | 438 i != pref_groups_.end(); ++i) { |
439 ++i) { | |
440 if (types.Has(i->first)) | 439 if (types.Has(i->first)) |
441 types_with_groups.PutAll(i->second); | 440 types_with_groups.PutAll(i->second); |
442 } | 441 } |
443 types_with_groups.RetainAll(registered_types); | 442 types_with_groups.RetainAll(registered_types); |
444 return types_with_groups; | 443 return types_with_groups; |
445 } | 444 } |
446 | 445 |
447 base::Time SyncPrefs::GetFirstSyncTime() const { | 446 base::Time SyncPrefs::GetFirstSyncTime() const { |
448 return base::Time::FromInternalValue( | 447 return base::Time::FromInternalValue( |
449 pref_service_->GetInt64(prefs::kSyncFirstSyncTime)); | 448 pref_service_->GetInt64(prefs::kSyncFirstSyncTime)); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 return std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState>(); | 546 return std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState>(); |
548 | 547 |
549 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState> result( | 548 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState> result( |
550 new syncer::SyncEncryptionHandler::NigoriState()); | 549 new syncer::SyncEncryptionHandler::NigoriState()); |
551 if (!result->nigori_specifics.ParseFromString(decoded)) | 550 if (!result->nigori_specifics.ParseFromString(decoded)) |
552 return std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState>(); | 551 return std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState>(); |
553 return result; | 552 return result; |
554 } | 553 } |
555 | 554 |
556 } // namespace sync_driver | 555 } // namespace sync_driver |
OLD | NEW |