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 "content/browser/payments/payment_app_database.h" | 5 #include "content/browser/payments/payment_app_database.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/optional.h" | 13 #include "base/optional.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "content/browser/payments/payment_app.pb.h" | 15 #include "content/browser/payments/payment_app.pb.h" |
16 #include "content/browser/payments/payment_app_context_impl.h" | 16 #include "content/browser/payments/payment_app_context_impl.h" |
17 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 17 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
18 #include "content/browser/service_worker/service_worker_registration.h" | 18 #include "content/browser/service_worker/service_worker_registration.h" |
19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/stored_payment_instrument.h" |
20 #include "third_party/skia/include/core/SkBitmap.h" | 21 #include "third_party/skia/include/core/SkBitmap.h" |
21 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
| 23 #include "url/gurl.h" |
| 24 #include "url/origin.h" |
22 | 25 |
23 namespace content { | 26 namespace content { |
24 namespace { | 27 namespace { |
25 | 28 |
26 using ::payments::mojom::PaymentHandlerStatus; | 29 using ::payments::mojom::PaymentHandlerStatus; |
27 using ::payments::mojom::PaymentInstrument; | 30 using ::payments::mojom::PaymentInstrument; |
28 using ::payments::mojom::PaymentInstrumentPtr; | 31 using ::payments::mojom::PaymentInstrumentPtr; |
29 | 32 |
| 33 const char kPaymentAppPrefix[] = "PaymentApp:"; |
30 const char kPaymentInstrumentPrefix[] = "PaymentInstrument:"; | 34 const char kPaymentInstrumentPrefix[] = "PaymentInstrument:"; |
31 const char kPaymentInstrumentKeyInfoPrefix[] = "PaymentInstrumentKeyInfo:"; | 35 const char kPaymentInstrumentKeyInfoPrefix[] = "PaymentInstrumentKeyInfo:"; |
32 | 36 |
| 37 std::string CreatePaymentAppKey(const std::string& origin) { |
| 38 return kPaymentAppPrefix + origin; |
| 39 } |
| 40 |
33 std::string CreatePaymentInstrumentKey(const std::string& instrument_key) { | 41 std::string CreatePaymentInstrumentKey(const std::string& instrument_key) { |
34 return kPaymentInstrumentPrefix + instrument_key; | 42 return kPaymentInstrumentPrefix + instrument_key; |
35 } | 43 } |
36 | 44 |
37 std::string CreatePaymentInstrumentKeyInfoKey( | 45 std::string CreatePaymentInstrumentKeyInfoKey( |
38 const std::string& instrument_key) { | 46 const std::string& instrument_key) { |
39 return kPaymentInstrumentKeyInfoPrefix + instrument_key; | 47 return kPaymentInstrumentKeyInfoPrefix + instrument_key; |
40 } | 48 } |
41 | 49 |
42 std::map<uint64_t, std::string> ToStoredPaymentInstrumentKeyInfos( | 50 std::map<uint64_t, std::string> ToStoredPaymentInstrumentKeyInfos( |
(...skipping 23 matching lines...) Expand all Loading... |
66 payments::mojom::ImageObject::New(GURL(icon.src()))); | 74 payments::mojom::ImageObject::New(GURL(icon.src()))); |
67 } | 75 } |
68 for (const auto& method : instrument_proto.enabled_methods()) | 76 for (const auto& method : instrument_proto.enabled_methods()) |
69 instrument->enabled_methods.push_back(method); | 77 instrument->enabled_methods.push_back(method); |
70 instrument->stringified_capabilities = | 78 instrument->stringified_capabilities = |
71 instrument_proto.stringified_capabilities(); | 79 instrument_proto.stringified_capabilities(); |
72 | 80 |
73 return instrument; | 81 return instrument; |
74 } | 82 } |
75 | 83 |
| 84 std::unique_ptr<StoredPaymentApp> ToStoredPaymentApp(const std::string& input) { |
| 85 StoredPaymentAppProto app_proto; |
| 86 if (!app_proto.ParseFromString(input)) |
| 87 return std::unique_ptr<StoredPaymentApp>(); |
| 88 |
| 89 std::unique_ptr<StoredPaymentApp> app = base::MakeUnique<StoredPaymentApp>(); |
| 90 app->registration_id = app_proto.registration_id(); |
| 91 app->origin = url::Origin(GURL(app_proto.origin())); |
| 92 app->name = app_proto.name(); |
| 93 |
| 94 if (!app_proto.icon().empty()) { |
| 95 std::string icon_raw_data; |
| 96 base::Base64Decode(app_proto.icon(), &icon_raw_data); |
| 97 // Note that the icon has been decoded to PNG raw data regardless of the |
| 98 // original icon format that was downloaded. |
| 99 gfx::Image icon_image = gfx::Image::CreateFrom1xPNGBytes( |
| 100 reinterpret_cast<const unsigned char*>(icon_raw_data.data()), |
| 101 icon_raw_data.size()); |
| 102 app->icon = base::MakeUnique<SkBitmap>(icon_image.AsBitmap()); |
| 103 } |
| 104 |
| 105 return app; |
| 106 } |
| 107 |
76 std::unique_ptr<StoredPaymentInstrument> ToStoredPaymentInstrument( | 108 std::unique_ptr<StoredPaymentInstrument> ToStoredPaymentInstrument( |
77 const std::string& input) { | 109 const std::string& input) { |
78 StoredPaymentInstrumentProto instrument_proto; | 110 StoredPaymentInstrumentProto instrument_proto; |
79 if (!instrument_proto.ParseFromString(input)) | 111 if (!instrument_proto.ParseFromString(input)) |
80 return std::unique_ptr<StoredPaymentInstrument>(); | 112 return std::unique_ptr<StoredPaymentInstrument>(); |
81 | 113 |
82 std::unique_ptr<StoredPaymentInstrument> instrument = | 114 std::unique_ptr<StoredPaymentInstrument> instrument = |
83 base::MakeUnique<StoredPaymentInstrument>(); | 115 base::MakeUnique<StoredPaymentInstrument>(); |
84 instrument->registration_id = instrument_proto.registration_id(); | |
85 instrument->instrument_key = instrument_proto.instrument_key(); | 116 instrument->instrument_key = instrument_proto.instrument_key(); |
86 instrument->origin = GURL(instrument_proto.origin()); | 117 instrument->origin = GURL(instrument_proto.origin()); |
87 instrument->name = instrument_proto.name(); | 118 instrument->name = instrument_proto.name(); |
88 | 119 |
89 if (!instrument_proto.decoded_instrument_icon().empty()) { | 120 if (!instrument_proto.decoded_instrument_icon().empty()) { |
90 std::string icon_raw_data; | 121 std::string icon_raw_data; |
91 base::Base64Decode(instrument_proto.decoded_instrument_icon(), | 122 base::Base64Decode(instrument_proto.decoded_instrument_icon(), |
92 &icon_raw_data); | 123 &icon_raw_data); |
93 // Note that the icon has been decoded to PNG raw data regardless of the | 124 // Note that the icon has been decoded to PNG raw data regardless of the |
94 // original icon format that was downloaded. | 125 // original icon format that was downloaded. |
(...skipping 18 matching lines...) Expand all Loading... |
113 | 144 |
114 PaymentAppDatabase::~PaymentAppDatabase() { | 145 PaymentAppDatabase::~PaymentAppDatabase() { |
115 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 146 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
116 } | 147 } |
117 | 148 |
118 void PaymentAppDatabase::ReadAllPaymentApps( | 149 void PaymentAppDatabase::ReadAllPaymentApps( |
119 ReadAllPaymentAppsCallback callback) { | 150 ReadAllPaymentAppsCallback callback) { |
120 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 151 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
121 | 152 |
122 service_worker_context_->GetUserDataForAllRegistrationsByKeyPrefix( | 153 service_worker_context_->GetUserDataForAllRegistrationsByKeyPrefix( |
123 kPaymentInstrumentPrefix, | 154 kPaymentAppPrefix, base::Bind(&PaymentAppDatabase::DidReadAllPaymentApps, |
124 base::Bind(&PaymentAppDatabase::DidReadAllPaymentApps, | 155 weak_ptr_factory_.GetWeakPtr(), |
125 weak_ptr_factory_.GetWeakPtr(), | 156 base::Passed(std::move(callback)))); |
126 base::Passed(std::move(callback)))); | |
127 } | 157 } |
128 | 158 |
129 void PaymentAppDatabase::DeletePaymentInstrument( | 159 void PaymentAppDatabase::DeletePaymentInstrument( |
130 const GURL& scope, | 160 const GURL& scope, |
131 const std::string& instrument_key, | 161 const std::string& instrument_key, |
132 DeletePaymentInstrumentCallback callback) { | 162 DeletePaymentInstrumentCallback callback) { |
133 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 163 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
134 | 164 |
135 service_worker_context_->FindReadyRegistrationForPattern( | 165 service_worker_context_->FindReadyRegistrationForPattern( |
136 scope, | 166 scope, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 | 251 |
222 service_worker_context_->FindReadyRegistrationForPattern( | 252 service_worker_context_->FindReadyRegistrationForPattern( |
223 scope, | 253 scope, |
224 base::Bind( | 254 base::Bind( |
225 &PaymentAppDatabase::DidFindRegistrationToWritePaymentInstrument, | 255 &PaymentAppDatabase::DidFindRegistrationToWritePaymentInstrument, |
226 weak_ptr_factory_.GetWeakPtr(), instrument_key, | 256 weak_ptr_factory_.GetWeakPtr(), instrument_key, |
227 base::Passed(std::move(instrument)), icon, | 257 base::Passed(std::move(instrument)), icon, |
228 base::Passed(std::move(callback)))); | 258 base::Passed(std::move(callback)))); |
229 } | 259 } |
230 | 260 |
| 261 void PaymentAppDatabase::FetchAndWritePaymentAppInfo( |
| 262 const GURL& context, |
| 263 const GURL& scope, |
| 264 FetchAndWritePaymentAppInfoCallback callback) { |
| 265 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 266 |
| 267 payment_app_info_fetcher_ = new PaymentAppInfoFetcher(); |
| 268 payment_app_info_fetcher_->Start( |
| 269 context, service_worker_context_, |
| 270 base::BindOnce(&PaymentAppDatabase::FetchPaymentAppInfoCallback, |
| 271 weak_ptr_factory_.GetWeakPtr(), scope, |
| 272 std::move(callback))); |
| 273 } |
| 274 |
| 275 void PaymentAppDatabase::FetchPaymentAppInfoCallback( |
| 276 const GURL& scope, |
| 277 FetchAndWritePaymentAppInfoCallback callback, |
| 278 const std::string& name, |
| 279 const std::string& icon) { |
| 280 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 281 |
| 282 payment_app_info_fetcher_ = nullptr; |
| 283 |
| 284 service_worker_context_->FindReadyRegistrationForPattern( |
| 285 scope, |
| 286 base::Bind(&PaymentAppDatabase::DidFindRegistrationToWritePaymentAppInfo, |
| 287 weak_ptr_factory_.GetWeakPtr(), |
| 288 base::Passed(std::move(callback)), name, icon)); |
| 289 } |
| 290 |
| 291 void PaymentAppDatabase::DidFindRegistrationToWritePaymentAppInfo( |
| 292 FetchAndWritePaymentAppInfoCallback callback, |
| 293 const std::string& name, |
| 294 const std::string& icon, |
| 295 ServiceWorkerStatusCode status, |
| 296 scoped_refptr<ServiceWorkerRegistration> registration) { |
| 297 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 298 if (status != SERVICE_WORKER_OK) { |
| 299 std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER); |
| 300 return; |
| 301 } |
| 302 |
| 303 StoredPaymentAppProto payment_app_proto; |
| 304 payment_app_proto.set_registration_id(registration->id()); |
| 305 payment_app_proto.set_origin(registration->pattern().GetOrigin().spec()); |
| 306 payment_app_proto.set_name(name.empty() ? payment_app_proto.origin() : name); |
| 307 payment_app_proto.set_icon(icon); |
| 308 |
| 309 std::string serialized_payment_app; |
| 310 bool success = payment_app_proto.SerializeToString(&serialized_payment_app); |
| 311 DCHECK(success); |
| 312 |
| 313 service_worker_context_->StoreRegistrationUserData( |
| 314 registration->id(), registration->pattern().GetOrigin(), |
| 315 {{CreatePaymentAppKey(registration->pattern().GetOrigin().spec()), |
| 316 serialized_payment_app}}, |
| 317 base::Bind(&PaymentAppDatabase::DidWritePaymentApp, |
| 318 weak_ptr_factory_.GetWeakPtr(), |
| 319 base::Passed(std::move(callback)), |
| 320 name.empty() | icon.empty())); |
| 321 } |
| 322 |
| 323 void PaymentAppDatabase::DidWritePaymentApp( |
| 324 FetchAndWritePaymentAppInfoCallback callback, |
| 325 bool fetch_app_info_failed, |
| 326 ServiceWorkerStatusCode status) { |
| 327 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 328 |
| 329 PaymentHandlerStatus handler_status = |
| 330 fetch_app_info_failed |
| 331 ? PaymentHandlerStatus::FETCH_PAYMENT_APP_INFO_FAILED |
| 332 : PaymentHandlerStatus::SUCCESS; |
| 333 handler_status = status == SERVICE_WORKER_OK |
| 334 ? handler_status |
| 335 : PaymentHandlerStatus::STORAGE_OPERATION_FAILED; |
| 336 return std::move(callback).Run(handler_status); |
| 337 } |
| 338 |
231 void PaymentAppDatabase::ClearPaymentInstruments( | 339 void PaymentAppDatabase::ClearPaymentInstruments( |
232 const GURL& scope, | 340 const GURL& scope, |
233 ClearPaymentInstrumentsCallback callback) { | 341 ClearPaymentInstrumentsCallback callback) { |
234 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 342 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
235 | 343 |
236 service_worker_context_->FindReadyRegistrationForPattern( | 344 service_worker_context_->FindReadyRegistrationForPattern( |
237 scope, | 345 scope, |
238 base::Bind( | 346 base::Bind( |
239 &PaymentAppDatabase::DidFindRegistrationToClearPaymentInstruments, | 347 &PaymentAppDatabase::DidFindRegistrationToClearPaymentInstruments, |
240 weak_ptr_factory_.GetWeakPtr(), scope, | 348 weak_ptr_factory_.GetWeakPtr(), scope, |
241 base::Passed(std::move(callback)))); | 349 base::Passed(std::move(callback)))); |
242 } | 350 } |
243 | 351 |
244 void PaymentAppDatabase::DidReadAllPaymentApps( | 352 void PaymentAppDatabase::DidReadAllPaymentApps( |
245 ReadAllPaymentAppsCallback callback, | 353 ReadAllPaymentAppsCallback callback, |
246 const std::vector<std::pair<int64_t, std::string>>& raw_data, | 354 const std::vector<std::pair<int64_t, std::string>>& raw_data, |
247 ServiceWorkerStatusCode status) { | 355 ServiceWorkerStatusCode status) { |
248 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 356 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
249 if (status != SERVICE_WORKER_OK) { | 357 if (status != SERVICE_WORKER_OK) { |
250 std::move(callback).Run(PaymentApps()); | 358 std::move(callback).Run(PaymentApps()); |
251 return; | 359 return; |
252 } | 360 } |
253 | 361 |
254 PaymentApps apps; | 362 PaymentApps apps; |
255 for (const auto& item_of_raw_data : raw_data) { | 363 for (const auto& item_of_raw_data : raw_data) { |
| 364 std::unique_ptr<StoredPaymentApp> app = |
| 365 ToStoredPaymentApp(item_of_raw_data.second); |
| 366 if (app) |
| 367 apps[app->origin.GetURL()] = std::move(app); |
| 368 } |
| 369 |
| 370 if (apps.size() == 0U) { |
| 371 std::move(callback).Run(PaymentApps()); |
| 372 return; |
| 373 } |
| 374 |
| 375 service_worker_context_->GetUserDataForAllRegistrationsByKeyPrefix( |
| 376 kPaymentInstrumentPrefix, |
| 377 base::Bind(&PaymentAppDatabase::DidReadAllPaymentInstruments, |
| 378 weak_ptr_factory_.GetWeakPtr(), base::Passed(std::move(apps)), |
| 379 base::Passed(std::move(callback)))); |
| 380 } |
| 381 |
| 382 void PaymentAppDatabase::DidReadAllPaymentInstruments( |
| 383 PaymentApps apps, |
| 384 ReadAllPaymentAppsCallback callback, |
| 385 const std::vector<std::pair<int64_t, std::string>>& raw_data, |
| 386 ServiceWorkerStatusCode status) { |
| 387 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 388 if (status != SERVICE_WORKER_OK) { |
| 389 std::move(callback).Run(std::move(apps)); |
| 390 return; |
| 391 } |
| 392 |
| 393 for (const auto& item_of_raw_data : raw_data) { |
256 std::unique_ptr<StoredPaymentInstrument> instrument = | 394 std::unique_ptr<StoredPaymentInstrument> instrument = |
257 ToStoredPaymentInstrument(item_of_raw_data.second); | 395 ToStoredPaymentInstrument(item_of_raw_data.second); |
258 if (!instrument) | 396 if (!instrument || !base::ContainsKey(apps, instrument->origin)) |
259 continue; | 397 continue; |
260 if (!base::ContainsKey(apps, instrument->origin)) | 398 apps[instrument->origin]->instruments.push_back(std::move(instrument)); |
261 apps.insert(std::make_pair(instrument->origin, Instruments())); | |
262 apps[instrument->origin].push_back(std::move(instrument)); | |
263 } | 399 } |
264 | 400 |
265 std::move(callback).Run(std::move(apps)); | 401 std::move(callback).Run(std::move(apps)); |
266 } | 402 } |
267 | 403 |
268 void PaymentAppDatabase::DidFindRegistrationToDeletePaymentInstrument( | 404 void PaymentAppDatabase::DidFindRegistrationToDeletePaymentInstrument( |
269 const std::string& instrument_key, | 405 const std::string& instrument_key, |
270 DeletePaymentInstrumentCallback callback, | 406 DeletePaymentInstrumentCallback callback, |
271 ServiceWorkerStatusCode status, | 407 ServiceWorkerStatusCode status, |
272 scoped_refptr<ServiceWorkerRegistration> registration) { | 408 scoped_refptr<ServiceWorkerRegistration> registration) { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 ServiceWorkerStatusCode status, | 565 ServiceWorkerStatusCode status, |
430 scoped_refptr<ServiceWorkerRegistration> registration) { | 566 scoped_refptr<ServiceWorkerRegistration> registration) { |
431 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 567 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
432 if (status != SERVICE_WORKER_OK) { | 568 if (status != SERVICE_WORKER_OK) { |
433 std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER); | 569 std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER); |
434 return; | 570 return; |
435 } | 571 } |
436 | 572 |
437 StoredPaymentInstrumentProto instrument_proto; | 573 StoredPaymentInstrumentProto instrument_proto; |
438 instrument_proto.set_decoded_instrument_icon(decoded_instrument_icon); | 574 instrument_proto.set_decoded_instrument_icon(decoded_instrument_icon); |
439 instrument_proto.set_registration_id(registration->id()); | |
440 instrument_proto.set_instrument_key(instrument_key); | 575 instrument_proto.set_instrument_key(instrument_key); |
441 instrument_proto.set_origin(registration->pattern().GetOrigin().spec()); | 576 instrument_proto.set_origin(registration->pattern().GetOrigin().spec()); |
442 instrument_proto.set_name(instrument->name); | 577 instrument_proto.set_name(instrument->name); |
443 for (const auto& method : instrument->enabled_methods) { | 578 for (const auto& method : instrument->enabled_methods) { |
444 instrument_proto.add_enabled_methods(method); | 579 instrument_proto.add_enabled_methods(method); |
445 } | 580 } |
446 for (const auto& image_object : instrument->icons) { | 581 for (const auto& image_object : instrument->icons) { |
447 StoredPaymentInstrumentImageObject* image_object_proto = | 582 StoredPaymentInstrumentImageObject* image_object_proto = |
448 instrument_proto.add_icons(); | 583 instrument_proto.add_icons(); |
449 image_object_proto->set_src(image_object->src.spec()); | 584 image_object_proto->set_src(image_object->src.spec()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 626 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
492 | 627 |
493 if (status != SERVICE_WORKER_OK) { | 628 if (status != SERVICE_WORKER_OK) { |
494 std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER); | 629 std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER); |
495 return; | 630 return; |
496 } | 631 } |
497 | 632 |
498 KeysOfPaymentInstruments( | 633 KeysOfPaymentInstruments( |
499 scope, | 634 scope, |
500 base::BindOnce(&PaymentAppDatabase::DidGetKeysToClearPaymentInstruments, | 635 base::BindOnce(&PaymentAppDatabase::DidGetKeysToClearPaymentInstruments, |
501 weak_ptr_factory_.GetWeakPtr(), registration->id(), | 636 weak_ptr_factory_.GetWeakPtr(), std::move(registration), |
502 std::move(callback))); | 637 std::move(callback))); |
503 } | 638 } |
504 | 639 |
505 void PaymentAppDatabase::DidGetKeysToClearPaymentInstruments( | 640 void PaymentAppDatabase::DidGetKeysToClearPaymentInstruments( |
506 int64_t registration_id, | 641 scoped_refptr<ServiceWorkerRegistration> registration, |
507 ClearPaymentInstrumentsCallback callback, | 642 ClearPaymentInstrumentsCallback callback, |
508 const std::vector<std::string>& keys, | 643 const std::vector<std::string>& keys, |
509 PaymentHandlerStatus status) { | 644 PaymentHandlerStatus status) { |
510 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 645 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
511 | 646 |
512 if (status != PaymentHandlerStatus::SUCCESS) { | 647 if (status != PaymentHandlerStatus::SUCCESS) { |
513 std::move(callback).Run(PaymentHandlerStatus::NOT_FOUND); | 648 std::move(callback).Run(PaymentHandlerStatus::NOT_FOUND); |
514 return; | 649 return; |
515 } | 650 } |
516 | 651 |
517 std::vector<std::string> keys_with_prefix; | 652 std::vector<std::string> keys_with_prefix; |
518 for (const auto& key : keys) { | 653 for (const auto& key : keys) { |
519 keys_with_prefix.push_back(CreatePaymentInstrumentKey(key)); | 654 keys_with_prefix.push_back(CreatePaymentInstrumentKey(key)); |
520 keys_with_prefix.push_back(CreatePaymentInstrumentKeyInfoKey(key)); | 655 keys_with_prefix.push_back(CreatePaymentInstrumentKeyInfoKey(key)); |
521 } | 656 } |
522 | 657 |
| 658 // Clear payment app info after clearing all payment instruments. |
| 659 keys_with_prefix.push_back( |
| 660 CreatePaymentAppKey(registration->pattern().GetOrigin().spec())); |
| 661 |
523 service_worker_context_->ClearRegistrationUserData( | 662 service_worker_context_->ClearRegistrationUserData( |
524 registration_id, keys_with_prefix, | 663 registration->id(), keys_with_prefix, |
525 base::Bind(&PaymentAppDatabase::DidClearPaymentInstruments, | 664 base::Bind(&PaymentAppDatabase::DidClearPaymentInstruments, |
526 weak_ptr_factory_.GetWeakPtr(), | 665 weak_ptr_factory_.GetWeakPtr(), |
527 base::Passed(std::move(callback)))); | 666 base::Passed(std::move(callback)))); |
528 } | 667 } |
529 | 668 |
530 void PaymentAppDatabase::DidClearPaymentInstruments( | 669 void PaymentAppDatabase::DidClearPaymentInstruments( |
531 ClearPaymentInstrumentsCallback callback, | 670 ClearPaymentInstrumentsCallback callback, |
532 ServiceWorkerStatusCode status) { | 671 ServiceWorkerStatusCode status) { |
533 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 672 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
534 return std::move(callback).Run(status == SERVICE_WORKER_OK | 673 return std::move(callback).Run(status == SERVICE_WORKER_OK |
535 ? PaymentHandlerStatus::SUCCESS | 674 ? PaymentHandlerStatus::SUCCESS |
536 : PaymentHandlerStatus::NOT_FOUND); | 675 : PaymentHandlerStatus::NOT_FOUND); |
537 } | 676 } |
538 | 677 |
539 } // namespace content | 678 } // namespace content |
OLD | NEW |