Home | History | Annotate | Download | only in wallet
      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_BROWSER_WALLET_WALLET_CLIENT_OBSERVER_H_
      6 #define COMPONENTS_AUTOFILL_BROWSER_WALLET_WALLET_CLIENT_OBSERVER_H_
      7 
      8 #include <string>
      9 
     10 #include "base/memory/scoped_ptr.h"
     11 #include "components/autofill/content/browser/wallet/form_field_error.h"
     12 #include "components/autofill/content/browser/wallet/wallet_client.h"
     13 #include "components/autofill/core/browser/autofill_client.h"
     14 
     15 class AutofillMetrics;
     16 
     17 namespace autofill {
     18 namespace wallet {
     19 
     20 class FullWallet;
     21 class WalletItems;
     22 
     23 // WalletClientDelegate is to be implemented any classes making calls with
     24 // WalletClient. The appropriate callback method will be called on
     25 // WalletClientDelegate with the response from the Online Wallet backend.
     26 class WalletClientDelegate {
     27  public:
     28   // --------------------------------------
     29   // Accessors called when making requests.
     30   // --------------------------------------
     31 
     32   // Returns the MetricLogger instance that should be used for logging Online
     33   // Wallet metrics.
     34   virtual const AutofillMetrics& GetMetricLogger() const = 0;
     35 
     36   // Returns the serialized fingerprint data to be sent to the Risk server.
     37   virtual std::string GetRiskData() const = 0;
     38 
     39   // Returns the cookie value used for authorization when making requests to
     40   // Wallet.
     41   virtual std::string GetWalletCookieValue() const = 0;
     42 
     43   // Whether or not shipping address is required by the delegate.
     44   virtual bool IsShippingAddressRequired() const = 0;
     45 
     46   // --------------------------------------------------------------------------
     47   // Callbacks called with responses from the Online Wallet backend.
     48   // --------------------------------------------------------------------------
     49 
     50   // Called when an AcceptLegalDocuments request finishes successfully.
     51   virtual void OnDidAcceptLegalDocuments() = 0;
     52 
     53   // Called when an AuthenticateInstrument request finishes successfully.
     54   virtual void OnDidAuthenticateInstrument(bool success) = 0;
     55 
     56   // Called when a GetFullWallet request finishes successfully. Ownership is
     57   // transferred to implementer of this interface.
     58   virtual void OnDidGetFullWallet(scoped_ptr<FullWallet> full_wallet) = 0;
     59 
     60   // Called when a GetWalletItems request finishes successfully. Ownership is
     61   // transferred to implementer of this interface.
     62   virtual void OnDidGetWalletItems(scoped_ptr<WalletItems> wallet_items) = 0;
     63 
     64   // Called when a SaveToWallet request finishes succesfully.
     65   // |instrument_id| and |address_id| can be used in subsequent
     66   // GetFullWallet calls. |required_actions| is populated if there was a
     67   // validation error with the data being saved. |form_field_errors| is
     68   // populated with the actual form fields that are failing validation.
     69   virtual void OnDidSaveToWallet(
     70       const std::string& instrument_id,
     71       const std::string& address_id,
     72       const std::vector<RequiredAction>& required_actions,
     73       const std::vector<FormFieldError>& form_field_errors) = 0;
     74 
     75   // Called when a request fails.
     76   virtual void OnWalletError(WalletClient::ErrorType error_type) = 0;
     77 
     78  protected:
     79   virtual ~WalletClientDelegate() {}
     80 };
     81 
     82 }  // namespace wallet
     83 }  // namespace autofill
     84 
     85 #endif  // COMPONENTS_AUTOFILL_BROWSER_WALLET_WALLET_CLIENT_OBSERVER_H_
     86