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

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

Issue 2870153002: [Payments] Record navigations that close the Payment Request as aborts. (Closed)
Patch Set: Created 3 years, 7 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_PAYMENT_REQUEST_WEB_CONTENTS_MANAGER_H_ 5 #ifndef COMPONENTS_PAYMENTS_PAYMENT_REQUEST_WEB_CONTENTS_MANAGER_H_
6 #define COMPONENTS_PAYMENTS_PAYMENT_REQUEST_WEB_CONTENTS_MANAGER_H_ 6 #define COMPONENTS_PAYMENTS_PAYMENT_REQUEST_WEB_CONTENTS_MANAGER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <unordered_map> 9 #include <unordered_map>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "components/payments/content/payment_request.h" 12 #include "components/payments/content/payment_request.h"
13 #include "components/payments/mojom/payment_request.mojom.h" 13 #include "components/payments/mojom/payment_request.mojom.h"
14 #include "content/public/browser/web_contents_observer.h"
14 #include "content/public/browser/web_contents_user_data.h" 15 #include "content/public/browser/web_contents_user_data.h"
15 #include "mojo/public/cpp/bindings/binding.h" 16 #include "mojo/public/cpp/bindings/binding.h"
16 17
17 namespace content { 18 namespace content {
19 class NavigationHandle;
18 class WebContents; 20 class WebContents;
19 } 21 } // namespace content
20 22
21 namespace payments { 23 namespace payments {
22 24
23 class PaymentRequestDelegate; 25 class PaymentRequestDelegate;
24 26
25 // This class owns the PaymentRequest associated with a given WebContents. 27 // This class owns the PaymentRequest associated with a given WebContents.
26 // 28 //
27 // Responsible for creating PaymentRequest's and retaining ownership. No request 29 // Responsible for creating PaymentRequest's and retaining ownership. No request
28 // pointers are currently available because the request manages its interactions 30 // pointers are currently available because the request manages its interactions
29 // with UI and renderer. The PaymentRequest may call DestroyRequest() to signal 31 // with UI and renderer. The PaymentRequest may call DestroyRequest() to signal
30 // it is ready to die. Otherwise it gets destroyed when the WebContents (thus 32 // it is ready to die. Otherwise it gets destroyed when the WebContents (thus
31 // this class) goes away. 33 // this class) goes away.
32 class PaymentRequestWebContentsManager 34 class PaymentRequestWebContentsManager
33 : public content::WebContentsUserData<PaymentRequestWebContentsManager> { 35 : public content::WebContentsObserver,
36 public content::WebContentsUserData<PaymentRequestWebContentsManager> {
34 public: 37 public:
35 ~PaymentRequestWebContentsManager() override; 38 ~PaymentRequestWebContentsManager() override;
36 39
37 // Retrieves the instance of PaymentRequestWebContentsManager that was 40 // Retrieves the instance of PaymentRequestWebContentsManager that was
38 // attached to the specified WebContents. If no instance was attached, 41 // attached to the specified WebContents. If no instance was attached,
39 // creates one, and attaches it to the specified WebContents. 42 // creates one, and attaches it to the specified WebContents.
40 static PaymentRequestWebContentsManager* GetOrCreateForWebContents( 43 static PaymentRequestWebContentsManager* GetOrCreateForWebContents(
41 content::WebContents* web_contents); 44 content::WebContents* web_contents);
42 45
43 // Creates the PaymentRequest that will interact with this |web_contents|. 46 // Creates the PaymentRequest that will interact with this |web_contents|.
44 void CreatePaymentRequest( 47 void CreatePaymentRequest(
45 content::WebContents* web_contents, 48 content::WebContents* web_contents,
46 std::unique_ptr<PaymentRequestDelegate> delegate, 49 std::unique_ptr<PaymentRequestDelegate> delegate,
47 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request, 50 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request,
48 PaymentRequest::ObserverForTest* observer_for_testing); 51 PaymentRequest::ObserverForTest* observer_for_testing);
49 52
50 // Destroys the given |request|. 53 // Destroys the given |request|.
51 void DestroyRequest(PaymentRequest* request); 54 void DestroyRequest(PaymentRequest* request);
52 55
56 // WebContentsObserver::
57 void DidStartNavigation(
58 content::NavigationHandle* navigation_handle) override;
59
53 private: 60 private:
54 explicit PaymentRequestWebContentsManager(content::WebContents* web_contents); 61 explicit PaymentRequestWebContentsManager(content::WebContents* web_contents);
55 friend class content::WebContentsUserData<PaymentRequestWebContentsManager>; 62 friend class content::WebContentsUserData<PaymentRequestWebContentsManager>;
56 friend class PaymentRequestBrowserTestBase; 63 friend class PaymentRequestBrowserTestBase;
57 64
58 // Owns all the PaymentRequest for this WebContents. Since the 65 // Owns all the PaymentRequest for this WebContents. Since the
59 // PaymentRequestWebContentsManager's lifetime is tied to the WebContents, 66 // PaymentRequestWebContentsManager's lifetime is tied to the WebContents,
60 // these requests only get destroyed when the WebContents goes away, or when 67 // these requests only get destroyed when the WebContents goes away, or when
61 // the requests themselves call DestroyRequest(). 68 // the requests themselves call DestroyRequest().
62 std::unordered_map<PaymentRequest*, std::unique_ptr<PaymentRequest>> 69 std::unordered_map<PaymentRequest*, std::unique_ptr<PaymentRequest>>
63 payment_requests_; 70 payment_requests_;
64 71
65 DISALLOW_COPY_AND_ASSIGN(PaymentRequestWebContentsManager); 72 DISALLOW_COPY_AND_ASSIGN(PaymentRequestWebContentsManager);
66 }; 73 };
67 74
68 } // namespace payments 75 } // namespace payments
69 76
70 #endif // COMPONENTS_PAYMENTS_PAYMENT_REQUEST_WEB_CONTENTS_MANAGER_H_ 77 #endif // COMPONENTS_PAYMENTS_PAYMENT_REQUEST_WEB_CONTENTS_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698