1 // Copyright 2013 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 COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_WALLET_SIGNIN_HELPER_H_
6 #define COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_WALLET_SIGNIN_HELPER_H_
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "net/url_request/url_fetcher_delegate.h"
17 class URLRequestContextGetter;
20 class GoogleServiceAuthError;
25 class WalletSigninHelperDelegate;
27 // Authenticates the user against the Online Wallet service.
28 // This class is not thread-safe. An instance may be used on any thread, but
29 // should not be accessed from multiple threads.
30 class WalletSigninHelper : public net::URLFetcherDelegate {
32 // Constructs a helper that works with a given |delegate| and uses a given
33 // |getter| to obtain a context for URL. Both |delegate| and |getter| shall
34 // remain valid over the entire lifetime of the created instance.
35 WalletSigninHelper(WalletSigninHelperDelegate* delegate,
36 net::URLRequestContextGetter* getter);
38 ~WalletSigninHelper() override;
40 // Initiates an attempt to passively sign the user into the Online Wallet.
41 // A passive sign-in is a non-interactive refresh of content area cookies,
42 // and it succeeds as long as the Online Wallet service could safely accept
43 // or refresh the existing area cookies, and the user doesn't need to be
44 // fully reauthenticated with the service.
45 // Either OnPassiveSigninSuccess or OnPassiveSigninFailure will be called
46 // on the original thread.
47 void StartPassiveSignin(size_t user_index);
49 // Initiates the fetch of the user's Google Wallet cookie.
50 void StartWalletCookieValueFetch();
53 // Called if a service authentication error occurs.
54 void OnServiceError(const GoogleServiceAuthError& error);
56 // Called if any other error occurs.
59 // URLFetcherDelegate implementation.
60 void OnURLFetchComplete(const net::URLFetcher* fetcher) override;
62 // Callback for when the Google Wallet cookie has been retrieved.
63 void ReturnWalletCookieValue(const std::string& cookie_value);
65 // Should be valid throughout the lifetime of the instance.
66 WalletSigninHelperDelegate* const delegate_;
68 // URLRequestContextGetter to be used for URLFetchers.
69 net::URLRequestContextGetter* const getter_;
71 // While passive login/merge session URL fetches are going on:
72 scoped_ptr<net::URLFetcher> url_fetcher_;
74 base::WeakPtrFactory<WalletSigninHelper> weak_ptr_factory_;
76 DISALLOW_COPY_AND_ASSIGN(WalletSigninHelper);
80 } // namespace autofill
82 #endif // COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_WALLET_SIGNIN_HELPER_H_