| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_CHROMEOS_PROFILES_PROFILE_HELPER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_PROFILES_PROFILE_HELPER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_PROFILES_PROFILE_HELPER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_PROFILES_PROFILE_HELPER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 14 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
| 15 #include "chrome/browser/chromeos/login/oauth2_login_manager.h" |
| 15 #include "chrome/browser/chromeos/login/user_manager.h" | 16 #include "chrome/browser/chromeos/login/user_manager.h" |
| 16 | 17 |
| 17 class Profile; | 18 class Profile; |
| 18 | 19 |
| 19 namespace chromeos { | 20 namespace chromeos { |
| 20 | 21 |
| 21 // This helper class is used on Chrome OS to keep track of currently | 22 // This helper class is used on Chrome OS to keep track of currently |
| 22 // active user profile. | 23 // active user profile. |
| 23 // Whenever active user is changed (either add another user into session or | 24 // Whenever active user is changed (either add another user into session or |
| 24 // switch between users), ActiveUserHashChanged() will be called thus | 25 // switch between users), ActiveUserHashChanged() will be called thus |
| 25 // internal state |active_user_id_hash_| will be updated. | 26 // internal state |active_user_id_hash_| will be updated. |
| 26 // Typical use cases for using this class: | 27 // Typical use cases for using this class: |
| 27 // 1. Get "signin profile" which is a special type of profile that is only used | 28 // 1. Get "signin profile" which is a special type of profile that is only used |
| 28 // during signin flow: GetSigninProfile() | 29 // during signin flow: GetSigninProfile() |
| 29 // 2. Get profile dir of an active user, used by ProfileManager: | 30 // 2. Get profile dir of an active user, used by ProfileManager: |
| 30 // GetActiveUserProfileDir() | 31 // GetActiveUserProfileDir() |
| 31 // 3. Get mapping from user_id_hash to Profile instance/profile path etc. | 32 // 3. Get mapping from user_id_hash to Profile instance/profile path etc. |
| 32 class ProfileHelper : public BrowsingDataRemover::Observer, | 33 class ProfileHelper : public BrowsingDataRemover::Observer, |
| 33 public UserManager::Observer, | 34 public OAuth2LoginManager::Observer, |
| 34 public UserManager::UserSessionStateObserver { | 35 public UserManager::UserSessionStateObserver { |
| 35 public: | 36 public: |
| 36 ProfileHelper(); | 37 ProfileHelper(); |
| 37 virtual ~ProfileHelper(); | 38 virtual ~ProfileHelper(); |
| 38 | 39 |
| 39 // Returns Profile instance that corresponds to |user_id_hash|. | 40 // Returns Profile instance that corresponds to |user_id_hash|. |
| 40 static Profile* GetProfileByUserIdHash(const std::string& user_id_hash); | 41 static Profile* GetProfileByUserIdHash(const std::string& user_id_hash); |
| 41 | 42 |
| 42 // Returns profile path that corresponds to a given |user_id_hash|. | 43 // Returns profile path that corresponds to a given |user_id_hash|. |
| 43 static base::FilePath GetProfilePathByUserIdHash( | 44 static base::FilePath GetProfilePathByUserIdHash( |
| 44 const std::string& user_id_hash); | 45 const std::string& user_id_hash); |
| 45 | 46 |
| 46 // Returns OffTheRecord profile for use during signing phase. | 47 // Returns OffTheRecord profile for use during signing phase. |
| 47 static Profile* GetSigninProfile(); | 48 static Profile* GetSigninProfile(); |
| 48 | 49 |
| 49 // Returns user_id hash for |profile| instance or empty string if hash | 50 // Returns user_id hash for |profile| instance or empty string if hash |
| 50 // could not be extracted from |profile|. | 51 // could not be extracted from |profile|. |
| 51 static std::string GetUserIdHashFromProfile(Profile* profile); | 52 static std::string GetUserIdHashFromProfile(Profile* profile); |
| 52 | 53 |
| 53 // Returns true if |profile| is the signin Profile. This can be used during | 54 // Returns true if |profile| is the signin Profile. This can be used during |
| 54 // construction of the signin Profile to determine if that Profile is the | 55 // construction of the signin Profile to determine if that Profile is the |
| 55 // signin Profile. | 56 // signin Profile. |
| 56 static bool IsSigninProfile(Profile* profile); | 57 static bool IsSigninProfile(Profile* profile); |
| 57 | 58 |
| 58 // Initialize a bunch of services that are tied to a browser profile. | 59 // Initialize a bunch of services that are tied to a browser profile. |
| 59 // TODO(dzhioev): Investigate whether or not this method is needed. | 60 // TODO(dzhioev): Investigate whether or not this method is needed. |
| 60 static void ProfileStartup(Profile* profile, bool process_startup); | 61 void ProfileStartup(Profile* profile, bool process_startup); |
| 61 | 62 |
| 62 // Returns active user profile dir in a format [u-$hash]. | 63 // Returns active user profile dir in a format [u-$hash]. |
| 63 base::FilePath GetActiveUserProfileDir(); | 64 base::FilePath GetActiveUserProfileDir(); |
| 64 | 65 |
| 65 // Should called once after UserManager instance has been created. | 66 // Should called once after UserManager instance has been created. |
| 66 void Initialize(); | 67 void Initialize(); |
| 67 | 68 |
| 68 // Returns hash for active user ID which is used to identify that user profile | 69 // Returns hash for active user ID which is used to identify that user profile |
| 69 // on Chrome OS. | 70 // on Chrome OS. |
| 70 std::string active_user_id_hash() { return active_user_id_hash_; } | 71 std::string active_user_id_hash() { return active_user_id_hash_; } |
| 71 | 72 |
| 72 // Clears site data (cookies, history, etc) for signin profile. | 73 // Clears site data (cookies, history, etc) for signin profile. |
| 73 // Callback can be empty. Not thread-safe. | 74 // Callback can be empty. Not thread-safe. |
| 74 void ClearSigninProfile(const base::Closure& on_clear_callback); | 75 void ClearSigninProfile(const base::Closure& on_clear_callback); |
| 75 | 76 |
| 76 private: | 77 private: |
| 77 friend class ProfileHelperTest; | 78 friend class ProfileHelperTest; |
| 78 | 79 |
| 79 // BrowsingDataRemover::Observer implementation: | 80 // BrowsingDataRemover::Observer implementation: |
| 80 virtual void OnBrowsingDataRemoverDone() OVERRIDE; | 81 virtual void OnBrowsingDataRemoverDone() OVERRIDE; |
| 81 | 82 |
| 82 // UserManager::Observer overrides. | 83 // UserManager::Observer overrides. |
| 83 virtual void MergeSessionStateChanged( | 84 virtual void OnSessionRestoreStateChanged( |
| 84 UserManager::MergeSessionState state) OVERRIDE; | 85 Profile* user_profile, |
| 86 OAuth2LoginManager::SessionRestoreState state) OVERRIDE; |
| 85 | 87 |
| 86 // UserManager::UserSessionStateObserver implementation: | 88 // UserManager::UserSessionStateObserver implementation: |
| 87 virtual void ActiveUserHashChanged(const std::string& hash) OVERRIDE; | 89 virtual void ActiveUserHashChanged(const std::string& hash) OVERRIDE; |
| 88 | 90 |
| 89 // Identifies path to active user profile on Chrome OS. | 91 // Identifies path to active user profile on Chrome OS. |
| 90 std::string active_user_id_hash_; | 92 std::string active_user_id_hash_; |
| 91 | 93 |
| 92 // True if signin profile clearing now. | 94 // True if signin profile clearing now. |
| 93 bool signin_profile_clear_requested_; | 95 bool signin_profile_clear_requested_; |
| 94 | 96 |
| 95 // List of callbacks called after signin profile clearance. | 97 // List of callbacks called after signin profile clearance. |
| 96 std::vector<base::Closure> on_clear_callbacks_; | 98 std::vector<base::Closure> on_clear_callbacks_; |
| 97 | 99 |
| 98 DISALLOW_COPY_AND_ASSIGN(ProfileHelper); | 100 DISALLOW_COPY_AND_ASSIGN(ProfileHelper); |
| 99 }; | 101 }; |
| 100 | 102 |
| 101 } // namespace chromeos | 103 } // namespace chromeos |
| 102 | 104 |
| 103 #endif // CHROME_BROWSER_CHROMEOS_PROFILES_PROFILE_HELPER_H_ | 105 #endif // CHROME_BROWSER_CHROMEOS_PROFILES_PROFILE_HELPER_H_ |
| OLD | NEW |