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