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

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

Issue 2851893002: [Payments] Record CanMakePayment metrics on Desktop. (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 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(state()->CanMakePayment());
Mathieu 2017/05/02 20:56:47 I think we should log the value that is sent back
sebsg 2017/05/02 22:15:08 Right, it's more safe if the code changes, but we
148 if (observer_for_testing_) 158 if (observer_for_testing_)
149 observer_for_testing_->OnCanMakePaymentCalled(); 159 observer_for_testing_->OnCanMakePaymentCalled();
150 } 160 }
151 161
152 void PaymentRequest::OnPaymentResponseAvailable( 162 void PaymentRequest::OnPaymentResponseAvailable(
153 mojom::PaymentResponsePtr response) { 163 mojom::PaymentResponsePtr response) {
154 client_->OnPaymentResponse(std::move(response)); 164 client_->OnPaymentResponse(std::move(response));
155 } 165 }
156 166
157 void PaymentRequest::OnShippingOptionIdSelected( 167 void PaymentRequest::OnShippingOptionIdSelected(
158 std::string shipping_option_id) { 168 std::string shipping_option_id) {
159 client_->OnShippingOptionChange(shipping_option_id); 169 client_->OnShippingOptionChange(shipping_option_id);
160 } 170 }
161 171
162 void PaymentRequest::OnShippingAddressSelected( 172 void PaymentRequest::OnShippingAddressSelected(
163 mojom::PaymentAddressPtr address) { 173 mojom::PaymentAddressPtr address) {
164 client_->OnShippingAddressChange(std::move(address)); 174 client_->OnShippingAddressChange(std::move(address));
165 } 175 }
166 176
167 void PaymentRequest::UserCancelled() { 177 void PaymentRequest::UserCancelled() {
168 // If |client_| is not bound, then the object is already being destroyed as 178 // If |client_| is not bound, then the object is already being destroyed as
169 // a result of a renderer event. 179 // a result of a renderer event.
170 if (!client_.is_bound()) 180 if (!client_.is_bound())
171 return; 181 return;
172 182
183 journey_logger_.RecordJourneyStatsHistograms(
184 JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
185
173 // This sends an error to the renderer, which informs the API user. 186 // This sends an error to the renderer, which informs the API user.
174 client_->OnError(mojom::PaymentErrorReason::USER_CANCEL); 187 client_->OnError(mojom::PaymentErrorReason::USER_CANCEL);
175 188
176 // We close all bindings and ask to be destroyed. 189 // We close all bindings and ask to be destroyed.
177 client_.reset(); 190 client_.reset();
178 binding_.Close(); 191 binding_.Close();
179 manager_->DestroyRequest(this); 192 manager_->DestroyRequest(this);
180 } 193 }
181 194
182 void PaymentRequest::OnConnectionTerminated() { 195 void PaymentRequest::OnConnectionTerminated() {
183 // We are here because of a browser-side error, or likely as a result of the 196 // 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 197 // 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 198 // has decided to close the pipe for various reasons (see all uses of
186 // PaymentRequest::clearResolversAndCloseMojoConnection() in Blink). We close 199 // PaymentRequest::clearResolversAndCloseMojoConnection() in Blink). We close
187 // the binding and the dialog, and ask to be deleted. 200 // the binding and the dialog, and ask to be deleted.
201 journey_logger_.RecordJourneyStatsHistograms(
202 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
Mathieu 2017/05/02 20:56:47 This method can get called because of many reasons
sebsg 2017/05/02 22:15:08 Yeah I would like if you could give me more info.
Mathieu 2017/05/03 02:22:49 Line 33-37 gives a possible way we could know of t
sebsg 2017/05/03 17:10:11 Thanks, will look at this right after this CL
188 client_.reset(); 203 client_.reset();
189 binding_.Close(); 204 binding_.Close();
190 delegate_->CloseDialog(); 205 delegate_->CloseDialog();
191 manager_->DestroyRequest(this); 206 manager_->DestroyRequest(this);
192 } 207 }
193 208
194 void PaymentRequest::Pay() { 209 void PaymentRequest::Pay() {
195 state_->GeneratePaymentResponse(); 210 state_->GeneratePaymentResponse();
196 } 211 }
197 212
198 } // namespace payments 213 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698