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

Side by Side Diff: chrome/browser/chromeos/arc/policy/arc_android_management_checker.h

Issue 2446563002: Refactor ArcAndroidManagementChecker. (Closed)
Patch Set: Address comments. Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_CHROMEOS_ARC_POLICY_ARC_ANDROID_MANAGEMENT_CHECKER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_POLICY_ARC_ANDROID_MANAGEMENT_CHECKER_H_
6 #define CHROME_BROWSER_CHROMEOS_ARC_POLICY_ARC_ANDROID_MANAGEMENT_CHECKER_H_ 6 #define CHROME_BROWSER_CHROMEOS_ARC_POLICY_ARC_ANDROID_MANAGEMENT_CHECKER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h"
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/chromeos/policy/android_management_client.h" 13 #include "chrome/browser/chromeos/policy/android_management_client.h"
13 #include "google_apis/gaia/oauth2_token_service.h" 14 #include "google_apis/gaia/oauth2_token_service.h"
14 15
16 class Profile;
15 class ProfileOAuth2TokenService; 17 class ProfileOAuth2TokenService;
16 18
17 namespace arc { 19 namespace arc {
18 20
19 class ArcAndroidManagementCheckerDelegate;
20
21 class ArcAndroidManagementChecker : public OAuth2TokenService::Observer { 21 class ArcAndroidManagementChecker : public OAuth2TokenService::Observer {
22 public: 22 public:
23 ArcAndroidManagementChecker(ArcAndroidManagementCheckerDelegate* delegate, 23 ArcAndroidManagementChecker(Profile* profile,
24 ProfileOAuth2TokenService* token_service, 24 ProfileOAuth2TokenService* token_service,
25 const std::string& account_id, 25 const std::string& account_id,
26 bool background_mode); 26 bool retry_on_error);
27 ~ArcAndroidManagementChecker() override; 27 ~ArcAndroidManagementChecker() override;
28 28
29 static void StartClient(); 29 static void StartClient();
30 30
31 // Starts the check. On completion |callback| will be invoked with the
32 // |result|. This must not be called if there is inflight check.
33 // If the instance is destructed while it has inflight check, then the
34 // check will be cancelled and |callback| will not be called.
35 using CheckCallback =
36 base::Callback<void(policy::AndroidManagementClient::Result result)>;
37 void StartCheck(const CheckCallback& callback);
38
39 private:
40 void StartCheckInternal();
41 void OnAndroidManagementChecked(
42 policy::AndroidManagementClient::Result result);
43 void ScheduleRetry();
44
45 // Ensures the refresh token is loaded in the |token_service|.
46 void EnsureRefreshTokenLoaded();
47
31 // OAuth2TokenService::Observer: 48 // OAuth2TokenService::Observer:
32 void OnRefreshTokenAvailable(const std::string& account_id) override; 49 void OnRefreshTokenAvailable(const std::string& account_id) override;
33 void OnRefreshTokensLoaded() override; 50 void OnRefreshTokensLoaded() override;
34 51
35 bool background_mode() const { return background_mode_; }
36
37 private:
38 void StartCheck();
39 void ScheduleCheck();
40 void DispatchResult(policy::AndroidManagementClient::Result result);
41 void OnAndroidManagementChecked(
42 policy::AndroidManagementClient::Result result);
43
44 // Unowned pointers. 52 // Unowned pointers.
45 ArcAndroidManagementCheckerDelegate* const delegate_; 53 Profile* profile_;
46 ProfileOAuth2TokenService* const token_service_; 54 ProfileOAuth2TokenService* const token_service_;
47 55
48 const std::string account_id_; 56 const std::string account_id_;
49 57
50 // In background mode errors are ignored and retry is attempted. There is no 58 // If true, on error, instead of reporting the error to the caller, schedule
51 // retry in foreground mode and result is passed to delegate directly. 59 // the retry with delay.
52 bool background_mode_; 60 const bool retry_on_error_;
53 61
54 // Keeps current retry time for background mode. 62 // Keeps current retry time.
55 int retry_time_ms_; 63 int retry_time_ms_;
56 64
57 policy::AndroidManagementClient android_management_client_; 65 policy::AndroidManagementClient android_management_client_;
58 66
67 // The callback for the inflight operation.
68 CheckCallback callback_;
69
59 base::WeakPtrFactory<ArcAndroidManagementChecker> weak_ptr_factory_; 70 base::WeakPtrFactory<ArcAndroidManagementChecker> weak_ptr_factory_;
60 71
61 DISALLOW_COPY_AND_ASSIGN(ArcAndroidManagementChecker); 72 DISALLOW_COPY_AND_ASSIGN(ArcAndroidManagementChecker);
62 }; 73 };
63 74
64 } // namespace arc 75 } // namespace arc
65 76
66 #endif // CHROME_BROWSER_CHROMEOS_ARC_POLICY_ARC_ANDROID_MANAGEMENT_CHECKER_H_ 77 #endif // CHROME_BROWSER_CHROMEOS_ARC_POLICY_ARC_ANDROID_MANAGEMENT_CHECKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698