| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_SUPERVISED_USER_LEGACY_SUPERVISED_USER_REGISTRATION_UTILI
TY_H_ | 5 #ifndef CHROME_BROWSER_SUPERVISED_USER_LEGACY_SUPERVISED_USER_REGISTRATION_UTILI
TY_H_ |
| 6 #define CHROME_BROWSER_SUPERVISED_USER_LEGACY_SUPERVISED_USER_REGISTRATION_UTILI
TY_H_ | 6 #define CHROME_BROWSER_SUPERVISED_USER_LEGACY_SUPERVISED_USER_REGISTRATION_UTILI
TY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 // contain an OAuth2 refresh token for the newly registered supervised user, | 51 // contain an OAuth2 refresh token for the newly registered supervised user, |
| 52 // otherwise |token| will be empty and |error| will contain the authentication | 52 // otherwise |token| will be empty and |error| will contain the authentication |
| 53 // error for the custodian. | 53 // error for the custodian. |
| 54 typedef base::Callback<void(const GoogleServiceAuthError& /* error */, | 54 typedef base::Callback<void(const GoogleServiceAuthError& /* error */, |
| 55 const std::string& /* token */)> | 55 const std::string& /* token */)> |
| 56 RegistrationCallback; | 56 RegistrationCallback; |
| 57 | 57 |
| 58 virtual ~SupervisedUserRegistrationUtility() {} | 58 virtual ~SupervisedUserRegistrationUtility() {} |
| 59 | 59 |
| 60 // Creates SupervisedUserRegistrationUtility for a given |profile|. | 60 // Creates SupervisedUserRegistrationUtility for a given |profile|. |
| 61 static scoped_ptr<SupervisedUserRegistrationUtility> Create(Profile* profile); | 61 static std::unique_ptr<SupervisedUserRegistrationUtility> Create( |
| 62 Profile* profile); |
| 62 | 63 |
| 63 static std::string GenerateNewSupervisedUserId(); | 64 static std::string GenerateNewSupervisedUserId(); |
| 64 | 65 |
| 65 // Registers a new supervised user with the server. |supervised_user_id| is a | 66 // Registers a new supervised user with the server. |supervised_user_id| is a |
| 66 // new unique ID for the new supervised user. If its value is the same as that | 67 // new unique ID for the new supervised user. If its value is the same as that |
| 67 // of one of the existing supervised users, then the same user will be created | 68 // of one of the existing supervised users, then the same user will be created |
| 68 // on this machine (and if he has no avatar in sync, his avatar will be | 69 // on this machine (and if he has no avatar in sync, his avatar will be |
| 69 // updated). |info| contains necessary information like the display name of | 70 // updated). |info| contains necessary information like the display name of |
| 70 // the user and his avatar. |callback| is called with the result of the | 71 // the user and his avatar. |callback| is called with the result of the |
| 71 // registration. We use the info here and not the profile, because on Chrome | 72 // registration. We use the info here and not the profile, because on Chrome |
| 72 // OS the profile of the supervised user does not yet exist. | 73 // OS the profile of the supervised user does not yet exist. |
| 73 virtual void Register(const std::string& supervised_user_id, | 74 virtual void Register(const std::string& supervised_user_id, |
| 74 const SupervisedUserRegistrationInfo& info, | 75 const SupervisedUserRegistrationInfo& info, |
| 75 const RegistrationCallback& callback) = 0; | 76 const RegistrationCallback& callback) = 0; |
| 76 | 77 |
| 77 protected: | 78 protected: |
| 78 SupervisedUserRegistrationUtility() {} | 79 SupervisedUserRegistrationUtility() {} |
| 79 | 80 |
| 80 private: | 81 private: |
| 81 friend class ScopedTestingSupervisedUserRegistrationUtility; | 82 friend class ScopedTestingSupervisedUserRegistrationUtility; |
| 82 friend class SupervisedUserRegistrationUtilityTest; | 83 friend class SupervisedUserRegistrationUtilityTest; |
| 83 | 84 |
| 84 // Creates implementation with explicit dependencies, can be used for testing. | 85 // Creates implementation with explicit dependencies, can be used for testing. |
| 85 static SupervisedUserRegistrationUtility* CreateImpl( | 86 static SupervisedUserRegistrationUtility* CreateImpl( |
| 86 PrefService* prefs, | 87 PrefService* prefs, |
| 87 scoped_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher, | 88 std::unique_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher, |
| 88 SupervisedUserSyncService* service, | 89 SupervisedUserSyncService* service, |
| 89 SupervisedUserSharedSettingsService* shared_settings_service); | 90 SupervisedUserSharedSettingsService* shared_settings_service); |
| 90 | 91 |
| 91 // Set the instance of SupervisedUserRegistrationUtility that will be returned | 92 // Set the instance of SupervisedUserRegistrationUtility that will be returned |
| 92 // by next Create() call. Takes ownership of the |utility|. | 93 // by next Create() call. Takes ownership of the |utility|. |
| 93 static void SetUtilityForTests(SupervisedUserRegistrationUtility* utility); | 94 static void SetUtilityForTests(SupervisedUserRegistrationUtility* utility); |
| 94 }; | 95 }; |
| 95 | 96 |
| 96 // Class that sets the instance of SupervisedUserRegistrationUtility that will | 97 // Class that sets the instance of SupervisedUserRegistrationUtility that will |
| 97 // be returned by next Create() call, and correctly destroys it if Create() was | 98 // be returned by next Create() call, and correctly destroys it if Create() was |
| 98 // not called. | 99 // not called. |
| 99 class ScopedTestingSupervisedUserRegistrationUtility { | 100 class ScopedTestingSupervisedUserRegistrationUtility { |
| 100 public: | 101 public: |
| 101 // Delegates ownership of the |instance| to SupervisedUserRegistrationUtility. | 102 // Delegates ownership of the |instance| to SupervisedUserRegistrationUtility. |
| 102 ScopedTestingSupervisedUserRegistrationUtility( | 103 ScopedTestingSupervisedUserRegistrationUtility( |
| 103 SupervisedUserRegistrationUtility* instance); | 104 SupervisedUserRegistrationUtility* instance); |
| 104 | 105 |
| 105 ~ScopedTestingSupervisedUserRegistrationUtility(); | 106 ~ScopedTestingSupervisedUserRegistrationUtility(); |
| 106 }; | 107 }; |
| 107 | 108 |
| 108 #endif // CHROME_BROWSER_SUPERVISED_USER_LEGACY_SUPERVISED_USER_REGISTRATION_UT
ILITY_H_ | 109 #endif // CHROME_BROWSER_SUPERVISED_USER_LEGACY_SUPERVISED_USER_REGISTRATION_UT
ILITY_H_ |
| OLD | NEW |