Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1127)

Side by Side Diff: components/payments/content/payment_manifest_downloader.h

Issue 2802043002: Use web-app manifest format for Android payment apps. (Closed)
Patch Set: Address comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_PAYMENTS_CONTENT_PAYMENT_MANIFEST_DOWNLOADER_H_ 5 #ifndef COMPONENTS_PAYMENTS_CONTENT_PAYMENT_MANIFEST_DOWNLOADER_H_
6 #define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_MANIFEST_DOWNLOADER_H_ 6 #define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_MANIFEST_DOWNLOADER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "net/url_request/url_fetcher.h" 13 #include "net/url_request/url_fetcher.h"
14 #include "net/url_request/url_fetcher_delegate.h" 14 #include "net/url_request/url_fetcher_delegate.h"
15 #include "url/gurl.h" 15 #include "url/gurl.h"
16 16
17 namespace net { 17 namespace net {
18 class URLRequestContextGetter; 18 class URLRequestContextGetter;
19 } 19 }
20 20
21 namespace payments { 21 namespace payments {
22 22
23 // Downloader of the payment method manifest based on the payment method name 23 // Downloader of the payment method manifest and web-app manifest based on the
24 // that is a URL with HTTPS scheme, e.g., https://bobpay.com. The download 24 // payment method name that is a URL with HTTPS scheme, e.g.,
25 // happens via two consecutive HTTP requests: 25 // https://bobpay.com.
26 // 26 //
27 // 1) HEAD request for the payment method name. The HTTP response header is 27 // The downloader does not follow redirects. A download succeeds only if all
28 // parsed for Link header that points to the location of the payment method
29 // manifest file. Example of a relative location:
30 //
31 // Link: <data/payment-manifest.json>; rel="payment-method-manifest"
32 //
33 // (This is relative to the payment method URL.) Example of an absolute
34 // location:
35 //
36 // Link: <https://bobpay.com/data/payment-manifest.json>;
37 // rel="payment-method-manifest"
38 //
39 // The absolute location must use HTTPS scheme.
40 //
41 // 2) GET request for the payment method manifest file.
42 //
43 // The downloader does not follow redirects. A download succeeds only if both
44 // HTTP response codes are 200. 28 // HTTP response codes are 200.
45 class PaymentManifestDownloader : public net::URLFetcherDelegate { 29 class PaymentManifestDownloader : public net::URLFetcherDelegate {
46 public: 30 public:
47 // The interface for receiving the result of downloading a manifest. 31 // The interface for receiving the result of downloading a manifest.
48 class Delegate { 32 class Delegate {
49 public: 33 public:
50 // Called when a manifest has been successfully downloaded. 34 // Called when a manifest has been successfully downloaded.
51 virtual void OnManifestDownloadSuccess(const std::string& content) = 0; 35 virtual void OnManifestDownloadSuccess(const std::string& content) = 0;
52 36
53 // Called when failed to download the manifest for any reason: 37 // Called when failed to download the manifest for any reason:
54 // - HTTP response code is not 200. 38 // - HTTP response code is not 200.
39 // - HTTP GET on the manifest URL returns empty content.
40 //
41 // In the case of a payment method manifest download, can also be called
42 // when:
55 // - HTTP response headers are absent. 43 // - HTTP response headers are absent.
56 // - HTTP response headers does not contain Link headers. 44 // - HTTP response headers do not contain Link headers.
57 // - Link header does not contain rel="payment-method-manifest". 45 // - Link header does not contain rel="payment-method-manifest".
58 // - Link header does not contain a valid URL. 46 // - Link header does not contain a valid URL.
59 // - HTTP GET on the manifest URL returns empty content.
60 virtual void OnManifestDownloadFailure() = 0; 47 virtual void OnManifestDownloadFailure() = 0;
61 48
62 protected: 49 protected:
63 virtual ~Delegate() {} 50 virtual ~Delegate() {}
64 }; 51 };
65 52
66 // |delegate| should not be null and must outlive this object. |method_name| 53 // |delegate| should not be null and must outlive this object. |url| should be
67 // should be a valid URL that starts with "https://". 54 // a valid URL with HTTPS scheme.
68 PaymentManifestDownloader( 55 PaymentManifestDownloader(
69 const scoped_refptr<net::URLRequestContextGetter>& context, 56 const scoped_refptr<net::URLRequestContextGetter>& context,
70 const GURL& method_name, 57 const GURL& url,
71 Delegate* delegate); 58 Delegate* delegate);
72 59
73 ~PaymentManifestDownloader() override; 60 ~PaymentManifestDownloader() override;
74 61
75 void Download(); 62 // Download a payment method manifest via two consecutive HTTP requests:
63 //
64 // 1) HEAD request for the payment method name. The HTTP response header is
65 // parsed for Link header that points to the location of the payment method
66 // manifest file. Example of a relative location:
67 //
68 // Link: <data/payment-manifest.json>; rel="payment-method-manifest"
69 //
70 // (This is relative to the payment method URL.) Example of an absolute
71 // location:
72 //
73 // Link: <https://bobpay.com/data/payment-manifest.json>;
74 // rel="payment-method-manifest"
75 //
76 // The absolute location must use HTTPS scheme.
77 //
78 // 2) GET request for the payment method manifest file.
79 void DownloadPaymentMethodManifest();
80
81 // Download a web app manifest via a single HTTP request:
82 //
83 // 1) GET request for the payment method name.
84 void DownloadWebAppManifest();
76 85
77 private: 86 private:
78 void InitiateDownload(const GURL& url, 87 void InitiateDownload(const GURL& url,
79 net::URLFetcher::RequestType request_type); 88 net::URLFetcher::RequestType request_type);
80 89
81 // net::URLFetcherDelegate 90 // net::URLFetcherDelegate
82 void OnURLFetchComplete(const net::URLFetcher* source) override; 91 void OnURLFetchComplete(const net::URLFetcher* source) override;
83 92
84 scoped_refptr<net::URLRequestContextGetter> context_; 93 scoped_refptr<net::URLRequestContextGetter> context_;
85 const GURL method_name_; 94 const GURL url_;
86 95
87 // Non-owned. Never null. Outlives this object. 96 // Non-owned. Never null. Outlives this object.
88 Delegate* delegate_; 97 Delegate* delegate_;
89 98
90 bool is_downloading_http_link_header_; 99 bool is_downloading_http_link_header_;
91 std::unique_ptr<net::URLFetcher> fetcher_; 100 std::unique_ptr<net::URLFetcher> fetcher_;
92 101
93 DISALLOW_COPY_AND_ASSIGN(PaymentManifestDownloader); 102 DISALLOW_COPY_AND_ASSIGN(PaymentManifestDownloader);
94 }; 103 };
95 104
96 } // namespace payments 105 } // namespace payments
97 106
98 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_MANIFEST_DOWNLOADER_H_ 107 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_MANIFEST_DOWNLOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698