OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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_PAYMENTS_ANDROID_PAYMENT_MANIFEST_DOWNLOADER_H_ |
| 6 #define COMPONENTS_PAYMENTS_ANDROID_PAYMENT_MANIFEST_DOWNLOADER_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "net/url_request/url_fetcher.h" |
| 14 #include "net/url_request/url_fetcher_delegate.h" |
| 15 |
| 16 namespace net { |
| 17 class URLRequestContextGetter; |
| 18 } |
| 19 |
| 20 namespace payments { |
| 21 |
| 22 // Downloader of the payment method manifest based on the payment method name |
| 23 // that is a URL with HTTPS scheme, e.g., https://bobpay.com. The download |
| 24 // happens via two consecutive HTTP requests: |
| 25 // |
| 26 // 1) HEAD request for the payment method name. The HTTP response header is |
| 27 // parsed for Link header that points to the location of the payment method |
| 28 // manifest file. Example of a relative location: |
| 29 // |
| 30 // Link: <data/payment-manifest.json>; rel="payment-method-manifest" |
| 31 // |
| 32 // (This is relative to the payment method URL.) Example of an absolute |
| 33 // location: |
| 34 // |
| 35 // Link: <https://bobpay.com/data/payment-manifest.json>; |
| 36 // rel="payment-method-manifest" |
| 37 // |
| 38 // The absolute location must use HTTPS scheme. |
| 39 // |
| 40 // 2) GET request for the payment method manifest file. |
| 41 class PaymentManifestDownloader : public net::URLFetcherDelegate { |
| 42 public: |
| 43 // The interface for receiving the result of downloading a manifest. |
| 44 class Delegate { |
| 45 public: |
| 46 // Called when a manifest has been successfully downloaded. |
| 47 virtual void OnManifestDownloadSuccess(const std::string& content) = 0; |
| 48 |
| 49 // Called when failed to download the manifest for any reason: |
| 50 // - HTTP response code is not 200. |
| 51 // - HTTP response headers does not contain Link headers. |
| 52 // - Link header does not contain rel="payment-method-manifest". |
| 53 // - Link header does not contain a URL. |
| 54 // - HTTP GET on the manifest URL returns empty content. |
| 55 virtual void OnManifestDownloadFailure() = 0; |
| 56 |
| 57 protected: |
| 58 virtual ~Delegate() {} |
| 59 }; |
| 60 |
| 61 // |delegate| should not be null and must outlive this object. |
| 62 PaymentManifestDownloader( |
| 63 const scoped_refptr<net::URLRequestContextGetter>& context, |
| 64 const std::string& method_name, |
| 65 Delegate* delegate); |
| 66 |
| 67 ~PaymentManifestDownloader() override; |
| 68 |
| 69 void Download(); |
| 70 |
| 71 private: |
| 72 void InitiateDownload(const std::string& url, |
| 73 net::URLFetcher::RequestType request_type); |
| 74 |
| 75 // net::URLFetcherDelegate |
| 76 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 77 |
| 78 scoped_refptr<net::URLRequestContextGetter> context_; |
| 79 std::string method_name_; |
| 80 |
| 81 // Non-owned. Never null. Outlives this object. |
| 82 Delegate* delegate_; |
| 83 |
| 84 bool is_downloading_http_link_header_; |
| 85 std::unique_ptr<net::URLFetcher> fetcher_; |
| 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(PaymentManifestDownloader); |
| 88 }; |
| 89 |
| 90 } // namespace payments |
| 91 |
| 92 #endif // COMPONENTS_PAYMENTS_ANDROID_PAYMENT_MANIFEST_DOWNLOADER_H_ |
OLD | NEW |