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.
5 #ifndef CHROME_BROWSER_CHROMEOS_PROFILES_PROFILE_HELPER_H_
6 #define CHROME_BROWSER_CHROMEOS_PROFILES_PROFILE_HELPER_H_
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/oauth2_login_manager.h"
16 #include "chrome/browser/chromeos/login/user_manager.h"
22 // This helper class is used on Chrome OS to keep track of currently
23 // active user profile.
24 // Whenever active user is changed (either add another user into session or
25 // switch between users), ActiveUserHashChanged() will be called thus
26 // internal state |active_user_id_hash_| will be updated.
27 // Typical use cases for using this class:
28 // 1. Get "signin profile" which is a special type of profile that is only used
29 // during signin flow: GetSigninProfile()
30 // 2. Get profile dir of an active user, used by ProfileManager:
31 // GetActiveUserProfileDir()
32 // 3. Get mapping from user_id_hash to Profile instance/profile path etc.
33 class ProfileHelper
: public BrowsingDataRemover::Observer
,
34 public OAuth2LoginManager::Observer
,
35 public UserManager::UserSessionStateObserver
{
38 virtual ~ProfileHelper();
40 // Returns Profile instance that corresponds to |user_id_hash|.
41 static Profile
* GetProfileByUserIdHash(const std::string
& user_id_hash
);
43 // Returns profile dir that corresponds to a --login-profile cmd line switch.
44 static base::FilePath
GetProfileDirByLegacyLoginProfileSwitch();
46 // Returns profile path that corresponds to a given |user_id_hash|.
47 static base::FilePath
GetProfilePathByUserIdHash(
48 const std::string
& user_id_hash
);
50 // Returns OffTheRecord profile for use during signing phase.
51 static Profile
* GetSigninProfile();
53 // Returns user_id hash for |profile| instance or empty string if hash
54 // could not be extracted from |profile|.
55 static std::string
GetUserIdHashFromProfile(Profile
* profile
);
57 // Returns user profile dir in a format [u-user_id_hash].
58 static base::FilePath
GetUserProfileDir(const std::string
& user_id_hash
);
60 // Returns true if |profile| is the signin Profile. This can be used during
61 // construction of the signin Profile to determine if that Profile is the
63 static bool IsSigninProfile(Profile
* profile
);
65 // Returns true when |profile| corresponds to owner's profile.
66 static bool IsOwnerProfile(Profile
* profile
);
68 // Initialize a bunch of services that are tied to a browser profile.
69 // TODO(dzhioev): Investigate whether or not this method is needed.
70 void ProfileStartup(Profile
* profile
, bool process_startup
);
72 // Returns active user profile dir in a format [u-$hash].
73 base::FilePath
GetActiveUserProfileDir();
75 // Should called once after UserManager instance has been created.
78 // Returns hash for active user ID which is used to identify that user profile
80 std::string
active_user_id_hash() { return active_user_id_hash_
; }
82 // Clears site data (cookies, history, etc) for signin profile.
83 // Callback can be empty. Not thread-safe.
84 void ClearSigninProfile(const base::Closure
& on_clear_callback
);
87 friend class ProfileHelperTest
;
88 friend class ProfileListChromeOSTest
;
90 // BrowsingDataRemover::Observer implementation:
91 virtual void OnBrowsingDataRemoverDone() OVERRIDE
;
93 // UserManager::Observer overrides.
94 virtual void OnSessionRestoreStateChanged(
95 Profile
* user_profile
,
96 OAuth2LoginManager::SessionRestoreState state
) OVERRIDE
;
98 // UserManager::UserSessionStateObserver implementation:
99 virtual void ActiveUserHashChanged(const std::string
& hash
) OVERRIDE
;
101 // Identifies path to active user profile on Chrome OS.
102 std::string active_user_id_hash_
;
104 // True if signin profile clearing now.
105 bool signin_profile_clear_requested_
;
107 // List of callbacks called after signin profile clearance.
108 std::vector
<base::Closure
> on_clear_callbacks_
;
110 DISALLOW_COPY_AND_ASSIGN(ProfileHelper
);
113 } // namespace chromeos
115 #endif // CHROME_BROWSER_CHROMEOS_PROFILES_PROFILE_HELPER_H_