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/credential_cache_service_win.h" | 5 #include "chrome/browser/sync/credential_cache_service_win.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 alternate_store_.release(); | 87 alternate_store_.release(); |
88 } | 88 } |
89 | 89 |
90 void CredentialCacheService::Observe( | 90 void CredentialCacheService::Observe( |
91 int type, | 91 int type, |
92 const content::NotificationSource& source, | 92 const content::NotificationSource& source, |
93 const content::NotificationDetails& details) { | 93 const content::NotificationDetails& details) { |
94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
95 DCHECK(local_store_.get()); | 95 DCHECK(local_store_.get()); |
96 switch (type) { | 96 switch (type) { |
97 case chrome::NOTIFICATION_PREF_CHANGED: { | |
98 // One of the two sync encryption tokens has changed. Update its value in | |
99 // the local cache. | |
100 const std::string pref_name = | |
101 *(content::Details<const std::string>(details).ptr()); | |
102 if (pref_name == prefs::kSyncEncryptionBootstrapToken) { | |
103 PackAndUpdateStringPref(pref_name, | |
104 sync_prefs_.GetEncryptionBootstrapToken()); | |
105 } else if (pref_name == prefs::kSyncKeystoreEncryptionBootstrapToken) { | |
106 PackAndUpdateStringPref( | |
107 pref_name, | |
108 sync_prefs_.GetKeystoreEncryptionBootstrapToken()); | |
109 } else { | |
110 NOTREACHED() "Invalid pref name " << pref_name << "."; | |
111 } | |
112 break; | |
113 } | |
114 | |
115 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT: { | 97 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT: { |
116 // The user has signed out. Write blank values to the google username, | 98 // The user has signed out. Write blank values to the google username, |
117 // encryption tokens and token service credentials in the local cache. | 99 // encryption tokens and token service credentials in the local cache. |
118 PackAndUpdateStringPref(prefs::kGoogleServicesUsername, std::string()); | 100 PackAndUpdateStringPref(prefs::kGoogleServicesUsername, std::string()); |
119 if (HasPref(local_store_, prefs::kSyncEncryptionBootstrapToken)) { | 101 if (HasPref(local_store_, prefs::kSyncEncryptionBootstrapToken)) { |
120 PackAndUpdateStringPref(prefs::kSyncEncryptionBootstrapToken, | 102 PackAndUpdateStringPref(prefs::kSyncEncryptionBootstrapToken, |
121 std::string()); | 103 std::string()); |
122 } | 104 } |
123 if (HasPref(local_store_, prefs::kSyncKeystoreEncryptionBootstrapToken)) { | 105 if (HasPref(local_store_, prefs::kSyncKeystoreEncryptionBootstrapToken)) { |
124 PackAndUpdateStringPref(prefs::kSyncKeystoreEncryptionBootstrapToken, | 106 PackAndUpdateStringPref(prefs::kSyncKeystoreEncryptionBootstrapToken, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 break; | 168 break; |
187 } | 169 } |
188 | 170 |
189 default: { | 171 default: { |
190 NOTREACHED(); | 172 NOTREACHED(); |
191 break; | 173 break; |
192 } | 174 } |
193 } | 175 } |
194 } | 176 } |
195 | 177 |
| 178 void CredentialCacheService::OnPreferenceChanged(PrefServiceBase* service, |
| 179 const std::string& pref_name) { |
| 180 // One of the two sync encryption tokens has changed. Update its value in |
| 181 // the local cache. |
| 182 if (pref_name == prefs::kSyncEncryptionBootstrapToken) { |
| 183 PackAndUpdateStringPref(pref_name, |
| 184 sync_prefs_.GetEncryptionBootstrapToken()); |
| 185 } else if (pref_name == prefs::kSyncKeystoreEncryptionBootstrapToken) { |
| 186 PackAndUpdateStringPref( |
| 187 pref_name, |
| 188 sync_prefs_.GetKeystoreEncryptionBootstrapToken()); |
| 189 } else { |
| 190 NOTREACHED() "Invalid pref name " << pref_name << "."; |
| 191 } |
| 192 } |
| 193 |
196 void CredentialCacheService::ReadCachedCredentialsFromAlternateProfile() { | 194 void CredentialCacheService::ReadCachedCredentialsFromAlternateProfile() { |
197 // If the local user has signed in and signed out, we do not consume cached | 195 // If the local user has signed in and signed out, we do not consume cached |
198 // credentials from the alternate profile. There is nothing more to do, now or | 196 // credentials from the alternate profile. There is nothing more to do, now or |
199 // later on. | 197 // later on. |
200 if (HasUserSignedOut()) | 198 if (HasUserSignedOut()) |
201 return; | 199 return; |
202 | 200 |
203 // Sanity check the alternate credential cache. Note that it is sufficient to | 201 // Sanity check the alternate credential cache. Note that it is sufficient to |
204 // have just one of the two sync encryption tokens. If any string credentials | 202 // have just one of the two sync encryption tokens. If any string credentials |
205 // are outright missing even though the file exists, something is awry with | 203 // are outright missing even though the file exists, something is awry with |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 !HasUserSignedOut() && | 868 !HasUserSignedOut() && |
871 !alternate_google_services_username.empty() && | 869 !alternate_google_services_username.empty() && |
872 !alternate_lsid.empty() && | 870 !alternate_lsid.empty() && |
873 !alternate_sid.empty() && | 871 !alternate_sid.empty() && |
874 !(alternate_encryption_bootstrap_token.empty() && | 872 !(alternate_encryption_bootstrap_token.empty() && |
875 alternate_keystore_encryption_bootstrap_token.empty()) && | 873 alternate_keystore_encryption_bootstrap_token.empty()) && |
876 !service->setup_in_progress(); | 874 !service->setup_in_progress(); |
877 } | 875 } |
878 | 876 |
879 } // namespace syncer | 877 } // namespace syncer |
OLD | NEW |