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

Side by Side Diff: content/browser/payments/payment_instrument_icon_fetcher.h

Issue 2925063003: [Payments] Implement payment instrument icons (Closed)
Patch Set: fix comment lines Created 3 years, 6 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
(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 CONTENT_BROWSER_PAYMENTS_PAYMENT_INSTRUMENT_ICON_FETCHER_H_
6 #define CONTENT_BROWSER_PAYMENTS_PAYMENT_INSTRUMENT_ICON_FETCHER_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "components/payments/mojom/payment_app.mojom.h"
14 #include "content/browser/service_worker/service_worker_context_wrapper.h"
15 #include "net/url_request/url_fetcher.h"
16 #include "net/url_request/url_fetcher_delegate.h"
17 #include "net/url_request/url_request_context_getter.h"
18 #include "third_party/skia/include/core/SkBitmap.h"
19
20 namespace content {
21
22 class PaymentInstrumentIconFetcher
23 : public base::RefCountedThreadSafe<PaymentInstrumentIconFetcher>,
24 private net::URLFetcherDelegate {
25 public:
26 using PaymentInstrumentIconFetcherCallback =
27 base::OnceCallback<void(const std::string&)>;
28
29 PaymentInstrumentIconFetcher();
30
31 // Starts fetching and decoding payment instrument icon from online. The
32 // result will be send back through |callback|.
33 // TODO(gogerald): Right now, we return the first fetchable and decodable icon
34 // with smallest available size. We may add more logic to choose appropriate
35 // icon according to icon size and our usage.
36 void Start(const std::vector<payments::mojom::ImageObjectPtr>& image_objects,
37 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
38 PaymentInstrumentIconFetcherCallback callback);
39
40 private:
41 friend class base::RefCountedThreadSafe<PaymentInstrumentIconFetcher>;
42 ~PaymentInstrumentIconFetcher() override;
43
44 void StartFromUIThread(
45 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context);
46 void PostCallbackToIOThread(const std::string& decoded_data);
47
48 // data_decoder::mojom::ImageDecoder::DecodeImageCallback.
49 void DecodeImageCallback(const SkBitmap& bitmap);
50
51 // Override net::URLFetcherDelegate.
52 void OnURLFetchComplete(const net::URLFetcher* source) override;
53
54 void FetchIcon();
55
56 // Declared set of image objects of the payment instrument.
57 std::vector<payments::mojom::ImageObjectPtr> image_objects_;
58
59 // The index of the currently checking image object in image_objects_.
60 size_t checking_image_object_index_;
61
62 // The callback to notify after complete.
63 PaymentInstrumentIconFetcherCallback callback_;
64
65 // The url request context getter for fetching icon from online.
66 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
67
68 // The url fetcher to fetch raw icon from online.
69 std::unique_ptr<net::URLFetcher> fetcher_;
70
71 DISALLOW_COPY_AND_ASSIGN(PaymentInstrumentIconFetcher);
72 };
73
74 } // namespace content
75
76 #endif // CONTENT_BROWSER_PAYMENTS_PAYMENT_INSTRUMENT_ICON_FETCHER_H_
OLDNEW
« no previous file with comments | « content/browser/payments/payment_app_database.cc ('k') | content/browser/payments/payment_instrument_icon_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698