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

Side by Side Diff: components/payments/content/payment_request.cc

Issue 2851893002: [Payments] Record CanMakePayment metrics on Desktop. (Closed)
Patch Set: Windows Fix and Rebase Fix 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 2016 The Chromium Authors. All rights reserved. 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 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 #include "components/payments/content/payment_request.h" 5 #include "components/payments/content/payment_request.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "components/payments/content/origin_security_checker.h" 11 #include "components/payments/content/origin_security_checker.h"
12 #include "components/payments/content/payment_details_validation.h" 12 #include "components/payments/content/payment_details_validation.h"
13 #include "components/payments/content/payment_request_web_contents_manager.h" 13 #include "components/payments/content/payment_request_web_contents_manager.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
16 16
17 namespace payments { 17 namespace payments {
18 18
19 PaymentRequest::PaymentRequest( 19 PaymentRequest::PaymentRequest(
20 content::WebContents* web_contents, 20 content::WebContents* web_contents,
21 std::unique_ptr<PaymentRequestDelegate> delegate, 21 std::unique_ptr<PaymentRequestDelegate> delegate,
22 PaymentRequestWebContentsManager* manager, 22 PaymentRequestWebContentsManager* manager,
23 mojo::InterfaceRequest<mojom::PaymentRequest> request, 23 mojo::InterfaceRequest<mojom::PaymentRequest> request,
24 ObserverForTest* observer_for_testing) 24 ObserverForTest* observer_for_testing)
25 : web_contents_(web_contents), 25 : web_contents_(web_contents),
26 delegate_(std::move(delegate)), 26 delegate_(std::move(delegate)),
27 manager_(manager), 27 manager_(manager),
28 binding_(this, std::move(request)), 28 binding_(this, std::move(request)),
29 observer_for_testing_(observer_for_testing) { 29 observer_for_testing_(observer_for_testing),
30 journey_logger_(delegate_->IsIncognito(),
31 web_contents_->GetLastCommittedURL(),
32 delegate_->GetUkmService()) {
30 // OnConnectionTerminated will be called when the Mojo pipe is closed. This 33 // OnConnectionTerminated will be called when the Mojo pipe is closed. This
31 // will happen as a result of many renderer-side events (both successful and 34 // will happen as a result of many renderer-side events (both successful and
32 // erroneous in nature). 35 // erroneous in nature).
33 // TODO(crbug.com/683636): Investigate using 36 // TODO(crbug.com/683636): Investigate using
34 // set_connection_error_with_reason_handler with Binding::CloseWithReason. 37 // set_connection_error_with_reason_handler with Binding::CloseWithReason.
35 binding_.set_connection_error_handler(base::Bind( 38 binding_.set_connection_error_handler(base::Bind(
36 &PaymentRequest::OnConnectionTerminated, base::Unretained(this))); 39 &PaymentRequest::OnConnectionTerminated, base::Unretained(this)));
37 } 40 }
38 41
39 PaymentRequest::~PaymentRequest() {} 42 PaymentRequest::~PaymentRequest() {}
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 100 }
98 101
99 if (!state_->AreRequestedMethodsSupported()) { 102 if (!state_->AreRequestedMethodsSupported()) {
100 client_->OnError(mojom::PaymentErrorReason::NOT_SUPPORTED); 103 client_->OnError(mojom::PaymentErrorReason::NOT_SUPPORTED);
101 if (observer_for_testing_) 104 if (observer_for_testing_)
102 observer_for_testing_->OnNotSupportedError(); 105 observer_for_testing_->OnNotSupportedError();
103 OnConnectionTerminated(); 106 OnConnectionTerminated();
104 return; 107 return;
105 } 108 }
106 109
110 journey_logger_.SetShowCalled();
107 delegate_->ShowDialog(this); 111 delegate_->ShowDialog(this);
108 } 112 }
109 113
110 void PaymentRequest::UpdateWith(mojom::PaymentDetailsPtr details) { 114 void PaymentRequest::UpdateWith(mojom::PaymentDetailsPtr details) {
111 std::string error; 115 std::string error;
112 if (!validatePaymentDetails(details, &error)) { 116 if (!validatePaymentDetails(details, &error)) {
113 LOG(ERROR) << error; 117 LOG(ERROR) << error;
114 OnConnectionTerminated(); 118 OnConnectionTerminated();
115 return; 119 return;
116 } 120 }
117 spec_->UpdateWith(std::move(details)); 121 spec_->UpdateWith(std::move(details));
118 } 122 }
119 123
120 void PaymentRequest::Abort() { 124 void PaymentRequest::Abort() {
121 // The API user has decided to abort. We return a successful abort message to 125 // The API user has decided to abort. We return a successful abort message to
122 // the renderer, which closes the Mojo message pipe, which triggers 126 // the renderer, which closes the Mojo message pipe, which triggers
123 // PaymentRequest::OnConnectionTerminated, which destroys this object. 127 // PaymentRequest::OnConnectionTerminated, which destroys this object.
128 // TODO(crbug.com/716546): Add a merchant abort metric,
129 journey_logger_.RecordJourneyStatsHistograms(
130 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
124 if (client_.is_bound()) 131 if (client_.is_bound())
125 client_->OnAbort(true /* aborted_successfully */); 132 client_->OnAbort(true /* aborted_successfully */);
126 } 133 }
127 134
128 void PaymentRequest::Complete(mojom::PaymentComplete result) { 135 void PaymentRequest::Complete(mojom::PaymentComplete result) {
129 if (!client_.is_bound()) 136 if (!client_.is_bound())
130 return; 137 return;
131 138
132 if (result != mojom::PaymentComplete::SUCCESS) { 139 if (result != mojom::PaymentComplete::SUCCESS) {
133 delegate_->ShowErrorMessage(); 140 delegate_->ShowErrorMessage();
134 } else { 141 } else {
142 journey_logger_.RecordJourneyStatsHistograms(
143 JourneyLogger::COMPLETION_STATUS_COMPLETED);
135 // When the renderer closes the connection, 144 // When the renderer closes the connection,
136 // PaymentRequest::OnConnectionTerminated will be called. 145 // PaymentRequest::OnConnectionTerminated will be called.
137 client_->OnComplete(); 146 client_->OnComplete();
138 } 147 }
139 } 148 }
140 149
141 void PaymentRequest::CanMakePayment() { 150 void PaymentRequest::CanMakePayment() {
142 // TODO(crbug.com/704676): Implement a quota policy for this method. 151 // TODO(crbug.com/704676): Implement a quota policy for this method.
143 // PaymentRequest.canMakePayments() never returns false in incognito mode. 152 // PaymentRequest.canMakePayments() never returns false in incognito mode.
144 client_->OnCanMakePayment( 153 client_->OnCanMakePayment(
145 delegate_->IsIncognito() || state()->CanMakePayment() 154 delegate_->IsIncognito() || state()->CanMakePayment()
146 ? mojom::CanMakePaymentQueryResult::CAN_MAKE_PAYMENT 155 ? mojom::CanMakePaymentQueryResult::CAN_MAKE_PAYMENT
147 : mojom::CanMakePaymentQueryResult::CANNOT_MAKE_PAYMENT); 156 : mojom::CanMakePaymentQueryResult::CANNOT_MAKE_PAYMENT);
157 journey_logger_.SetCanMakePaymentValue(delegate_->IsIncognito() ||
158 state()->CanMakePayment());
148 if (observer_for_testing_) 159 if (observer_for_testing_)
149 observer_for_testing_->OnCanMakePaymentCalled(); 160 observer_for_testing_->OnCanMakePaymentCalled();
150 } 161 }
151 162
152 void PaymentRequest::OnPaymentResponseAvailable( 163 void PaymentRequest::OnPaymentResponseAvailable(
153 mojom::PaymentResponsePtr response) { 164 mojom::PaymentResponsePtr response) {
154 client_->OnPaymentResponse(std::move(response)); 165 client_->OnPaymentResponse(std::move(response));
155 } 166 }
156 167
157 void PaymentRequest::OnShippingOptionIdSelected( 168 void PaymentRequest::OnShippingOptionIdSelected(
158 std::string shipping_option_id) { 169 std::string shipping_option_id) {
159 client_->OnShippingOptionChange(shipping_option_id); 170 client_->OnShippingOptionChange(shipping_option_id);
160 } 171 }
161 172
162 void PaymentRequest::OnShippingAddressSelected( 173 void PaymentRequest::OnShippingAddressSelected(
163 mojom::PaymentAddressPtr address) { 174 mojom::PaymentAddressPtr address) {
164 client_->OnShippingAddressChange(std::move(address)); 175 client_->OnShippingAddressChange(std::move(address));
165 } 176 }
166 177
167 void PaymentRequest::UserCancelled() { 178 void PaymentRequest::UserCancelled() {
168 // If |client_| is not bound, then the object is already being destroyed as 179 // If |client_| is not bound, then the object is already being destroyed as
169 // a result of a renderer event. 180 // a result of a renderer event.
170 if (!client_.is_bound()) 181 if (!client_.is_bound())
171 return; 182 return;
172 183
184 journey_logger_.RecordJourneyStatsHistograms(
185 JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
186
173 // This sends an error to the renderer, which informs the API user. 187 // This sends an error to the renderer, which informs the API user.
174 client_->OnError(mojom::PaymentErrorReason::USER_CANCEL); 188 client_->OnError(mojom::PaymentErrorReason::USER_CANCEL);
175 189
176 // We close all bindings and ask to be destroyed. 190 // We close all bindings and ask to be destroyed.
177 client_.reset(); 191 client_.reset();
178 binding_.Close(); 192 binding_.Close();
179 manager_->DestroyRequest(this); 193 manager_->DestroyRequest(this);
180 } 194 }
181 195
182 void PaymentRequest::OnConnectionTerminated() { 196 void PaymentRequest::OnConnectionTerminated() {
183 // We are here because of a browser-side error, or likely as a result of the 197 // We are here because of a browser-side error, or likely as a result of the
184 // connection_error_handler on |binding_|, which can mean that the renderer 198 // connection_error_handler on |binding_|, which can mean that the renderer
185 // has decided to close the pipe for various reasons (see all uses of 199 // has decided to close the pipe for various reasons (see all uses of
186 // PaymentRequest::clearResolversAndCloseMojoConnection() in Blink). We close 200 // PaymentRequest::clearResolversAndCloseMojoConnection() in Blink). We close
187 // the binding and the dialog, and ask to be deleted. 201 // the binding and the dialog, and ask to be deleted.
188 client_.reset(); 202 client_.reset();
189 binding_.Close(); 203 binding_.Close();
190 delegate_->CloseDialog(); 204 delegate_->CloseDialog();
191 manager_->DestroyRequest(this); 205 manager_->DestroyRequest(this);
192 } 206 }
193 207
194 void PaymentRequest::Pay() { 208 void PaymentRequest::Pay() {
195 state_->GeneratePaymentResponse(); 209 state_->GeneratePaymentResponse();
196 } 210 }
197 211
198 } // namespace payments 212 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/content/payment_request.h ('k') | components/payments/core/autofill_payment_instrument_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698