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

Side by Side Diff: content/browser/payments/payment_app_database.cc

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

Powered by Google App Engine
This is Rietveld 408576698