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 #ifndef CHROME_BROWSER_SYNC_CREDENTIAL_CACHE_SERVICE_WIN_H_ | 5 #ifndef CHROME_BROWSER_SYNC_CREDENTIAL_CACHE_SERVICE_WIN_H_ |
6 #define CHROME_BROWSER_SYNC_CREDENTIAL_CACHE_SERVICE_WIN_H_ | 6 #define CHROME_BROWSER_SYNC_CREDENTIAL_CACHE_SERVICE_WIN_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/cancelable_callback.h" | 11 #include "base/cancelable_callback.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/prefs/json_pref_store.h" | 15 #include "base/prefs/json_pref_store.h" |
16 #include "base/prefs/public/pref_change_registrar.h" | 16 #include "base/prefs/public/pref_change_registrar.h" |
| 17 #include "base/prefs/public/pref_observer.h" |
17 #include "chrome/browser/profiles/profile_keyed_service.h" | 18 #include "chrome/browser/profiles/profile_keyed_service.h" |
18 #include "chrome/browser/sync/sync_prefs.h" | 19 #include "chrome/browser/sync/sync_prefs.h" |
19 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
20 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
21 | 22 |
22 namespace base { | 23 namespace base { |
23 class StringValue; | 24 class StringValue; |
24 class Value; | 25 class Value; |
25 } | 26 } |
26 | 27 |
27 class Profile; | 28 class Profile; |
28 | 29 |
29 namespace syncer { | 30 namespace syncer { |
30 | 31 |
31 // On Windows 8, Chrome must maintain separate profile directories for Metro and | 32 // On Windows 8, Chrome must maintain separate profile directories for Metro and |
32 // Desktop modes. When the user signs in to sync in one of the modes, we would | 33 // Desktop modes. When the user signs in to sync in one of the modes, we would |
33 // like to automatically start sync in the other mode. | 34 // like to automatically start sync in the other mode. |
34 // | 35 // |
35 // This class implements a caching service for sync credentials. It listens for | 36 // This class implements a caching service for sync credentials. It listens for |
36 // updates to the PrefService and TokenService that pertain to the user | 37 // updates to the PrefService and TokenService that pertain to the user |
37 // signing in and out of sync, and persists the credentials to a separate file | 38 // signing in and out of sync, and persists the credentials to a separate file |
38 // in the default profile directory. It also contains functionality to bootstrap | 39 // in the default profile directory. It also contains functionality to bootstrap |
39 // sync using credentials that were cached due to signing in on the other | 40 // sync using credentials that were cached due to signing in on the other |
40 // (alternate) mode. | 41 // (alternate) mode. |
41 class CredentialCacheService : public ProfileKeyedService, | 42 class CredentialCacheService : public ProfileKeyedService, |
42 public content::NotificationObserver { | 43 public content::NotificationObserver, |
| 44 public PrefObserver { |
43 public: | 45 public: |
44 explicit CredentialCacheService(Profile* profile); | 46 explicit CredentialCacheService(Profile* profile); |
45 virtual ~CredentialCacheService(); | 47 virtual ~CredentialCacheService(); |
46 | 48 |
47 // ProfileKeyedService implementation. | 49 // ProfileKeyedService implementation. |
48 virtual void Shutdown() OVERRIDE; | 50 virtual void Shutdown() OVERRIDE; |
49 | 51 |
50 // content::NotificationObserver implementation. | 52 // content::NotificationObserver implementation. |
51 virtual void Observe(int type, | 53 virtual void Observe(int type, |
52 const content::NotificationSource& source, | 54 const content::NotificationSource& source, |
53 const content::NotificationDetails& details) OVERRIDE; | 55 const content::NotificationDetails& details) OVERRIDE; |
54 | 56 |
| 57 // PrefObserver implementation. |
| 58 virtual void OnPreferenceChanged(PrefServiceBase* service, |
| 59 const std::string& pref_name) OVERRIDE; |
| 60 |
55 // Loads cached sync credentials from the alternate profile and applies them | 61 // Loads cached sync credentials from the alternate profile and applies them |
56 // to the local profile if the load was successful. | 62 // to the local profile if the load was successful. |
57 void ReadCachedCredentialsFromAlternateProfile(); | 63 void ReadCachedCredentialsFromAlternateProfile(); |
58 | 64 |
59 // Writes kSyncKeepEverythingSynced and the sync preferences for individual | 65 // Writes kSyncKeepEverythingSynced and the sync preferences for individual |
60 // datatypes to the local cache. | 66 // datatypes to the local cache. |
61 void WriteSyncPrefsToLocalCache(); | 67 void WriteSyncPrefsToLocalCache(); |
62 | 68 |
63 // Resets |alternate_store_| and schedules the next read from the alternate | 69 // Resets |alternate_store_| and schedules the next read from the alternate |
64 // credential cache in |delay_secs| seconds. | 70 // credential cache in |delay_secs| seconds. |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 // Used to make sure that there is always at most one future read scheduled | 316 // Used to make sure that there is always at most one future read scheduled |
311 // on the alternate credential cache. | 317 // on the alternate credential cache. |
312 base::CancelableClosure next_read_; | 318 base::CancelableClosure next_read_; |
313 | 319 |
314 DISALLOW_COPY_AND_ASSIGN(CredentialCacheService); | 320 DISALLOW_COPY_AND_ASSIGN(CredentialCacheService); |
315 }; | 321 }; |
316 | 322 |
317 } // namespace syncer | 323 } // namespace syncer |
318 | 324 |
319 #endif // CHROME_BROWSER_SYNC_CREDENTIAL_CACHE_SERVICE_WIN_H_ | 325 #endif // CHROME_BROWSER_SYNC_CREDENTIAL_CACHE_SERVICE_WIN_H_ |
OLD | NEW |