Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_LOGIN_AUTH_ONLINE_ATTEMPT_H_ | 5 #ifndef CHROMEOS_LOGIN_AUTH_ONLINE_ATTEMPT_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_ONLINE_ATTEMPT_H_ | 6 #define CHROMEOS_LOGIN_AUTH_ONLINE_ATTEMPT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "chromeos/chromeos_export.h" | |
| 15 #include "chromeos/login/auth/auth_status_consumer.h" | 16 #include "chromeos/login/auth/auth_status_consumer.h" |
| 16 #include "google_apis/gaia/gaia_auth_consumer.h" | 17 #include "google_apis/gaia/gaia_auth_consumer.h" |
| 17 #include "google_apis/gaia/google_service_auth_error.h" | 18 #include "google_apis/gaia/google_service_auth_error.h" |
| 18 | 19 |
| 19 class GaiaAuthFetcher; | 20 class GaiaAuthFetcher; |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
|
Nikita (slow)
2014/07/24 15:25:59
not needed
Denis Kuznetsov (DE-MUC)
2014/07/24 15:48:52
Done.
| |
| 22 class BrowserContext; | 23 class BrowserContext; |
| 23 } | 24 } |
| 24 | 25 |
| 26 namespace net { | |
| 27 class URLRequestContextGetter; | |
| 28 } | |
| 29 | |
| 25 namespace chromeos { | 30 namespace chromeos { |
| 26 class AuthAttemptState; | 31 class AuthAttemptState; |
| 27 class AuthAttemptStateResolver; | 32 class AuthAttemptStateResolver; |
| 28 | 33 |
| 29 class OnlineAttempt | 34 class CHROMEOS_EXPORT OnlineAttempt : public GaiaAuthConsumer { |
| 30 : public GaiaAuthConsumer { | |
| 31 public: | 35 public: |
| 32 OnlineAttempt(AuthAttemptState* current_attempt, | 36 OnlineAttempt(AuthAttemptState* current_attempt, |
| 33 AuthAttemptStateResolver* callback); | 37 AuthAttemptStateResolver* callback); |
| 34 virtual ~OnlineAttempt(); | 38 virtual ~OnlineAttempt(); |
| 35 | 39 |
| 36 // Initiate the online login attempt either through client or auth login. | 40 // Initiate the online login attempt either through client or auth login. |
| 37 // Status will be recorded in |current_attempt|, and resolver_->Resolve() will | 41 // Status will be recorded in |current_attempt|, and resolver_->Resolve() will |
| 38 // be called on the IO thread when useful state is available. | 42 // be called on the IO thread when useful state is available. |
| 39 // Must be called on the UI thread. | 43 // Must be called on the UI thread. |
| 40 void Initiate(content::BrowserContext* auth_context); | 44 void Initiate(net::URLRequestContextGetter* request_context); |
| 41 | 45 |
| 42 // GaiaAuthConsumer overrides. Callbacks from GaiaAuthFetcher | 46 // GaiaAuthConsumer overrides. Callbacks from GaiaAuthFetcher |
| 43 virtual void OnClientLoginFailure( | 47 virtual void OnClientLoginFailure( |
| 44 const GoogleServiceAuthError& error) OVERRIDE; | 48 const GoogleServiceAuthError& error) OVERRIDE; |
| 45 virtual void OnClientLoginSuccess( | 49 virtual void OnClientLoginSuccess( |
| 46 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; | 50 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; |
| 47 | 51 |
| 48 private: | 52 private: |
| 49 FRIEND_TEST_ALL_PREFIXES(OnlineAttemptTest, LoginSuccess); | 53 FRIEND_TEST_ALL_PREFIXES(OnlineAttemptTest, LoginSuccess); |
| 50 FRIEND_TEST_ALL_PREFIXES(OnlineAttemptTest, TwoFactorSuccess); | 54 FRIEND_TEST_ALL_PREFIXES(OnlineAttemptTest, TwoFactorSuccess); |
| 51 | 55 |
| 52 // Milliseconds until we timeout our attempt to hit ClientLogin. | 56 // Milliseconds until we timeout our attempt to hit ClientLogin. |
| 53 static const int kClientLoginTimeoutMs; | 57 static const int kClientLoginTimeoutMs; |
| 54 | 58 |
| 55 void TryClientLogin(); | 59 void TryClientLogin(); |
| 56 void CancelClientLogin(); | 60 void CancelClientLogin(); |
| 57 | 61 |
| 58 void TriggerResolve(const AuthFailure& outcome); | 62 void TriggerResolve(const AuthFailure& outcome); |
| 59 | 63 |
| 60 bool HasPendingFetch(); | 64 bool HasPendingFetch(); |
| 61 void CancelRequest(); | 65 void CancelRequest(); |
| 62 | 66 |
| 67 scoped_refptr<base::MessageLoopProxy> message_loop_; | |
| 68 | |
| 63 AuthAttemptState* const attempt_; | 69 AuthAttemptState* const attempt_; |
| 64 AuthAttemptStateResolver* const resolver_; | 70 AuthAttemptStateResolver* const resolver_; |
| 65 | 71 |
| 66 // Handles ClientLogin communications with Gaia. | 72 // Handles ClientLogin communications with Gaia. |
| 67 scoped_ptr<GaiaAuthFetcher> client_fetcher_; | 73 scoped_ptr<GaiaAuthFetcher> client_fetcher_; |
| 68 | 74 |
| 69 // Used to cancel the CancelClientLogin closure. | 75 // Used to cancel the CancelClientLogin closure. |
| 70 base::WeakPtrFactory<OnlineAttempt> weak_factory_; | 76 base::WeakPtrFactory<OnlineAttempt> weak_factory_; |
| 71 | 77 |
| 72 // Whether we're willing to re-try the ClientLogin attempt. | 78 // Whether we're willing to re-try the ClientLogin attempt. |
| 73 bool try_again_; | 79 bool try_again_; |
| 74 | 80 |
| 75 friend class OnlineAttemptTest; | 81 friend class OnlineAttemptTest; |
| 76 DISALLOW_COPY_AND_ASSIGN(OnlineAttempt); | 82 DISALLOW_COPY_AND_ASSIGN(OnlineAttempt); |
| 77 }; | 83 }; |
| 78 | 84 |
| 79 } // namespace chromeos | 85 } // namespace chromeos |
| 80 | 86 |
| 81 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_ONLINE_ATTEMPT_H_ | 87 #endif // CHROMEOS_LOGIN_AUTH_ONLINE_ATTEMPT_H_ |
| OLD | NEW |