Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: chrome/browser/chromeos/policy/android_management_client.h

Issue 1892093002: Add AndroidManagementClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed comments. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/chromeos/policy/android_management_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/policy/android_management_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698