Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 #include "chrome/browser/payments/payment_request_impl.h" | |
| 6 | |
| 7 #include <set> | |
| 8 | |
| 9 #include "base/lazy_instance.h" | |
| 10 #include "base/synchronization/lock.h" | |
|
Lei Zhang
2016/11/16 00:59:33
No longer needed.
Kevin Bailey
2016/11/16 14:13:47
Done. Odd, git cl lint doesn't complain.
Lei Zhang
2016/11/16 18:39:30
git cl lint is not a "find what #includes you don'
Kevin Bailey
2016/11/16 22:34:09
As I stated. My point was, since it does do 'iwyu'
| |
| 11 #include "chrome/browser/payments/ui/payment_request_dialog.h" | |
| 12 #include "components/web_modal/web_contents_modal_dialog_host.h" | |
| 13 #include "components/web_modal/web_contents_modal_dialog_manager.h" | |
| 14 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | |
| 15 #include "content/public/browser/web_contents.h" | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 class PaymentRequestFactory { | |
| 20 public: | |
| 21 bool AssignPaymentRequest( | |
| 22 content::WebContents* web_contents, | |
| 23 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) { | |
| 24 if (set_.find(web_contents) == set_.end()) { | |
| 25 scoped_refptr<payments::PaymentRequestImpl> p( | |
| 26 new payments::PaymentRequestImpl(web_contents, std::move(request))); | |
| 27 set_.insert(web_contents); | |
| 28 p->AddRef(); | |
| 29 return true; | |
| 30 } | |
| 31 return false; | |
| 32 } | |
| 33 | |
| 34 void UnassignPaymentRequest(content::WebContents* web_contents) { | |
| 35 set_.erase(web_contents); | |
| 36 } | |
| 37 | |
| 38 private: | |
| 39 std::set<content::WebContents*> set_; | |
|
Lei Zhang
2016/11/16 00:59:33
If you make this a map of: content::WebContents* t
Kevin Bailey
2016/11/16 14:13:47
Funny that you mention it, but it was a map<> and
Lei Zhang
2016/11/16 18:39:30
I haven't played with Mojo in a while. Ok, how abo
Lei Zhang
2016/11/16 18:43:19
FWIW, most of the set_connection_error_handler() c
Kevin Bailey
2016/11/16 22:34:09
Works for me, since it prevents one without the ot
Lei Zhang
2016/11/16 23:02:25
I don't know what "the right way" is, so I would s
| |
| 40 }; | |
| 41 | |
| 42 base::LazyInstance<PaymentRequestFactory> payment_request_factory; | |
| 43 | |
| 44 } // namespace | |
| 45 | |
| 46 namespace payments { | |
| 47 | |
| 48 PaymentRequestImpl::PaymentRequestImpl( | |
| 49 content::WebContents* web_contents, | |
| 50 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) | |
| 51 : web_contents_(web_contents), | |
| 52 binding_(this, std::move(request)), | |
| 53 dialog_(nullptr) { | |
| 54 binding_.set_connection_error_handler( | |
| 55 base::Bind(&PaymentRequestImpl::onError, this)); | |
| 56 } | |
| 57 | |
| 58 PaymentRequestImpl::~PaymentRequestImpl() { | |
| 59 payment_request_factory.Get().UnassignPaymentRequest(web_contents_); | |
| 60 } | |
| 61 | |
| 62 void PaymentRequestImpl::Init( | |
| 63 payments::mojom::PaymentRequestClientPtr client, | |
| 64 std::vector<payments::mojom::PaymentMethodDataPtr> methodData, | |
| 65 payments::mojom::PaymentDetailsPtr details, | |
| 66 payments::mojom::PaymentOptionsPtr options) { | |
| 67 dialog_ = new PaymentRequestDialog(std::move(client)); | |
| 68 views::DialogDelegate::CreateDialogWidget( | |
| 69 dialog_, nullptr, | |
| 70 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents_) | |
| 71 ->delegate() | |
| 72 ->GetWebContentsModalDialogHost() | |
| 73 ->GetHostView()) | |
| 74 ->Show(); | |
| 75 } | |
| 76 | |
| 77 void PaymentRequestImpl::onError() { | |
| 78 binding_.Close(); | |
| 79 // TODO(krb): Call dialog_->Close() here, but avoid double-free | |
| 80 Release(); | |
| 81 } | |
| 82 | |
| 83 } // namespace payments | |
| 84 | |
| 85 void CreatePaymentRequestHandler( | |
| 86 content::WebContents* web_contents, | |
| 87 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) { | |
| 88 payment_request_factory.Get().AssignPaymentRequest(web_contents, | |
| 89 std::move(request)); | |
| 90 } | |
| OLD | NEW |