| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/glue/session_model_associator.h" | 5 #include "chrome/browser/sync/glue/session_model_associator.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 SessionModelAssociator::SessionModelAssociator(ProfileSyncService* sync_service, | 89 SessionModelAssociator::SessionModelAssociator(ProfileSyncService* sync_service, |
| 90 DataTypeErrorHandler* error_handler) | 90 DataTypeErrorHandler* error_handler) |
| 91 : tab_pool_(sync_service), | 91 : tab_pool_(sync_service), |
| 92 local_session_syncid_(syncer::kInvalidId), | 92 local_session_syncid_(syncer::kInvalidId), |
| 93 sync_service_(sync_service), | 93 sync_service_(sync_service), |
| 94 stale_session_threshold_days_(kDefaultStaleSessionThresholdDays), | 94 stale_session_threshold_days_(kDefaultStaleSessionThresholdDays), |
| 95 setup_for_test_(false), | 95 setup_for_test_(false), |
| 96 waiting_for_change_(false), | 96 waiting_for_change_(false), |
| 97 ALLOW_THIS_IN_INITIALIZER_LIST(test_weak_factory_(this)), | 97 ALLOW_THIS_IN_INITIALIZER_LIST(test_weak_factory_(this)), |
| 98 profile_(sync_service->profile()), | 98 profile_(sync_service->profile()), |
| 99 pref_service_(PrefServiceSyncable::FromProfile(profile_)), | |
| 100 error_handler_(error_handler) { | 99 error_handler_(error_handler) { |
| 101 DCHECK(CalledOnValidThread()); | 100 DCHECK(CalledOnValidThread()); |
| 102 DCHECK(sync_service_); | 101 DCHECK(sync_service_); |
| 103 DCHECK(profile_); | 102 DCHECK(profile_); |
| 104 if (pref_service_->FindPreference(kSyncSessionsGUID) == NULL) { | |
| 105 static_cast<PrefRegistrySyncable*>( | |
| 106 pref_service_->DeprecatedGetPrefRegistry())->RegisterStringPref( | |
| 107 kSyncSessionsGUID, | |
| 108 std::string(), | |
| 109 PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 110 } | |
| 111 } | 103 } |
| 112 | 104 |
| 113 SessionModelAssociator::SessionModelAssociator(ProfileSyncService* sync_service, | 105 SessionModelAssociator::SessionModelAssociator(ProfileSyncService* sync_service, |
| 114 bool setup_for_test) | 106 bool setup_for_test) |
| 115 : tab_pool_(sync_service), | 107 : tab_pool_(sync_service), |
| 116 local_session_syncid_(syncer::kInvalidId), | 108 local_session_syncid_(syncer::kInvalidId), |
| 117 sync_service_(sync_service), | 109 sync_service_(sync_service), |
| 118 stale_session_threshold_days_(kDefaultStaleSessionThresholdDays), | 110 stale_session_threshold_days_(kDefaultStaleSessionThresholdDays), |
| 119 setup_for_test_(setup_for_test), | 111 setup_for_test_(setup_for_test), |
| 120 waiting_for_change_(false), | 112 waiting_for_change_(false), |
| 121 ALLOW_THIS_IN_INITIALIZER_LIST(test_weak_factory_(this)), | 113 ALLOW_THIS_IN_INITIALIZER_LIST(test_weak_factory_(this)), |
| 122 profile_(sync_service->profile()), | 114 profile_(sync_service->profile()), |
| 123 pref_service_(NULL), | |
| 124 error_handler_(NULL) { | 115 error_handler_(NULL) { |
| 125 DCHECK(CalledOnValidThread()); | 116 DCHECK(CalledOnValidThread()); |
| 126 DCHECK(sync_service_); | 117 DCHECK(sync_service_); |
| 127 DCHECK(profile_); | 118 DCHECK(profile_); |
| 128 DCHECK(setup_for_test); | 119 DCHECK(setup_for_test); |
| 129 } | 120 } |
| 130 | 121 |
| 131 SessionModelAssociator::~SessionModelAssociator() { | 122 SessionModelAssociator::~SessionModelAssociator() { |
| 132 DCHECK(CalledOnValidThread()); | 123 DCHECK(CalledOnValidThread()); |
| 133 } | 124 } |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 content::Source<Profile>(sync_service_->profile()), | 708 content::Source<Profile>(sync_service_->profile()), |
| 718 content::NotificationService::NoDetails()); | 709 content::NotificationService::NoDetails()); |
| 719 return syncer::SyncError(); | 710 return syncer::SyncError(); |
| 720 } | 711 } |
| 721 | 712 |
| 722 void SessionModelAssociator::InitializeCurrentMachineTag( | 713 void SessionModelAssociator::InitializeCurrentMachineTag( |
| 723 syncer::WriteTransaction* trans) { | 714 syncer::WriteTransaction* trans) { |
| 724 DCHECK(CalledOnValidThread()); | 715 DCHECK(CalledOnValidThread()); |
| 725 DCHECK(current_machine_tag_.empty()); | 716 DCHECK(current_machine_tag_.empty()); |
| 726 std::string persisted_guid; | 717 std::string persisted_guid; |
| 727 if (pref_service_) | 718 browser_sync::SyncPrefs prefs(profile_->GetPrefs()); |
| 728 persisted_guid = pref_service_->GetString(kSyncSessionsGUID); | 719 persisted_guid = prefs.GetSyncSessionsGUID(); |
| 729 if (!persisted_guid.empty()) { | 720 if (!persisted_guid.empty()) { |
| 730 current_machine_tag_ = persisted_guid; | 721 current_machine_tag_ = persisted_guid; |
| 731 DVLOG(1) << "Restoring persisted session sync guid: " | 722 DVLOG(1) << "Restoring persisted session sync guid: " |
| 732 << persisted_guid; | 723 << persisted_guid; |
| 733 } else { | 724 } else { |
| 734 current_machine_tag_ = GetMachineTagFromTransaction(trans); | 725 current_machine_tag_ = GetMachineTagFromTransaction(trans); |
| 735 DVLOG(1) << "Creating session sync guid: " << current_machine_tag_; | 726 DVLOG(1) << "Creating session sync guid: " << current_machine_tag_; |
| 736 if (pref_service_) | 727 prefs.SetSyncSessionsGUID(current_machine_tag_); |
| 737 pref_service_->SetString(kSyncSessionsGUID, current_machine_tag_); | |
| 738 } | 728 } |
| 739 | 729 |
| 740 tab_pool_.set_machine_tag(current_machine_tag_); | 730 tab_pool_.set_machine_tag(current_machine_tag_); |
| 741 } | 731 } |
| 742 | 732 |
| 743 bool SessionModelAssociator::GetSyncedFaviconForPageURL( | 733 bool SessionModelAssociator::GetSyncedFaviconForPageURL( |
| 744 const std::string& url, | 734 const std::string& url, |
| 745 std::string* png_favicon) const { | 735 std::string* png_favicon) const { |
| 746 std::map<std::string, std::string>::const_iterator iter = | 736 std::map<std::string, std::string>::const_iterator iter = |
| 747 synced_favicon_pages_.find(url); | 737 synced_favicon_pages_.find(url); |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1253 | 1243 |
| 1254 bool SessionModelAssociator::CryptoReadyIfNecessary() { | 1244 bool SessionModelAssociator::CryptoReadyIfNecessary() { |
| 1255 // We only access the cryptographer while holding a transaction. | 1245 // We only access the cryptographer while holding a transaction. |
| 1256 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1246 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 1257 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes(); | 1247 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes(); |
| 1258 return !encrypted_types.Has(SESSIONS) || | 1248 return !encrypted_types.Has(SESSIONS) || |
| 1259 sync_service_->IsCryptographerReady(&trans); | 1249 sync_service_->IsCryptographerReady(&trans); |
| 1260 } | 1250 } |
| 1261 | 1251 |
| 1262 } // namespace browser_sync | 1252 } // namespace browser_sync |
| OLD | NEW |