| OLD | NEW |
| (Empty) |
| 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_MANAGED_MODE_MANAGED_USER_REGISTRATION_UTILITY_H_ | |
| 6 #define CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_REGISTRATION_UTILITY_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/callback.h" | |
| 13 #include "base/gtest_prod_util.h" | |
| 14 #include "base/memory/weak_ptr.h" | |
| 15 #include "base/prefs/pref_change_registrar.h" | |
| 16 #include "base/strings/string16.h" | |
| 17 #include "base/values.h" | |
| 18 #include "chrome/browser/managed_mode/managed_user_sync_service.h" | |
| 19 #include "chrome/browser/managed_mode/managed_user_sync_service_observer.h" | |
| 20 #include "chrome/browser/managed_mode/managed_users.h" | |
| 21 #include "components/keyed_service/core/keyed_service.h" | |
| 22 | |
| 23 class GoogleServiceAuthError; | |
| 24 class ManagedUserRefreshTokenFetcher; | |
| 25 class ManagedUserRegistrationUtilityTest; | |
| 26 class ManagedUserSharedSettingsService; | |
| 27 class PrefService; | |
| 28 class Profile; | |
| 29 | |
| 30 namespace browser_sync { | |
| 31 class DeviceInfo; | |
| 32 } | |
| 33 | |
| 34 // Structure to store registration information. | |
| 35 struct ManagedUserRegistrationInfo { | |
| 36 ManagedUserRegistrationInfo(const base::string16& name, int avatar_index); | |
| 37 ~ManagedUserRegistrationInfo(); | |
| 38 int avatar_index; | |
| 39 base::string16 name; | |
| 40 std::string master_key; | |
| 41 std::string password_signature_key; | |
| 42 std::string password_encryption_key; | |
| 43 base::DictionaryValue password_data; | |
| 44 }; | |
| 45 | |
| 46 // Holds the state necessary for registering a new managed user with the | |
| 47 // management server and associating it with its custodian. Each instance | |
| 48 // of this class handles registering a single managed user and should not | |
| 49 // be used afterwards. | |
| 50 class ManagedUserRegistrationUtility { | |
| 51 public: | |
| 52 // Callback for Register() below. If registration is successful, |token| will | |
| 53 // contain an OAuth2 refresh token for the newly registered managed user, | |
| 54 // otherwise |token| will be empty and |error| will contain the authentication | |
| 55 // error for the custodian. | |
| 56 typedef base::Callback<void(const GoogleServiceAuthError& /* error */, | |
| 57 const std::string& /* token */)> | |
| 58 RegistrationCallback; | |
| 59 | |
| 60 virtual ~ManagedUserRegistrationUtility() {} | |
| 61 | |
| 62 // Creates ManagedUserRegistrationUtility for a given |profile|. | |
| 63 static scoped_ptr<ManagedUserRegistrationUtility> Create(Profile* profile); | |
| 64 | |
| 65 static std::string GenerateNewManagedUserId(); | |
| 66 | |
| 67 // Registers a new managed user with the server. |managed_user_id| is a new | |
| 68 // unique ID for the new managed user. If its value is the same as that of | |
| 69 // of one of the existing managed users, then the same user will be created | |
| 70 // on this machine (and if he has no avatar in sync, his avatar will | |
| 71 // be updated). |info| contains necessary information like | |
| 72 // the display name of the user and his avatar. |callback| is called | |
| 73 // with the result of the registration. We use the info here and not the | |
| 74 // profile, because on Chrome OS the profile of the managed user does not | |
| 75 // yet exist. | |
| 76 virtual void Register(const std::string& managed_user_id, | |
| 77 const ManagedUserRegistrationInfo& info, | |
| 78 const RegistrationCallback& callback) = 0; | |
| 79 | |
| 80 protected: | |
| 81 ManagedUserRegistrationUtility() {} | |
| 82 | |
| 83 private: | |
| 84 friend class ScopedTestingManagedUserRegistrationUtility; | |
| 85 friend class ManagedUserRegistrationUtilityTest; | |
| 86 | |
| 87 // Creates implementation with explicit dependencies, can be used for testing. | |
| 88 static ManagedUserRegistrationUtility* CreateImpl( | |
| 89 PrefService* prefs, | |
| 90 scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher, | |
| 91 ManagedUserSyncService* service, | |
| 92 ManagedUserSharedSettingsService* shared_settings_service); | |
| 93 | |
| 94 // Set the instance of ManagedUserRegistrationUtility that will be returned | |
| 95 // by next Create() call. Takes ownership of the |utility|. | |
| 96 static void SetUtilityForTests(ManagedUserRegistrationUtility* utility); | |
| 97 }; | |
| 98 | |
| 99 // Class that sets the instance of ManagedUserRegistrationUtility that will be | |
| 100 // returned by next Create() call, and correctly destroys it if Create() was | |
| 101 // not called. | |
| 102 class ScopedTestingManagedUserRegistrationUtility { | |
| 103 public: | |
| 104 // Delegates ownership of the |instance| to ManagedUserRegistrationUtility. | |
| 105 ScopedTestingManagedUserRegistrationUtility( | |
| 106 ManagedUserRegistrationUtility* instance); | |
| 107 | |
| 108 ~ScopedTestingManagedUserRegistrationUtility(); | |
| 109 }; | |
| 110 | |
| 111 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_REGISTRATION_UTILITY_H_ | |
| OLD | NEW |