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