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

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

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

Powered by Google App Engine
This is Rietveld 408576698