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

Unified Diff: chrome/browser/chromeos/arc/policy/arc_android_management_checker.h

Issue 2446563002: Refactor ArcAndroidManagementChecker. (Closed)
Patch Set: rebase Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/arc/policy/arc_android_management_checker.h
diff --git a/chrome/browser/chromeos/arc/policy/arc_android_management_checker.h b/chrome/browser/chromeos/arc/policy/arc_android_management_checker.h
index dc50f834d53f73b0c456dff189a8f0725a413428..54b0de6b5a21f707d1ef92f91c9e9224039cfe85 100644
--- a/chrome/browser/chromeos/arc/policy/arc_android_management_checker.h
+++ b/chrome/browser/chromeos/arc/policy/arc_android_management_checker.h
@@ -7,56 +7,67 @@
#include <string>
+#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "chrome/browser/chromeos/policy/android_management_client.h"
#include "google_apis/gaia/oauth2_token_service.h"
+class Profile;
class ProfileOAuth2TokenService;
namespace arc {
-class ArcAndroidManagementCheckerDelegate;
-
class ArcAndroidManagementChecker : public OAuth2TokenService::Observer {
public:
- ArcAndroidManagementChecker(ArcAndroidManagementCheckerDelegate* delegate,
+ ArcAndroidManagementChecker(Profile* profile,
ProfileOAuth2TokenService* token_service,
const std::string& account_id,
- bool background_mode);
+ bool retry_on_error);
~ArcAndroidManagementChecker() override;
static void StartClient();
- // OAuth2TokenService::Observer:
- void OnRefreshTokenAvailable(const std::string& account_id) override;
- void OnRefreshTokensLoaded() override;
-
- bool background_mode() const { return background_mode_; }
+ // Starts the check. On completion |callback| will be invoked with the
+ // |result|. This must not be called if there is inflight check.
+ // If the instance is destructed while it has inflight check, then the
+ // check will be cancelled and |callback| will not be called.
+ using CheckCallback =
+ base::Callback<void(policy::AndroidManagementClient::Result result)>;
+ void StartCheck(const CheckCallback& callback);
private:
- void StartCheck();
- void ScheduleCheck();
- void DispatchResult(policy::AndroidManagementClient::Result result);
+ void StartCheckInternal();
void OnAndroidManagementChecked(
policy::AndroidManagementClient::Result result);
+ void ScheduleRetry();
+
+ // Ensures the refresh token is loaded in the |token_service|.
+ void EnsureRefreshTokenLoaded();
+
+ // OAuth2TokenService::Observer:
+ void OnRefreshTokenAvailable(const std::string& account_id) override;
+ void OnRefreshTokensLoaded() override;
// Unowned pointers.
- ArcAndroidManagementCheckerDelegate* const delegate_;
+ Profile* profile_;
ProfileOAuth2TokenService* const token_service_;
const std::string account_id_;
- // In background mode errors are ignored and retry is attempted. There is no
- // retry in foreground mode and result is passed to delegate directly.
- bool background_mode_;
+ // If true, on error, instead of reporting the error to the caller, schedule
+ // the retry with delay.
+ const bool retry_on_error_;
// Keeps current retry delay.
base::TimeDelta retry_delay_;
policy::AndroidManagementClient android_management_client_;
+ // The callback for the inflight operation.
+ CheckCallback callback_;
+
base::WeakPtrFactory<ArcAndroidManagementChecker> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ArcAndroidManagementChecker);
« 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