| OLD | NEW |
| 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" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 return; | 145 return; |
| 146 } | 146 } |
| 147 spec_->UpdateWith(std::move(details)); | 147 spec_->UpdateWith(std::move(details)); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void PaymentRequest::Abort() { | 150 void PaymentRequest::Abort() { |
| 151 // The API user has decided to abort. We return a successful abort message to | 151 // The API user has decided to abort. We return a successful abort message to |
| 152 // the renderer, which closes the Mojo message pipe, which triggers | 152 // the renderer, which closes the Mojo message pipe, which triggers |
| 153 // PaymentRequest::OnConnectionTerminated, which destroys this object. | 153 // PaymentRequest::OnConnectionTerminated, which destroys this object. |
| 154 // TODO(crbug.com/716546): Add a merchant abort metric, | 154 // TODO(crbug.com/716546): Add a merchant abort metric, |
| 155 journey_logger_.RecordJourneyStatsHistograms( | 155 RecordFirstCompletionStatus(JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED); |
| 156 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED); | |
| 157 if (client_.is_bound()) | 156 if (client_.is_bound()) |
| 158 client_->OnAbort(true /* aborted_successfully */); | 157 client_->OnAbort(true /* aborted_successfully */); |
| 159 } | 158 } |
| 160 | 159 |
| 161 void PaymentRequest::Complete(mojom::PaymentComplete result) { | 160 void PaymentRequest::Complete(mojom::PaymentComplete result) { |
| 162 if (!client_.is_bound()) | 161 if (!client_.is_bound()) |
| 163 return; | 162 return; |
| 164 | 163 |
| 165 if (result != mojom::PaymentComplete::SUCCESS) { | 164 if (result != mojom::PaymentComplete::SUCCESS) { |
| 166 delegate_->ShowErrorMessage(); | 165 delegate_->ShowErrorMessage(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 mojom::PaymentAddressPtr address) { | 218 mojom::PaymentAddressPtr address) { |
| 220 client_->OnShippingAddressChange(std::move(address)); | 219 client_->OnShippingAddressChange(std::move(address)); |
| 221 } | 220 } |
| 222 | 221 |
| 223 void PaymentRequest::UserCancelled() { | 222 void PaymentRequest::UserCancelled() { |
| 224 // If |client_| is not bound, then the object is already being destroyed as | 223 // If |client_| is not bound, then the object is already being destroyed as |
| 225 // a result of a renderer event. | 224 // a result of a renderer event. |
| 226 if (!client_.is_bound()) | 225 if (!client_.is_bound()) |
| 227 return; | 226 return; |
| 228 | 227 |
| 229 journey_logger_.RecordJourneyStatsHistograms( | 228 RecordFirstCompletionStatus(JourneyLogger::COMPLETION_STATUS_USER_ABORTED); |
| 230 JourneyLogger::COMPLETION_STATUS_USER_ABORTED); | |
| 231 | 229 |
| 232 // This sends an error to the renderer, which informs the API user. | 230 // This sends an error to the renderer, which informs the API user. |
| 233 client_->OnError(mojom::PaymentErrorReason::USER_CANCEL); | 231 client_->OnError(mojom::PaymentErrorReason::USER_CANCEL); |
| 234 | 232 |
| 235 // We close all bindings and ask to be destroyed. | 233 // We close all bindings and ask to be destroyed. |
| 236 client_.reset(); | 234 client_.reset(); |
| 237 binding_.Close(); | 235 binding_.Close(); |
| 238 if (observer_for_testing_) | 236 if (observer_for_testing_) |
| 239 observer_for_testing_->OnConnectionTerminated(); | 237 observer_for_testing_->OnConnectionTerminated(); |
| 240 manager_->DestroyRequest(this); | 238 manager_->DestroyRequest(this); |
| 241 } | 239 } |
| 242 | 240 |
| 241 void PaymentRequest::DidStartNavigation(bool is_user_initiated) { |
| 242 RecordFirstCompletionStatus( |
| 243 is_user_initiated ? JourneyLogger::COMPLETION_STATUS_USER_ABORTED |
| 244 : JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED); |
| 245 } |
| 246 |
| 243 void PaymentRequest::OnConnectionTerminated() { | 247 void PaymentRequest::OnConnectionTerminated() { |
| 244 // We are here because of a browser-side error, or likely as a result of the | 248 // We are here because of a browser-side error, or likely as a result of the |
| 245 // connection_error_handler on |binding_|, which can mean that the renderer | 249 // connection_error_handler on |binding_|, which can mean that the renderer |
| 246 // has decided to close the pipe for various reasons (see all uses of | 250 // has decided to close the pipe for various reasons (see all uses of |
| 247 // PaymentRequest::clearResolversAndCloseMojoConnection() in Blink). We close | 251 // PaymentRequest::clearResolversAndCloseMojoConnection() in Blink). We close |
| 248 // the binding and the dialog, and ask to be deleted. | 252 // the binding and the dialog, and ask to be deleted. |
| 249 client_.reset(); | 253 client_.reset(); |
| 250 binding_.Close(); | 254 binding_.Close(); |
| 251 delegate_->CloseDialog(); | 255 delegate_->CloseDialog(); |
| 252 if (observer_for_testing_) | 256 if (observer_for_testing_) |
| 253 observer_for_testing_->OnConnectionTerminated(); | 257 observer_for_testing_->OnConnectionTerminated(); |
| 254 manager_->DestroyRequest(this); | 258 manager_->DestroyRequest(this); |
| 255 } | 259 } |
| 256 | 260 |
| 257 void PaymentRequest::Pay() { | 261 void PaymentRequest::Pay() { |
| 258 state_->GeneratePaymentResponse(); | 262 state_->GeneratePaymentResponse(); |
| 259 } | 263 } |
| 260 | 264 |
| 265 void PaymentRequest::RecordFirstCompletionStatus( |
| 266 JourneyLogger::CompletionStatus completion_status) { |
| 267 if (!has_recorded_abort_reason_) { |
| 268 has_recorded_abort_reason_ = true; |
| 269 journey_logger_.RecordJourneyStatsHistograms(completion_status); |
| 270 } |
| 271 } |
| 272 |
| 261 } // namespace payments | 273 } // namespace payments |
| OLD | NEW |