File: profile_helper.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (180 lines) | stat: -rw-r--r-- 7,326 bytes parent folder | download | duplicates (6)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ASH_PROFILES_PROFILE_HELPER_H_
#define CHROME_BROWSER_ASH_PROFILES_PROFILE_HELPER_H_

#include <map>
#include <memory>
#include <string>
#include <vector>

#include "base/files/file_path.h"
#include "base/functional/callback_forward.h"

class AccountId;
class IndependentOTRProfileManagerTest;
class Profile;

namespace user_manager {
class User;
}

namespace ash {

// This helper class is used on Chrome OS to keep track of currently
// active user profile.
// 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 mapping from user_id_hash to Profile instance/profile path etc.
class ProfileHelper {
 public:
  ProfileHelper();

  ProfileHelper(const ProfileHelper&) = delete;
  ProfileHelper& operator=(const ProfileHelper&) = delete;

  virtual ~ProfileHelper();

  // Creates and returns ProfileHelper implementation instance to
  // BrowserProcess/BrowserProcessPlatformPart.
  static std::unique_ptr<ProfileHelper> CreateInstance();

  // Returns ProfileHelper instance. This class is not singleton and is owned
  // by BrowserProcess/BrowserProcessPlatformPart. This method keeps that
  // knowledge in one place.
  static ProfileHelper* Get();

  // DEPRECATED: Please use
  // ash::BrowserContextHelper::GetBrowserContextPathByUserIdHash() instead.
  // Returns profile path that corresponds to a given |user_id_hash|.
  static base::FilePath GetProfilePathByUserIdHash(
      const std::string& user_id_hash);

  // DEPRECATED: Please use
  // ash::BrowserContextHelper::GetSigninBrowserContext() instead.
  // Returns OffTheRecord profile for use during signing phase.
  static Profile* GetSigninProfile();

  // DEPRECATED. Please use
  // ash::BrowserContextHelper::GetUserIdHashFromBrowserContext() instead.
  // Returns user_id hash for |profile| instance or empty string if hash
  // could not be extracted from |profile|.
  static std::string GetUserIdHashFromProfile(const Profile* profile);

  // DEPRECATED. Please use
  // ash::BrowserContextHelper::GetUserBrowserContextDirName() instead.
  // Returns user profile dir in a format [u-user_id_hash].
  static base::FilePath GetUserProfileDir(const std::string& user_id_hash);

  // DEPRECATED. Please use ash::IsSigninBrowserContext() instead.
  // 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(const Profile* profile);

  // DEPRECATED. Please use
  // ash::BrowserContextHelper::GetLockScreenBrowserContextPath() instead.
  // Returns the path that corresponds to the lockscreen profile.
  static base::FilePath GetLockScreenProfileDir();

  // DEPRECATED. Please use
  // ash::BrowserContextHelper::GetLockScreenBrowserContext() instead.
  // Returns OffTheRecord profile for use during online authentication on the
  // lock screen.
  static Profile* GetLockScreenProfile();

  // DEPRECATED. Please use ash::IsLockScreenBrowserContext() instead.
  // Returns true if |profile| is the lockscreen profile.
  static bool IsLockScreenProfile(const Profile* profile);

  // DEPRECATED. Please use
  // user_manager::UserManager::Get()->IsOwnerUser(
  //     BrowserContextHelper::Get()->GetUserByBrowserContext(profile))
  // instead.
  // Returns true when |profile| corresponds to owner's profile.
  static bool IsOwnerProfile(const Profile* profile);

  // DEPRECATED. Please use
  // user_manager::UserManager::Get()->IsPrimaryUser(
  //     BrowserContextHelper::Get()->GetUserByBrowserContext(profile))
  // instead.
  // Returns true when |profile| corresponds to the primary user profile
  // of the current session.
  static bool IsPrimaryProfile(const Profile* profile);

  // DEPRECATED. Please use
  // user_manager::UserManager::Get()->IsEphemeralUser(
  //     BrowserContextHelper::Get()->GetUserByBrowserContext(profile))
  // instead.
  // Returns true when |profile| is for an ephemeral user.
  static bool IsEphemeralUserProfile(const Profile* profile);

  // DEPRECATED. Please use ash::IsUserBrowserContext() instead.
  // Returns true if profile or profile_path has corresponding chrome os user.
  // I.e. it is not one for internal use, such as sign-in or lockscreen etc.
  // Note: System and Guest Profiles are considered User profiles. To check on
  // that `Profile` specific method that checks the profile type should used
  // such as `Profile::IsRegularProfile()` or `Profile::IsSystemProfile()`.
  static bool IsUserProfile(const Profile* profile);

  // DEPRECATED. Please use ash::IsUserBrowserContextBaseName() instead.
  static bool IsUserProfilePath(const base::FilePath& profile_path);

  // DEPRECATED: Please use
  // BrowserContextHelper::GetBrowserContextByAccountId() instead.
  // Returns profile of the user associated with |account_id| if it is created
  // and fully initialized. Otherwise, returns NULL.
  virtual Profile* GetProfileByAccountId(const AccountId& account_id) = 0;

  // DEPRECATED: Please use
  // BrowserContextHelper::GetBrowserContextByUser() instead.
  // Returns profile of the |user| if it is created and fully initialized.
  // Otherwise, returns NULL.
  virtual Profile* GetProfileByUser(const user_manager::User* user) = 0;

  // DEPRECATED: Please use
  // BrowserContextHelper::GetUserByBrowserContext() instead.
  // Returns NULL if User is not created.
  virtual const user_manager::User* GetUserByProfile(
      const Profile* profile) const = 0;
  virtual user_manager::User* GetUserByProfile(Profile* profile) const = 0;

  // Enables/disables testing GetUserByProfile() by always returning
  // primary user.
  static void SetAlwaysReturnPrimaryUserForTesting(bool value);

  // DEPRECATED: please set up UserManager and create a Profile tied to a user
  // by its path. You may be interested in to create a testing profile by
  // TestingProfileManager.
  // Associates |profile| with |user|, for GetProfileByUser() testing.
  virtual void SetUserToProfileMappingForTesting(const user_manager::User* user,
                                                 Profile* profile) = 0;

  // Enables/disables testing code path in GetUserByProfile() like
  // always return primary user (when always_return_primary_user_for_testing is
  // set).
  static void SetProfileToUserForTestingEnabled(bool enabled);

 protected:
  // TODO(nkostylev): Create a test API class that will be the only one allowed
  // to access private test methods.
  friend class FakeChromeUserManager;
  friend class ProfileHelperTest;
  friend class ::IndependentOTRProfileManagerTest;

  // If true testing code path is used in GetUserByProfile() even if
  // user_list_for_testing_ list is empty. In that case primary user will always
  // be returned.
  static bool enable_profile_to_user_testing;

  // If true and enable_profile_to_user_testing is true then primary user will
  // always be returned by GetUserByProfile().
  static bool always_return_primary_user_for_testing;
};

}  // namespace ash

#endif  // CHROME_BROWSER_ASH_PROFILES_PROFILE_HELPER_H_