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
3 // found in the LICENSE file.
5 #ifndef CHROMEOS_LOGIN_AUTH_ONLINE_ATTEMPT_H_
6 #define CHROMEOS_LOGIN_AUTH_ONLINE_ATTEMPT_H_
10 #include "base/compiler_specific.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/single_thread_task_runner.h"
16 #include "chromeos/chromeos_export.h"
17 #include "chromeos/login/auth/auth_status_consumer.h"
18 #include "google_apis/gaia/gaia_auth_consumer.h"
19 #include "google_apis/gaia/google_service_auth_error.h"
21 class GaiaAuthFetcher
;
24 class URLRequestContextGetter
;
28 class AuthAttemptState
;
29 class AuthAttemptStateResolver
;
31 class CHROMEOS_EXPORT OnlineAttempt
: public GaiaAuthConsumer
{
33 OnlineAttempt(AuthAttemptState
* current_attempt
,
34 AuthAttemptStateResolver
* callback
);
35 ~OnlineAttempt() override
;
37 // Initiate the online login attempt either through client or auth login.
38 // Status will be recorded in |current_attempt|, and resolver_->Resolve() will
39 // be called on the IO thread when useful state is available.
40 // Must be called on the UI thread.
41 void Initiate(net::URLRequestContextGetter
* request_context
);
43 // GaiaAuthConsumer overrides. Callbacks from GaiaAuthFetcher
44 void OnClientLoginFailure(const GoogleServiceAuthError
& error
) override
;
45 void OnClientLoginSuccess(
46 const GaiaAuthConsumer::ClientLoginResult
& credentials
) override
;
49 FRIEND_TEST_ALL_PREFIXES(OnlineAttemptTest
, LoginSuccess
);
50 FRIEND_TEST_ALL_PREFIXES(OnlineAttemptTest
, TwoFactorSuccess
);
52 // Milliseconds until we timeout our attempt to hit ClientLogin.
53 static const int kClientLoginTimeoutMs
;
55 void TryClientLogin();
56 void CancelClientLogin();
58 void TriggerResolve(const AuthFailure
& outcome
);
60 bool HasPendingFetch();
63 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
65 AuthAttemptState
* const attempt_
;
66 AuthAttemptStateResolver
* const resolver_
;
68 // Handles ClientLogin communications with Gaia.
69 scoped_ptr
<GaiaAuthFetcher
> client_fetcher_
;
71 // Whether we're willing to re-try the ClientLogin attempt.
74 // Used to cancel the CancelClientLogin closure.
75 base::WeakPtrFactory
<OnlineAttempt
> weak_factory_
;
77 friend class OnlineAttemptTest
;
78 DISALLOW_COPY_AND_ASSIGN(OnlineAttempt
);
81 } // namespace chromeos
83 #endif // CHROMEOS_LOGIN_AUTH_ONLINE_ATTEMPT_H_