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

Unified Diff: chrome/browser/signin/force_signin_verifier.h

Issue 2802373002: Add ForceSigninVerifier. (Closed)
Patch Set: rogers' comments Created 3 years, 8 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/signin/force_signin_verifier.h
diff --git a/chrome/browser/signin/force_signin_verifier.h b/chrome/browser/signin/force_signin_verifier.h
new file mode 100644
index 0000000000000000000000000000000000000000..03548c03eba884fdc7343e9671601586617852a0
--- /dev/null
+++ b/chrome/browser/signin/force_signin_verifier.h
@@ -0,0 +1,84 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SIGNIN_FORCE_SIGNIN_VERIFIER_H_
+#define CHROME_BROWSER_SIGNIN_FORCE_SIGNIN_VERIFIER_H_
+
+#include <memory>
+#include <string>
+
+#include "base/macros.h"
+#include "base/time/time.h"
+#include "base/timer/timer.h"
+#include "google_apis/gaia/oauth2_token_service.h"
+#include "net/base/backoff_entry.h"
+#include "net/base/network_change_notifier.h"
+
+class Profile;
+class SigninManager;
+
+// ForceSigninVerifier will verify profile's auth token when profile is loaded
+// into memory by the first time via gaia server. It will retry on any transient
+// error.
+class ForceSigninVerifier
+ : public OAuth2TokenService::Consumer,
+ public net::NetworkChangeNotifier::NetworkChangeObserver {
+ public:
+ explicit ForceSigninVerifier(Profile* profile);
+ ~ForceSigninVerifier() override;
+
+ // OAuth2TokenService::Consumer implementation
+ void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
+ const std::string& access_token,
+ const base::Time& expiration_time) override;
+ void OnGetTokenFailure(const OAuth2TokenService::Request* request,
+ const GoogleServiceAuthError& error) override;
+
+ // net::NetworkChangeNotifier::NetworkChangeObserver
+ void OnNetworkChanged(
+ net::NetworkChangeNotifier::ConnectionType type) override;
+
+ // Cancel any pending or ongoing verification.
+ void Cancel();
+
+ // Return the value of |has_token_verified_|.
+ bool HasTokenBeenVerified();
+
+ protected:
+ // Send the token verification request. The request will be sent only if
+ // - The token has never been verified before.
+ // - There is no on going verification.
+ // - There is network connection.
+ // - The profile has signed in.
+ //
+ void SendRequest();
+
+ virtual bool ShouldSendRequest();
+
+ // Show the warning dialog before signing out user and closing assoicated
+ // browser window.
+ virtual void ShowDialog();
+
+ OAuth2TokenService::Request* GetRequestForTesting();
+ net::BackoffEntry* GetBackoffEntryForTesting();
+ base::OneShotTimer* GetOneShotTimerForTesting();
+
+ private:
+ std::unique_ptr<OAuth2TokenService::Request> access_token_request_;
+
+ // Indicates whether the verification is finished successfully or with a
+ // persistent error.
+ bool has_token_verified_;
+ net::BackoffEntry backoff_entry_;
+ base::OneShotTimer backoff_request_timer_;
+
+ OAuth2TokenService* oauth2_token_service_;
+ SigninManager* signin_manager_;
+
+ base::Time token_request_time_;
+
+ DISALLOW_COPY_AND_ASSIGN(ForceSigninVerifier);
+};
+
+#endif // CHROME_BROWSER_SIGNIN_FORCE_SIGNIN_VERIFIER_H_
« no previous file with comments | « chrome/browser/signin/chrome_signin_client_unittest.cc ('k') | chrome/browser/signin/force_signin_verifier.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698