Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016 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_POLICY_ANDROID_MANAGEMENT_CLIENT_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_POLICY_ANDROID_MANAGEMENT_CLIENT_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "base/memory/weak_ptr.h" | |
| 15 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | |
| 16 #include "google_apis/gaia/oauth2_token_service.h" | |
| 17 #include "net/url_request/url_request_context_getter.h" | |
| 18 | |
| 19 namespace enterprise_management { | |
| 20 class DeviceManagementResponse; | |
| 21 } | |
| 22 | |
| 23 namespace policy { | |
| 24 | |
| 25 class DeviceManagementRequestJob; | |
| 26 class DeviceManagementService; | |
| 27 | |
| 28 // Interacts with the device management service and determines whether Android | |
| 29 // management is enabled for the user or not. Uses the OAuth2TokenService to | |
| 30 // acquire access tokens for the device management. | |
| 31 class AndroidManagementClient : public OAuth2TokenService::Consumer { | |
| 32 public: | |
| 33 // Indicates result of the android management check. | |
| 34 enum Result { | |
| 35 RESULT_MANAGED, // Android management is enabled. | |
| 36 RESULT_UNMANAGED, // Android management is disabled. | |
| 37 RESULT_ERROR, // Received a error. | |
| 38 }; | |
| 39 | |
| 40 // A callback which receives Result status of an operation. | |
| 41 using StatusCallback = base::Callback<void(Result)>; | |
| 42 | |
| 43 AndroidManagementClient( | |
| 44 DeviceManagementService* service, | |
| 45 scoped_refptr<net::URLRequestContextGetter> request_context, | |
| 46 const std::string& account_id, | |
| 47 OAuth2TokenService* token_service); | |
| 48 ~AndroidManagementClient() override; | |
| 49 | |
| 50 // Sends a check Android management request to the device management service. | |
| 51 void StartCheckAndroidManagement(const StatusCallback& callback); | |
| 52 | |
| 53 // |access_token| is owned by caller and must exist before | |
| 54 // StartCheckAndroidManagement is called for testing. | |
| 55 static void SetAccessTokenForTesting(const char* access_token); | |
| 56 | |
| 57 private: | |
| 58 // OAuth2TokenService::Consumer: | |
| 59 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | |
| 60 const std::string& access_token, | |
| 61 const base::Time& expiration_time) override; | |
| 62 void OnGetTokenFailure(const OAuth2TokenService::Request* request, | |
| 63 const GoogleServiceAuthError& error) override; | |
| 64 | |
| 65 // Requests an access token. | |
| 66 void RequestAccessToken(); | |
| 67 | |
| 68 void CheckAndroidManagement(const std::string& access_token); | |
|
Thiemo Nagel
2016/04/28 13:26:59
Please add comment.
Polina Bondarenko
2016/04/28 16:18:40
Done.
| |
| 69 | |
| 70 // Callback for check Android management requests. | |
| 71 void OnAndroidManagementChecked( | |
| 72 DeviceManagementStatus status, | |
| 73 int net_error, | |
| 74 const enterprise_management::DeviceManagementResponse& response); | |
| 75 | |
| 76 // Used to communicate with the device management service. | |
| 77 DeviceManagementService* service_; | |
|
Thiemo Nagel
2016/04/28 13:26:59
I think that could be made a const pointer.
I'd p
Polina Bondarenko
2016/04/28 16:18:40
Done.
| |
| 78 scoped_refptr<net::URLRequestContextGetter> request_context_; | |
| 79 std::unique_ptr<DeviceManagementRequestJob> request_job_; | |
| 80 | |
| 81 // The account ID that will be used for the access token fetch. | |
| 82 const std::string account_id_; | |
| 83 // The token service used to retrieve the access token. | |
| 84 OAuth2TokenService* const token_service_; | |
| 85 // The OAuth request to receive the access token. | |
| 86 std::unique_ptr<OAuth2TokenService::Request> token_request_; | |
| 87 | |
| 88 StatusCallback callback_; | |
| 89 | |
| 90 base::WeakPtrFactory<AndroidManagementClient> weak_ptr_factory_; | |
| 91 | |
| 92 DISALLOW_COPY_AND_ASSIGN(AndroidManagementClient); | |
| 93 }; | |
| 94 | |
| 95 } // namespace policy | |
| 96 | |
| 97 #endif // CHROME_BROWSER_CHROMEOS_POLICY_ANDROID_MANAGEMENT_CLIENT_H_ | |
| OLD | NEW |