• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_ONLINE_ATTEMPT_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_ONLINE_ATTEMPT_H_
7 #pragma once
8 
9 #include <string>
10 
11 
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "chrome/browser/chromeos/login/login_status_consumer.h"
15 #include "chrome/common/net/gaia/gaia_auth_consumer.h"
16 #include "chrome/common/net/gaia/google_service_auth_error.h"
17 
18 class CancelableTask;
19 class GaiaAuthFetcher;
20 class Profile;
21 
22 namespace net {
23 class URLRequestContextGetter;
24 }
25 
26 namespace chromeos {
27 class AuthAttemptState;
28 class AuthAttemptStateResolver;
29 
30 class OnlineAttempt
31     : public base::RefCountedThreadSafe<OnlineAttempt>,
32       public GaiaAuthConsumer {
33  public:
34   OnlineAttempt(AuthAttemptState* current_attempt,
35                 AuthAttemptStateResolver* callback);
36   virtual ~OnlineAttempt();
37 
38   // Initiate the online login attempt.  Status will be recorded in
39   // |current_attempt|, and resolver_->Resolve() will be called on the
40   // IO thread when useful state is available.
41   // Must be called on the UI thread.
42   void Initiate(Profile* profile);
43 
44   // Callbacks from GaiaAuthFetcher
45   virtual void OnClientLoginFailure(
46       const GoogleServiceAuthError& error);
47   virtual void OnClientLoginSuccess(
48       const GaiaAuthConsumer::ClientLoginResult& credentials);
49 
50  private:
51   // Milliseconds until we timeout our attempt to hit ClientLogin.
52   static const int kClientLoginTimeoutMs;
53 
54   void TryClientLogin();
55   void CancelClientLogin();
56 
57   void TriggerResolve(const GaiaAuthConsumer::ClientLoginResult& credentials,
58                       const LoginFailure& outcome);
59 
60   AuthAttemptState* const attempt_;
61   AuthAttemptStateResolver* const resolver_;
62 
63   // Handles all net communications with Gaia.
64   scoped_ptr<GaiaAuthFetcher> gaia_authenticator_;
65   CancelableTask* fetch_canceler_;
66 
67   // Whether we're willing to re-try the ClientLogin attempt.
68   bool try_again_;
69 
70   friend class OnlineAttemptTest;
71   DISALLOW_COPY_AND_ASSIGN(OnlineAttempt);
72 };
73 
74 }  // namespace chromeos
75 
76 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_ONLINE_ATTEMPT_H_
77