Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / components / user_manager / fake_user_manager.h
bloba40eed6e800818d468aff2d7e88e3b4ae1f2f41e
1 // Copyright 2014 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 COMPONENTS_USER_MANAGER_FAKE_USER_MANAGER_H_
6 #define COMPONENTS_USER_MANAGER_FAKE_USER_MANAGER_H_
8 #include <map>
9 #include <string>
11 #include "base/memory/scoped_ptr.h"
12 #include "components/user_manager/user.h"
13 #include "components/user_manager/user_manager_base.h"
15 namespace user_manager {
17 // Fake user manager with a barebones implementation. Users can be added
18 // and set as logged in, and those users can be returned.
19 class USER_MANAGER_EXPORT FakeUserManager : public UserManagerBase {
20 public:
21 FakeUserManager();
22 ~FakeUserManager() override;
24 // Create and add a new user. Created user is not affiliated with the domain,
25 // that owns the device.
26 virtual const user_manager::User* AddUser(const std::string& email);
28 // The same as AddUser() but allows to specify user affiliation with the
29 // domain, that owns the device.
30 virtual const user_manager::User* AddUserWithAffiliation(
31 const std::string& email, bool is_affiliated);
33 // Calculates the user name hash and calls UserLoggedIn to login a user.
34 void LoginUser(const std::string& email);
36 // UserManager overrides.
37 const user_manager::UserList& GetUsers() const override;
38 user_manager::UserList GetUsersAllowedForMultiProfile() const override;
39 const user_manager::UserList& GetLoggedInUsers() const override;
41 // Set the user as logged in.
42 void UserLoggedIn(const std::string& email,
43 const std::string& username_hash,
44 bool browser_restart) override;
46 const user_manager::User* GetActiveUser() const override;
47 user_manager::User* GetActiveUser() override;
48 void SwitchActiveUser(const std::string& email) override;
49 void SaveUserDisplayName(const std::string& username,
50 const base::string16& display_name) override;
52 // Not implemented.
53 void UpdateUserAccountData(const std::string& user_id,
54 const UserAccountData& account_data) override {}
55 void Shutdown() override {}
56 const user_manager::UserList& GetLRULoggedInUsers() const override;
57 user_manager::UserList GetUnlockUsers() const override;
58 const std::string& GetOwnerEmail() const override;
59 void SessionStarted() override {}
60 void RemoveUser(const std::string& email,
61 user_manager::RemoveUserDelegate* delegate) override {}
62 void RemoveUserFromList(const std::string& email) override;
63 bool IsKnownUser(const std::string& email) const override;
64 const user_manager::User* FindUser(const std::string& email) const override;
65 user_manager::User* FindUserAndModify(const std::string& email) override;
66 const user_manager::User* GetLoggedInUser() const override;
67 user_manager::User* GetLoggedInUser() override;
68 const user_manager::User* GetPrimaryUser() const override;
69 void SaveUserOAuthStatus(
70 const std::string& username,
71 user_manager::User::OAuthTokenStatus oauth_token_status) override {}
72 void SaveForceOnlineSignin(const std::string& user_id,
73 bool force_online_signin) override {}
74 base::string16 GetUserDisplayName(const std::string& username) const override;
75 void SaveUserDisplayEmail(const std::string& username,
76 const std::string& display_email) override {}
77 std::string GetUserDisplayEmail(const std::string& username) const override;
78 bool IsCurrentUserOwner() const override;
79 bool IsCurrentUserNew() const override;
80 bool IsCurrentUserNonCryptohomeDataEphemeral() const override;
81 bool CanCurrentUserLock() const override;
82 bool IsUserLoggedIn() const override;
83 bool IsLoggedInAsUserWithGaiaAccount() const override;
84 bool IsLoggedInAsPublicAccount() const override;
85 bool IsLoggedInAsGuest() const override;
86 bool IsLoggedInAsSupervisedUser() const override;
87 bool IsLoggedInAsKioskApp() const override;
88 bool IsLoggedInAsStub() const override;
89 bool IsSessionStarted() const override;
90 bool IsUserNonCryptohomeDataEphemeral(
91 const std::string& email) const override;
92 void AddObserver(Observer* obs) override {}
93 void RemoveObserver(Observer* obs) override {}
94 void AddSessionStateObserver(UserSessionStateObserver* obs) override {}
95 void RemoveSessionStateObserver(UserSessionStateObserver* obs) override {}
96 void NotifyLocalStateChanged() override {}
97 bool AreSupervisedUsersAllowed() const override;
99 // UserManagerBase overrides:
100 bool AreEphemeralUsersEnabled() const override;
101 const std::string& GetApplicationLocale() const override;
102 PrefService* GetLocalState() const override;
103 void HandleUserOAuthTokenStatusChange(
104 const std::string& user_id,
105 user_manager::User::OAuthTokenStatus status) const override {}
106 bool IsEnterpriseManaged() const override;
107 void LoadPublicAccounts(std::set<std::string>* public_sessions_set) override {
109 void PerformPreUserListLoadingActions() override {}
110 void PerformPostUserListLoadingActions() override {}
111 void PerformPostUserLoggedInActions(bool browser_restart) override {}
112 bool IsDemoApp(const std::string& user_id) const override;
113 bool IsKioskApp(const std::string& user_id) const override;
114 bool IsPublicAccountMarkedForRemoval(
115 const std::string& user_id) const override;
116 void DemoAccountLoggedIn() override {}
117 void KioskAppLoggedIn(const std::string& app_id) override {}
118 void PublicAccountUserLoggedIn(user_manager::User* user) override {}
119 void SupervisedUserLoggedIn(const std::string& user_id) override {}
120 void OnUserRemoved(const std::string& user_id) override {}
122 protected:
123 user_manager::User* primary_user_;
125 // If set this is the active user. If empty, the first created user is the
126 // active user.
127 std::string active_user_id_;
129 private:
130 // We use this internal function for const-correctness.
131 user_manager::User* GetActiveUserInternal() const;
133 // stub, always empty string.
134 std::string owner_email_;
136 DISALLOW_COPY_AND_ASSIGN(FakeUserManager);
139 } // namespace user_manager
141 #endif // COMPONENTS_USER_MANAGER_FAKE_USER_MANAGER_H_