Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / chromeos / login / auth / online_attempt.h
blob032d2f5f3eebd2bd2064c3b16655bc97c46f5f68
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_
8 #include <string>
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 "chromeos/chromeos_export.h"
16 #include "chromeos/login/auth/auth_status_consumer.h"
17 #include "google_apis/gaia/gaia_auth_consumer.h"
18 #include "google_apis/gaia/google_service_auth_error.h"
20 class GaiaAuthFetcher;
22 namespace net {
23 class URLRequestContextGetter;
26 namespace chromeos {
27 class AuthAttemptState;
28 class AuthAttemptStateResolver;
30 class CHROMEOS_EXPORT OnlineAttempt : public GaiaAuthConsumer {
31 public:
32 OnlineAttempt(AuthAttemptState* current_attempt,
33 AuthAttemptStateResolver* callback);
34 ~OnlineAttempt() override;
36 // Initiate the online login attempt either through client or auth login.
37 // Status will be recorded in |current_attempt|, and resolver_->Resolve() will
38 // be called on the IO thread when useful state is available.
39 // Must be called on the UI thread.
40 void Initiate(net::URLRequestContextGetter* request_context);
42 // GaiaAuthConsumer overrides. Callbacks from GaiaAuthFetcher
43 void OnClientLoginFailure(const GoogleServiceAuthError& error) override;
44 void OnClientLoginSuccess(
45 const GaiaAuthConsumer::ClientLoginResult& credentials) override;
47 private:
48 FRIEND_TEST_ALL_PREFIXES(OnlineAttemptTest, LoginSuccess);
49 FRIEND_TEST_ALL_PREFIXES(OnlineAttemptTest, TwoFactorSuccess);
51 // Milliseconds until we timeout our attempt to hit ClientLogin.
52 static const int kClientLoginTimeoutMs;
54 void TryClientLogin();
55 void CancelClientLogin();
57 void TriggerResolve(const AuthFailure& outcome);
59 bool HasPendingFetch();
60 void CancelRequest();
62 scoped_refptr<base::MessageLoopProxy> message_loop_;
64 AuthAttemptState* const attempt_;
65 AuthAttemptStateResolver* const resolver_;
67 // Handles ClientLogin communications with Gaia.
68 scoped_ptr<GaiaAuthFetcher> client_fetcher_;
70 // Whether we're willing to re-try the ClientLogin attempt.
71 bool try_again_;
73 // Used to cancel the CancelClientLogin closure.
74 base::WeakPtrFactory<OnlineAttempt> weak_factory_;
76 friend class OnlineAttemptTest;
77 DISALLOW_COPY_AND_ASSIGN(OnlineAttempt);
80 } // namespace chromeos
82 #endif // CHROMEOS_LOGIN_AUTH_ONLINE_ATTEMPT_H_