1 // Copyright 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. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SUPERVISED_USER_MANAGER_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SUPERVISED_USER_MANAGER_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "base/callback.h" 12 #include "base/strings/string16.h" 13 #include "chrome/browser/profiles/profile.h" 14 15 class PrefRegistrySimple; 16 17 namespace chromeos { 18 19 class User; 20 21 // Base class for SupervisedUserManagerImpl - provides a mechanism for getting 22 // and setting specific values for supervised users, as well as additional 23 // lookup methods that make sense only for supervised users. 24 class SupervisedUserManager { 25 public: 26 typedef base::Callback<void(const std::string& /* token */)> 27 LoadTokenCallback; 28 29 // Registers user manager preferences. 30 static void RegisterPrefs(PrefRegistrySimple* registry); 31 SupervisedUserManager()32 SupervisedUserManager() {} ~SupervisedUserManager()33 virtual ~SupervisedUserManager() {} 34 35 // Creates supervised user with given |display_name| and |local_user_id| 36 // and persists that to user list. Also links this user identified by 37 // |sync_user_id| to manager with a |manager_id|. 38 // Returns created user, or existing user if there already 39 // was locally managed user with such display name. 40 // TODO(antrim): Refactor into a single struct to have only 1 getter. 41 virtual const User* CreateUserRecord( 42 const std::string& manager_id, 43 const std::string& local_user_id, 44 const std::string& sync_user_id, 45 const base::string16& display_name) = 0; 46 47 // Generates unique user ID for supervised user. 48 virtual std::string GenerateUserId() = 0; 49 50 // Returns the supervised user with the given |display_name| if found in 51 // the persistent list. Returns |NULL| otherwise. 52 virtual const User* FindByDisplayName( 53 const base::string16& display_name) const = 0; 54 55 // Returns the supervised user with the given |sync_id| if found in 56 // the persistent list. Returns |NULL| otherwise. 57 virtual const User* FindBySyncId(const std::string& sync_id) const = 0; 58 59 // Returns sync_user_id for supervised user with |user_id| or empty string if 60 // such user is not found or it doesn't have user_id defined. 61 virtual std::string GetUserSyncId(const std::string& user_id) const = 0; 62 63 // Returns the display name for manager of user |user_id| if it is known 64 // (was previously set by a |SaveUserDisplayName| call). 65 // Otherwise, returns a manager id. 66 virtual base::string16 GetManagerDisplayName( 67 const std::string& user_id) const = 0; 68 69 // Returns the user id for manager of user |user_id| if it is known (user is 70 // actually a managed user). 71 // Otherwise, returns an empty string. 72 virtual std::string GetManagerUserId(const std::string& user_id) const = 0; 73 74 // Returns the display email for manager of user |user_id| if it is known 75 // (user is actually a managed user). 76 // Otherwise, returns an empty string. 77 virtual std::string GetManagerDisplayEmail(const std::string& user_id) 78 const = 0; 79 80 // Create a record about starting supervised user creation transaction. 81 virtual void StartCreationTransaction(const base::string16& display_name) = 0; 82 83 // Add user id to supervised user creation transaction record. 84 virtual void SetCreationTransactionUserId(const std::string& user_id) = 0; 85 86 // Remove locally managed user creation transaction record. 87 virtual void CommitCreationTransaction() = 0; 88 89 // Loads a sync oauth token in background, and passes it to callback. 90 virtual void LoadSupervisedUserToken(Profile* profile, 91 const LoadTokenCallback& callback) = 0; 92 93 // Configures sync service with oauth token. 94 virtual void ConfigureSyncWithToken(Profile* profile, 95 const std::string& token) = 0; 96 97 private: 98 DISALLOW_COPY_AND_ASSIGN(SupervisedUserManager); 99 }; 100 101 } // namespace chromeos 102 103 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SUPERVISED_USER_MANAGER_H_ 104