| 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 149 |
| 150 void PaymentRequest::Abort() { | 150 void PaymentRequest::Abort() { |
| 151 // The API user has decided to abort. If a successful abort message is | 151 // The API user has decided to abort. If a successful abort message is |
| 152 // returned to the renderer, the Mojo message pipe is closed, which triggers | 152 // returned to the renderer, the Mojo message pipe is closed, which triggers |
| 153 // PaymentRequest::OnConnectionTerminated, which destroys this object. | 153 // PaymentRequest::OnConnectionTerminated, which destroys this object. |
| 154 // Otherwise, the abort promise is rejected and the pipe is not closed. | 154 // Otherwise, the abort promise is rejected and the pipe is not closed. |
| 155 // The abort is only successful if the payment app wasn't yet invoked. | 155 // The abort is only successful if the payment app wasn't yet invoked. |
| 156 // TODO(crbug.com/716546): Add a merchant abort metric | 156 // TODO(crbug.com/716546): Add a merchant abort metric |
| 157 | 157 |
| 158 bool accepting_abort = !state_->IsPaymentAppInvoked(); | 158 bool accepting_abort = !state_->IsPaymentAppInvoked(); |
| 159 if (accepting_abort) { | 159 if (accepting_abort) |
| 160 RecordFirstCompletionStatus(JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED); | 160 RecordFirstAbortReason(JourneyLogger::ABORT_REASON_ABORTED_BY_MERCHANT); |
| 161 } | |
| 162 | 161 |
| 163 if (client_.is_bound()) | 162 if (client_.is_bound()) |
| 164 client_->OnAbort(accepting_abort); | 163 client_->OnAbort(accepting_abort); |
| 165 | 164 |
| 166 if (observer_for_testing_) | 165 if (observer_for_testing_) |
| 167 observer_for_testing_->OnAbortCalled(); | 166 observer_for_testing_->OnAbortCalled(); |
| 168 } | 167 } |
| 169 | 168 |
| 170 void PaymentRequest::Complete(mojom::PaymentComplete result) { | 169 void PaymentRequest::Complete(mojom::PaymentComplete result) { |
| 171 if (!client_.is_bound()) | 170 if (!client_.is_bound()) |
| 172 return; | 171 return; |
| 173 | 172 |
| 174 if (result != mojom::PaymentComplete::SUCCESS) { | 173 if (result != mojom::PaymentComplete::SUCCESS) { |
| 175 delegate_->ShowErrorMessage(); | 174 delegate_->ShowErrorMessage(); |
| 176 } else { | 175 } else { |
| 176 DCHECK(!has_recorded_completion_); |
| 177 journey_logger_.SetCompleted(); | 177 journey_logger_.SetCompleted(); |
| 178 has_recorded_completion_ = true; |
| 179 |
| 178 delegate_->GetPrefService()->SetBoolean(kPaymentsFirstTransactionCompleted, | 180 delegate_->GetPrefService()->SetBoolean(kPaymentsFirstTransactionCompleted, |
| 179 true); | 181 true); |
| 180 // When the renderer closes the connection, | 182 // When the renderer closes the connection, |
| 181 // PaymentRequest::OnConnectionTerminated will be called. | 183 // PaymentRequest::OnConnectionTerminated will be called. |
| 182 client_->OnComplete(); | 184 client_->OnComplete(); |
| 183 state_->RecordUseStats(); | 185 state_->RecordUseStats(); |
| 184 } | 186 } |
| 185 } | 187 } |
| 186 | 188 |
| 187 void PaymentRequest::CanMakePayment() { | 189 void PaymentRequest::CanMakePayment() { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 mojom::PaymentAddressPtr address) { | 229 mojom::PaymentAddressPtr address) { |
| 228 client_->OnShippingAddressChange(std::move(address)); | 230 client_->OnShippingAddressChange(std::move(address)); |
| 229 } | 231 } |
| 230 | 232 |
| 231 void PaymentRequest::UserCancelled() { | 233 void PaymentRequest::UserCancelled() { |
| 232 // If |client_| is not bound, then the object is already being destroyed as | 234 // If |client_| is not bound, then the object is already being destroyed as |
| 233 // a result of a renderer event. | 235 // a result of a renderer event. |
| 234 if (!client_.is_bound()) | 236 if (!client_.is_bound()) |
| 235 return; | 237 return; |
| 236 | 238 |
| 237 RecordFirstCompletionStatus(JourneyLogger::COMPLETION_STATUS_USER_ABORTED); | 239 RecordFirstAbortReason(JourneyLogger::ABORT_REASON_ABORTED_BY_USER); |
| 238 | 240 |
| 239 // This sends an error to the renderer, which informs the API user. | 241 // This sends an error to the renderer, which informs the API user. |
| 240 client_->OnError(mojom::PaymentErrorReason::USER_CANCEL); | 242 client_->OnError(mojom::PaymentErrorReason::USER_CANCEL); |
| 241 | 243 |
| 242 // We close all bindings and ask to be destroyed. | 244 // We close all bindings and ask to be destroyed. |
| 243 client_.reset(); | 245 client_.reset(); |
| 244 binding_.Close(); | 246 binding_.Close(); |
| 245 if (observer_for_testing_) | 247 if (observer_for_testing_) |
| 246 observer_for_testing_->OnConnectionTerminated(); | 248 observer_for_testing_->OnConnectionTerminated(); |
| 247 manager_->DestroyRequest(this); | 249 manager_->DestroyRequest(this); |
| 248 } | 250 } |
| 249 | 251 |
| 250 void PaymentRequest::DidStartNavigation(bool is_user_initiated) { | 252 void PaymentRequest::DidStartNavigation(bool is_user_initiated) { |
| 251 RecordFirstCompletionStatus( | 253 RecordFirstAbortReason(is_user_initiated |
| 252 is_user_initiated ? JourneyLogger::COMPLETION_STATUS_USER_ABORTED | 254 ? JourneyLogger::ABORT_REASON_USER_NAVIGATION |
| 253 : JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED); | 255 : JourneyLogger::ABORT_REASON_MERCHANT_NAVIGATION); |
| 254 } | 256 } |
| 255 | 257 |
| 256 void PaymentRequest::OnConnectionTerminated() { | 258 void PaymentRequest::OnConnectionTerminated() { |
| 257 // We are here because of a browser-side error, or likely as a result of the | 259 // We are here because of a browser-side error, or likely as a result of the |
| 258 // connection_error_handler on |binding_|, which can mean that the renderer | 260 // connection_error_handler on |binding_|, which can mean that the renderer |
| 259 // has decided to close the pipe for various reasons (see all uses of | 261 // has decided to close the pipe for various reasons (see all uses of |
| 260 // PaymentRequest::clearResolversAndCloseMojoConnection() in Blink). We close | 262 // PaymentRequest::clearResolversAndCloseMojoConnection() in Blink). We close |
| 261 // the binding and the dialog, and ask to be deleted. | 263 // the binding and the dialog, and ask to be deleted. |
| 262 client_.reset(); | 264 client_.reset(); |
| 263 binding_.Close(); | 265 binding_.Close(); |
| 264 delegate_->CloseDialog(); | 266 delegate_->CloseDialog(); |
| 265 if (observer_for_testing_) | 267 if (observer_for_testing_) |
| 266 observer_for_testing_->OnConnectionTerminated(); | 268 observer_for_testing_->OnConnectionTerminated(); |
| 269 |
| 270 RecordFirstAbortReason(JourneyLogger::ABORT_REASON_MOJO_CONNECTION_ERROR); |
| 267 manager_->DestroyRequest(this); | 271 manager_->DestroyRequest(this); |
| 268 } | 272 } |
| 269 | 273 |
| 270 void PaymentRequest::Pay() { | 274 void PaymentRequest::Pay() { |
| 271 state_->GeneratePaymentResponse(); | 275 state_->GeneratePaymentResponse(); |
| 272 } | 276 } |
| 273 | 277 |
| 274 void PaymentRequest::RecordFirstCompletionStatus( | 278 void PaymentRequest::RecordFirstAbortReason( |
| 275 JourneyLogger::CompletionStatus completion_status) { | 279 JourneyLogger::AbortReason abort_reason) { |
| 276 if (!has_recorded_abort_reason_) { | 280 if (!has_recorded_completion_) { |
| 277 has_recorded_abort_reason_ = true; | 281 has_recorded_completion_ = true; |
| 278 // TODO(crbug.com/716546): Record more abort reasons. | 282 journey_logger_.SetAborted(abort_reason); |
| 279 if (completion_status == JourneyLogger::COMPLETION_STATUS_USER_ABORTED) { | |
| 280 journey_logger_.SetAborted(JourneyLogger::ABORT_REASON_ABORTED_BY_USER); | |
| 281 } else { | |
| 282 journey_logger_.SetAborted(JourneyLogger::ABORT_REASON_OTHER); | |
| 283 } | |
| 284 } | 283 } |
| 285 } | 284 } |
| 286 | 285 |
| 287 } // namespace payments | 286 } // namespace payments |
| OLD | NEW |