online_attempt.h revision 731df977c0511bca2206b5f333555b1205ff1f43
1// Copyright (c) 2010 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/ref_counted.h"
13#include "base/scoped_ptr.h"
14#include "chrome/browser/browser_thread.h"
15#include "chrome/browser/chromeos/login/login_status_consumer.h"
16#include "chrome/common/net/gaia/gaia_auth_consumer.h"
17#include "chrome/common/net/gaia/google_service_auth_error.h"
18
19class GaiaAuthenticator2;
20class Profile;
21
22namespace chromeos {
23class AuthAttemptState;
24class AuthAttemptStateResolver;
25
26class OnlineAttempt
27    : public base::RefCountedThreadSafe<OnlineAttempt>,
28      public GaiaAuthConsumer {
29 public:
30  OnlineAttempt(AuthAttemptState* current_attempt,
31                AuthAttemptStateResolver* callback);
32  virtual ~OnlineAttempt();
33
34  // Initiate the online login attempt.  Status will be recorded in
35  // |current_attempt|, and resolver_->Resolve() will be called on the
36  // IO thread when useful state is available.
37  void Initiate(Profile* profile);
38
39  // Callbacks from GaiaAuthenticator2
40  virtual void OnClientLoginFailure(
41      const GoogleServiceAuthError& error);
42  virtual void OnClientLoginSuccess(
43      const GaiaAuthConsumer::ClientLoginResult& credentials);
44
45 private:
46  // Milliseconds until we timeout our attempt to hit ClientLogin.
47  static const int kClientLoginTimeoutMs;
48
49  void TryClientLogin();
50  void CancelClientLogin();
51
52  void TriggerResolve(const GaiaAuthConsumer::ClientLoginResult& credentials,
53                      const LoginFailure& outcome);
54
55  AuthAttemptState* const attempt_;
56  AuthAttemptStateResolver* const resolver_;
57
58  // Handles all net communications with Gaia.
59  scoped_ptr<GaiaAuthenticator2> gaia_authenticator_;
60  CancelableTask* fetch_canceler_;
61
62  // Whether we're willing to re-try the ClientLogin attempt.
63  bool try_again_;
64
65  friend class OnlineAttemptTest;
66  DISALLOW_COPY_AND_ASSIGN(OnlineAttempt);
67};
68
69}  // namespace chromeos
70
71#endif  // CHROME_BROWSER_CHROMEOS_LOGIN_ONLINE_ATTEMPT_H_
72