Chromium Code Reviews| Index: chrome/browser/sync/credential_cache_service_win.h |
| diff --git a/chrome/browser/sync/credential_cache_service_win.h b/chrome/browser/sync/credential_cache_service_win.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0094961f5dc6730d1c1cdf4d1b40c63e88b84da1 |
| --- /dev/null |
| +++ b/chrome/browser/sync/credential_cache_service_win.h |
| @@ -0,0 +1,172 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_SYNC_CREDENTIAL_CACHE_SERVICE_WIN_H_ |
| +#define CHROME_BROWSER_SYNC_CREDENTIAL_CACHE_SERVICE_WIN_H_ |
| + |
| +#include <string> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/file_path.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "chrome/browser/prefs/pref_change_registrar.h" |
| +#include "chrome/browser/profiles/profile_keyed_service.h" |
| +#include "chrome/common/json_pref_store.h" |
| +#include "content/public/browser/notification_observer.h" |
| +#include "content/public/browser/notification_registrar.h" |
| + |
| +namespace base { |
| +class StringValue; |
| +class Value; |
| +} |
| + |
| +class Profile; |
| + |
| +namespace syncer { |
| + |
| +// On Windows 8, Chrome must maintain separate profile directories for Metro and |
| +// Desktop modes. When the user signs in to sync in one of the modes, we would |
| +// like to automatically start sync in the other mode. |
| +// |
| +// This class implements a caching service for sync credentials. It listens for |
| +// 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.
|
| +// signing in and out of sync, and persists the credentials to a separate file |
| +// in the default profile directory. It also contains functionality to bootstrap |
| +// sync using credentials that were cached due to signing in on the other |
| +// (alternate) mode. |
| +class CredentialCacheService : public ProfileKeyedService, |
| + public content::NotificationObserver, |
| + public PrefStore::Observer { |
| + public: |
| + explicit CredentialCacheService(Profile* profile); |
| + virtual ~CredentialCacheService(); |
| + |
| + // ProfileKeyedService implementation. |
| + virtual void Shutdown() OVERRIDE; |
| + |
| + // Returns true if |profile_dir| is the "Default" folder in Chrome's default |
| + // user data directory, and false otherwise. |
| + static bool IsDefaultProfileDir(const FilePath& profile_dir); |
| + |
| + // Encrypts and base 64 encodes |credential|, converts the result to a |
| + // StringValue, and returns the result. Caller owns the StringValue returned. |
| + static base::StringValue* PackCredential(const std::string& credential); |
| + |
| + // Extracts a string from the Value |packed|, base 64 decodes and decrypts it, |
| + // and returns the result. |
| + static std::string UnpackCredential(const base::Value& packed); |
| + |
| + // PrefStore::Observer implementation. |
| + virtual void OnInitializationCompleted(bool succeeded) OVERRIDE; |
| + virtual void OnPrefValueChanged(const std::string& key) OVERRIDE; |
| + |
| + // Asynchronously looks for a cached credential file in the alternate profile |
| + // and initiates start up using cached credentials if the file was found. |
| + // Called by ProfileSyncService when it tries to start up on Windows 8 and |
| + // cannot auto-start. |
| + 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
|
| + |
| + // Returns true if the service was able to successfully load credentials from |
| + // the alternate profile. |
| + bool SuccessfullyLoadedCredentials() const; |
| + |
| + // Returns true if the credential cache represented by |store| contains a |
| + // value for |pref_name|. |
| + bool HasPref(scoped_refptr<JsonPrefStore> store, |
| + const std::string& pref_name); |
| + |
| + // Returns true if there is an empty value for kGoogleServicesUsername in the |
| + // credential cache for the local profile (indicating that the user first |
| + // signed in and then signed out). Returns false if there's no value at all |
| + // (indicating that the user has never signed in) or if there's a non-empty |
| + // value (indicating that the user is currently signed in). |
| + bool HasUserSignedOut(); |
| + |
| + // Updates the value of |pref_name| to |new_value|, unless the user has signed |
| + // out, in which case we write an empty string value to |pref_name|. |
| + void UpdateStringPref(const std::string& pref_name, |
| + const std::string& new_value); |
| + |
| + // Updates the value of |pref_name| to |new_value|, unless the user has signed |
| + // out, in which case we write "false" to |pref_name|. |
| + void UpdateBooleanPref(const std::string& pref_name, bool new_value); |
| + |
| + // Returns the string pref value contained in |store| for |pref_name|. Assumes |
| + // that |store| contains a value for |pref_name|. |
| + std::string GetStringPref(scoped_refptr<JsonPrefStore> store, |
| + const std::string& pref_name); |
| + |
| + // Returns the boolean pref value contained in |store| for |pref_name|. |
| + // Assumes that |store| contains a value for |pref_name|. |
| + bool GetBooleanPref(scoped_refptr<JsonPrefStore> store, |
| + const std::string& pref_name); |
| + |
| + // content::NotificationObserver implementation. |
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) OVERRIDE; |
| + |
| + protected: |
| + // Used for write operations to the credential cache file in the local profile |
| + // directory. This is separate from the chrome pref store. Protected so that |
| + // it can be accessed by unit tests. |
| + 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.
|
| + |
| + private: |
| + // Returns the path to the sync credentials file in the current profile |
| + // directory. |
| + FilePath GetCredentialPathInCurrentProfile() const; |
| + |
| + // Returns the path to the sync credentials file in the default Desktop |
| + // profile directory if we are running in Metro mode, and vice versa. |
| + FilePath GetCredentialPathInAlternateProfile() const; |
| + |
| + // Initializes the JsonPrefStore object for the local profile directory. |
| + void InitializeLocalCredentialCacheWriter(); |
| + |
| + // Initializes the JsonPrefStore object for the alternate profile directory |
| + // if |should_initialize| is true. We take a bool* instead of a bool since |
| + // this is a callback, and base::Owned needs to clean up the flag. |
| + void InitializeAlternateCredentialCacheReader(bool* should_initialize); |
| + |
| + // Loads cached sync credentials from the alternate profile and calls |
| + // ApplyCachedCredentials if the load was successful. |
| + void ReadCachedCredentialsFromAlternateProfile(); |
| + |
| + // Applies the credentials read from the alternate profile to the pref store |
| + // and token service of the local profile and then notifies listeners. |
| + void ApplyCachedCredentials(const std::string& google_services_username, |
| + const std::string& lsid, |
| + const std::string& sid, |
| + const std::string& encryption_bootstrap_token, |
| + bool keep_everything_synced, |
| + const bool datatype_prefs[]); |
| + |
| + // Keeps track of when we were able to successfully load credentials from |
| + // the alternate profile. |
| + bool loaded_credentials_; |
| + |
| + // Profile for which credentials are being cached. |
| + Profile* profile_; |
| + |
| + // WeakPtr implementation. |
| + base::WeakPtrFactory<CredentialCacheService> weak_factory_; |
| + |
| + // Used for read operations on the credential cache file in the alternate |
| + // profile directory. This is separate from the chrome pref store. |
| + scoped_refptr<JsonPrefStore> alternate_store_; |
| + |
| + // Registrar for notifications from the PrefService. |
| + PrefChangeRegistrar pref_registrar_; |
| + |
| + // Registrar for notifications from the TokenService. |
| + content::NotificationRegistrar registrar_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CredentialCacheService); |
| +}; |
| + |
| +} // namespace syncer |
| + |
| +#endif // CHROME_BROWSER_SYNC_CREDENTIAL_CACHE_SERVICE_WIN_H_ |