Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / profiles / profile_helper.h
blobe31cadd2977e355f09c762b15550992c72e81c98
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_
8 #include <string>
9 #include <vector>
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"
18 class Profile;
20 namespace chromeos {
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 {
36 public:
37 ProfileHelper();
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
62 // signin Profile.
63 static bool IsSigninProfile(Profile* profile);
65 // Initialize a bunch of services that are tied to a browser profile.
66 // TODO(dzhioev): Investigate whether or not this method is needed.
67 void ProfileStartup(Profile* profile, bool process_startup);
69 // Returns active user profile dir in a format [u-$hash].
70 base::FilePath GetActiveUserProfileDir();
72 // Should called once after UserManager instance has been created.
73 void Initialize();
75 // Returns hash for active user ID which is used to identify that user profile
76 // on Chrome OS.
77 std::string active_user_id_hash() { return active_user_id_hash_; }
79 // Clears site data (cookies, history, etc) for signin profile.
80 // Callback can be empty. Not thread-safe.
81 void ClearSigninProfile(const base::Closure& on_clear_callback);
83 private:
84 friend class ProfileHelperTest;
85 friend class ProfileListChromeOSTest;
87 // BrowsingDataRemover::Observer implementation:
88 virtual void OnBrowsingDataRemoverDone() OVERRIDE;
90 // UserManager::Observer overrides.
91 virtual void OnSessionRestoreStateChanged(
92 Profile* user_profile,
93 OAuth2LoginManager::SessionRestoreState state) OVERRIDE;
95 // UserManager::UserSessionStateObserver implementation:
96 virtual void ActiveUserHashChanged(const std::string& hash) OVERRIDE;
98 // Identifies path to active user profile on Chrome OS.
99 std::string active_user_id_hash_;
101 // True if signin profile clearing now.
102 bool signin_profile_clear_requested_;
104 // List of callbacks called after signin profile clearance.
105 std::vector<base::Closure> on_clear_callbacks_;
107 DISALLOW_COPY_AND_ASSIGN(ProfileHelper);
110 } // namespace chromeos
112 #endif // CHROME_BROWSER_CHROMEOS_PROFILES_PROFILE_HELPER_H_