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