| 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_PAYMENT_REQUEST_WEB_CONTENTS_MANAGER_H_ | |
| 6 #define COMPONENTS_PAYMENTS_PAYMENT_REQUEST_WEB_CONTENTS_MANAGER_H_ | |
| 7 | |
| 8 #include <unordered_map> | |
| 9 | |
| 10 #include "components/payments/payment_request.h" | |
| 11 #include "components/payments/payment_request.mojom.h" | |
| 12 #include "content/public/browser/web_contents_user_data.h" | |
| 13 #include "mojo/public/cpp/bindings/binding.h" | |
| 14 | |
| 15 namespace payments { | |
| 16 | |
| 17 class PaymentRequestDelegate; | |
| 18 | |
| 19 // This class owns the PaymentRequest associated with a given WebContents. | |
| 20 // | |
| 21 // Responsible for creating PaymentRequest's and retaining ownership. No request | |
| 22 // pointers are currently available because the request manages its interactions | |
| 23 // with UI and renderer. The PaymentRequest may call DestroyRequest() to signal | |
| 24 // it is ready to die. Otherwise it gets destroyed when the WebContents (thus | |
| 25 // this class) goes away. | |
| 26 class PaymentRequestWebContentsManager | |
| 27 : public content::WebContentsUserData<PaymentRequestWebContentsManager> { | |
| 28 public: | |
| 29 ~PaymentRequestWebContentsManager() override; | |
| 30 | |
| 31 // Retrieves the instance of PaymentRequestWebContentsManager that was | |
| 32 // attached to the specified WebContents. If no instance was attached, | |
| 33 // creates one, and attaches it to the specified WebContents. | |
| 34 static PaymentRequestWebContentsManager* GetOrCreateForWebContents( | |
| 35 content::WebContents* web_contents); | |
| 36 | |
| 37 // Creates the PaymentRequest that will interact with this |web_contents|. | |
| 38 void CreatePaymentRequest( | |
| 39 content::WebContents* web_contents, | |
| 40 std::unique_ptr<PaymentRequestDelegate> delegate, | |
| 41 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request); | |
| 42 | |
| 43 // Destroys the given |request|. | |
| 44 void DestroyRequest(PaymentRequest* request); | |
| 45 | |
| 46 private: | |
| 47 explicit PaymentRequestWebContentsManager(content::WebContents* web_contents); | |
| 48 friend class content::WebContentsUserData<PaymentRequestWebContentsManager>; | |
| 49 friend class PaymentRequestInteractiveTestBase; | |
| 50 | |
| 51 // Owns all the PaymentRequest for this WebContents. Since the | |
| 52 // PaymentRequestWebContentsManager's lifetime is tied to the WebContents, | |
| 53 // these requests only get destroyed when the WebContents goes away, or when | |
| 54 // the requests themselves call DestroyRequest(). | |
| 55 std::unordered_map<PaymentRequest*, std::unique_ptr<PaymentRequest>> | |
| 56 payment_requests_; | |
| 57 }; | |
| 58 | |
| 59 } // namespace payments | |
| 60 | |
| 61 #endif // COMPONENTS_PAYMENTS_PAYMENT_REQUEST_WEB_CONTENTS_MANAGER_H_ | |
| OLD | NEW |