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