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 // Starts sending of check Android management request to DM server, issues |
| 51 // access token if neccessary. |callback| is called on check Android |
| 52 // management completion. |
| 53 void StartCheckAndroidManagement(const StatusCallback& callback); |
| 54 |
| 55 // |access_token| is owned by caller and must exist before |
| 56 // StartCheckAndroidManagement is called for testing. |
| 57 static void SetAccessTokenForTesting(const char* access_token); |
| 58 |
| 59 private: |
| 60 // OAuth2TokenService::Consumer: |
| 61 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 62 const std::string& access_token, |
| 63 const base::Time& expiration_time) override; |
| 64 void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 65 const GoogleServiceAuthError& error) override; |
| 66 |
| 67 // Requests an access token. |
| 68 void RequestAccessToken(); |
| 69 |
| 70 // Sends a CheckAndroidManagementRequest to DM server. |
| 71 void CheckAndroidManagement(const std::string& access_token); |
| 72 |
| 73 // Callback for check Android management requests. |
| 74 void OnAndroidManagementChecked( |
| 75 DeviceManagementStatus status, |
| 76 int net_error, |
| 77 const enterprise_management::DeviceManagementResponse& response); |
| 78 |
| 79 // Used to communicate with the device management service. |
| 80 DeviceManagementService* const device_management_service_; |
| 81 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 82 std::unique_ptr<DeviceManagementRequestJob> request_job_; |
| 83 |
| 84 // The account ID that will be used for the access token fetch. |
| 85 const std::string account_id_; |
| 86 // The token service used to retrieve the access token. |
| 87 OAuth2TokenService* const token_service_; |
| 88 // The OAuth request to receive the access token. |
| 89 std::unique_ptr<OAuth2TokenService::Request> token_request_; |
| 90 |
| 91 StatusCallback callback_; |
| 92 |
| 93 base::WeakPtrFactory<AndroidManagementClient> weak_ptr_factory_; |
| 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(AndroidManagementClient); |
| 96 }; |
| 97 |
| 98 } // namespace policy |
| 99 |
| 100 #endif // CHROME_BROWSER_CHROMEOS_POLICY_ANDROID_MANAGEMENT_CLIENT_H_ |
OLD | NEW |