Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: chrome/browser/sync/credential_cache_service_win.h

Issue 10656033: [sync] Automatic bootstrapping of Sync on Win 8 from cached credentials (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix TokenServiceTests Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_SYNC_CREDENTIAL_CACHE_SERVICE_WIN_H_
6 #define CHROME_BROWSER_SYNC_CREDENTIAL_CACHE_SERVICE_WIN_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/file_path.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/prefs/pref_change_registrar.h"
15 #include "chrome/browser/profiles/profile_keyed_service.h"
16 #include "chrome/common/json_pref_store.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
19
20 namespace base {
21 class StringValue;
22 class Value;
23 }
24
25 class Profile;
26
27 namespace syncer {
28
29 // On Windows 8, Chrome must maintain separate profile directories for Metro and
30 // Desktop modes. When the user signs in to sync in one of the modes, we would
31 // like to automatically start sync in the other mode.
32 //
33 // This class implements a caching service for sync credentials. It listens for
34 // updates to the PrefService and TokenSerervice that pertain to the user
Roger Tawa OOO till Jul 10th 2012/07/23 15:10:33 Serervice -> Service
Raghu Simha 2012/07/23 20:35:54 Done.
35 // signing in and out of sync, and persists the credentials to a separate file
36 // in the default profile directory. It also contains functionality to bootstrap
37 // sync using credentials that were cached due to signing in on the other
38 // (alternate) mode.
39 class CredentialCacheService : public ProfileKeyedService,
40 public content::NotificationObserver,
41 public PrefStore::Observer {
42 public:
43 explicit CredentialCacheService(Profile* profile);
44 virtual ~CredentialCacheService();
45
46 // ProfileKeyedService implementation.
47 virtual void Shutdown() OVERRIDE;
48
49 // Returns true if |profile_dir| is the "Default" folder in Chrome's default
50 // user data directory, and false otherwise.
51 static bool IsDefaultProfileDir(const FilePath& profile_dir);
52
53 // Encrypts and base 64 encodes |credential|, converts the result to a
54 // StringValue, and returns the result. Caller owns the StringValue returned.
55 static base::StringValue* PackCredential(const std::string& credential);
56
57 // Extracts a string from the Value |packed|, base 64 decodes and decrypts it,
58 // and returns the result.
59 static std::string UnpackCredential(const base::Value& packed);
60
61 // PrefStore::Observer implementation.
62 virtual void OnInitializationCompleted(bool succeeded) OVERRIDE;
63 virtual void OnPrefValueChanged(const std::string& key) OVERRIDE;
64
65 // Asynchronously looks for a cached credential file in the alternate profile
66 // and initiates start up using cached credentials if the file was found.
67 // Called by ProfileSyncService when it tries to start up on Windows 8 and
68 // cannot auto-start.
69 void LookForCachedCredentialsInAlternateProfile();
Roger Tawa OOO till Jul 10th 2012/07/23 15:10:33 I think this is the only methods that needs to be
Raghu Simha 2012/07/23 20:35:54 Good point, but LookForCachedCredentialsInAlternat
70
71 // Returns true if the service was able to successfully load credentials from
72 // the alternate profile.
73 bool SuccessfullyLoadedCredentials() const;
74
75 // Returns true if the credential cache represented by |store| contains a
76 // value for |pref_name|.
77 bool HasPref(scoped_refptr<JsonPrefStore> store,
78 const std::string& pref_name);
79
80 // Returns true if there is an empty value for kGoogleServicesUsername in the
81 // credential cache for the local profile (indicating that the user first
82 // signed in and then signed out). Returns false if there's no value at all
83 // (indicating that the user has never signed in) or if there's a non-empty
84 // value (indicating that the user is currently signed in).
85 bool HasUserSignedOut();
86
87 // Updates the value of |pref_name| to |new_value|, unless the user has signed
88 // out, in which case we write an empty string value to |pref_name|.
89 void UpdateStringPref(const std::string& pref_name,
90 const std::string& new_value);
91
92 // Updates the value of |pref_name| to |new_value|, unless the user has signed
93 // out, in which case we write "false" to |pref_name|.
94 void UpdateBooleanPref(const std::string& pref_name, bool new_value);
95
96 // Returns the string pref value contained in |store| for |pref_name|. Assumes
97 // that |store| contains a value for |pref_name|.
98 std::string GetStringPref(scoped_refptr<JsonPrefStore> store,
99 const std::string& pref_name);
100
101 // Returns the boolean pref value contained in |store| for |pref_name|.
102 // Assumes that |store| contains a value for |pref_name|.
103 bool GetBooleanPref(scoped_refptr<JsonPrefStore> store,
104 const std::string& pref_name);
105
106 // content::NotificationObserver implementation.
107 virtual void Observe(int type,
108 const content::NotificationSource& source,
109 const content::NotificationDetails& details) OVERRIDE;
110
111 protected:
112 // Used for write operations to the credential cache file in the local profile
113 // directory. This is separate from the chrome pref store. Protected so that
114 // it can be accessed by unit tests.
115 scoped_refptr<JsonPrefStore> local_store_;
Roger Tawa OOO till Jul 10th 2012/07/23 15:10:33 should move data member to private section and add
Raghu Simha 2012/07/23 20:35:54 Done.
116
117 private:
118 // Returns the path to the sync credentials file in the current profile
119 // directory.
120 FilePath GetCredentialPathInCurrentProfile() const;
121
122 // Returns the path to the sync credentials file in the default Desktop
123 // profile directory if we are running in Metro mode, and vice versa.
124 FilePath GetCredentialPathInAlternateProfile() const;
125
126 // Initializes the JsonPrefStore object for the local profile directory.
127 void InitializeLocalCredentialCacheWriter();
128
129 // Initializes the JsonPrefStore object for the alternate profile directory
130 // if |should_initialize| is true. We take a bool* instead of a bool since
131 // this is a callback, and base::Owned needs to clean up the flag.
132 void InitializeAlternateCredentialCacheReader(bool* should_initialize);
133
134 // Loads cached sync credentials from the alternate profile and calls
135 // ApplyCachedCredentials if the load was successful.
136 void ReadCachedCredentialsFromAlternateProfile();
137
138 // Applies the credentials read from the alternate profile to the pref store
139 // and token service of the local profile and then notifies listeners.
140 void ApplyCachedCredentials(const std::string& google_services_username,
141 const std::string& lsid,
142 const std::string& sid,
143 const std::string& encryption_bootstrap_token,
144 bool keep_everything_synced,
145 const bool datatype_prefs[]);
146
147 // Keeps track of when we were able to successfully load credentials from
148 // the alternate profile.
149 bool loaded_credentials_;
150
151 // Profile for which credentials are being cached.
152 Profile* profile_;
153
154 // WeakPtr implementation.
155 base::WeakPtrFactory<CredentialCacheService> weak_factory_;
156
157 // Used for read operations on the credential cache file in the alternate
158 // profile directory. This is separate from the chrome pref store.
159 scoped_refptr<JsonPrefStore> alternate_store_;
160
161 // Registrar for notifications from the PrefService.
162 PrefChangeRegistrar pref_registrar_;
163
164 // Registrar for notifications from the TokenService.
165 content::NotificationRegistrar registrar_;
166
167 DISALLOW_COPY_AND_ASSIGN(CredentialCacheService);
168 };
169
170 } // namespace syncer
171
172 #endif // CHROME_BROWSER_SYNC_CREDENTIAL_CACHE_SERVICE_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698