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

Side by Side Diff: components/payments/payment_request_impl.cc

Issue 2611253004: [Payment Request] Change the lifetime management of PaymentRequestImpl (Closed)
Patch Set: added a browser test Created 3 years, 11 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 2016 The Chromium Authors. All rights reserved.
please use gerrit instead 2017/01/06 21:49:09 2017
Mathieu 2017/01/07 05:03:07 Well it was moved so I'll keep 2016.
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 "components/payments/payment_request_impl.h"
6
7 #include <map>
8
9 #include "base/lazy_instance.h"
10 #include "components/payments/payment_details_validation.h"
11 #include "components/payments/payment_request_delegate.h"
12 #include "components/payments/payment_request_web_contents_manager.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/web_contents.h"
15
16 namespace payments {
17
18 PaymentRequestImpl::PaymentRequestImpl(
19 content::WebContents* web_contents,
20 std::unique_ptr<PaymentRequestDelegate> delegate,
21 PaymentRequestWebContentsManager* manager,
22 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request)
23 : web_contents_(web_contents),
24 delegate_(std::move(delegate)),
25 manager_(manager),
26 binding_(this, std::move(request)) {
27 binding_.set_connection_error_handler(
28 base::Bind(&PaymentRequestImpl::OnError, base::Unretained(this)));
29 }
30
31 PaymentRequestImpl::~PaymentRequestImpl() {}
32
33 void PaymentRequestImpl::Init(
34 payments::mojom::PaymentRequestClientPtr client,
35 std::vector<payments::mojom::PaymentMethodDataPtr> methodData,
36 payments::mojom::PaymentDetailsPtr details,
37 payments::mojom::PaymentOptionsPtr options) {
38 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
39 std::string error;
40 if (!payments::validatePaymentDetails(details, &error)) {
41 LOG(ERROR) << error;
42 OnError();
43 return;
44 }
45 client_ = std::move(client);
46 details_ = std::move(details);
47 }
48
49 void PaymentRequestImpl::Show() {
50 delegate_->ShowPaymentRequestDialog(this);
51 }
52
53 void PaymentRequestImpl::Cancel() {
54 client_->OnError(payments::mojom::PaymentErrorReason::USER_CANCEL);
55 }
56
57 void PaymentRequestImpl::OnError() {
58 binding_.Close();
59 // Kill ourselves.
please use gerrit instead 2017/01/06 21:49:09 DestroyRequest(this) is self-explanatory, IMHO.
Mathieu 2017/01/07 05:03:07 Done.
60 manager_->DestroyRequest(this);
61 }
62
63 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698