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

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

Issue 2866063004: payment app android
Patch Set: payment app android 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 "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/bind.h" 10 #include "base/bind.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 return key_info; 77 return key_info;
78 } 78 }
79 79
80 PaymentInstrumentPtr DeserializePaymentInstrument(const std::string& input) { 80 PaymentInstrumentPtr DeserializePaymentInstrument(const std::string& input) {
81 PaymentInstrumentProto instrument_proto; 81 PaymentInstrumentProto instrument_proto;
82 if (!instrument_proto.ParseFromString(input)) 82 if (!instrument_proto.ParseFromString(input))
83 return nullptr; 83 return nullptr;
84 84
85 PaymentInstrumentPtr instrument = PaymentInstrument::New(); 85 PaymentInstrumentPtr instrument = PaymentInstrument::New();
86 instrument->registration_id = instrument_proto.registration_id();
87 instrument->instrument_key = instrument_proto.instrument_key();
88 instrument->origin = GURL(instrument_proto.origin());
86 instrument->name = instrument_proto.name(); 89 instrument->name = instrument_proto.name();
87 for (const auto& method : instrument_proto.enabled_methods()) 90 for (const auto& method : instrument_proto.enabled_methods())
88 instrument->enabled_methods.push_back(method); 91 instrument->enabled_methods.push_back(method);
89 instrument->stringified_capabilities = 92 instrument->stringified_capabilities =
90 instrument_proto.stringified_capabilities(); 93 instrument_proto.stringified_capabilities();
91 94
92 return instrument; 95 return instrument;
93 } 96 }
94 97
95 } // namespace 98 } // namespace
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 void PaymentAppDatabase::ReadAllManifests( 131 void PaymentAppDatabase::ReadAllManifests(
129 const ReadAllManifestsCallback& callback) { 132 const ReadAllManifestsCallback& callback) {
130 DCHECK_CURRENTLY_ON(BrowserThread::IO); 133 DCHECK_CURRENTLY_ON(BrowserThread::IO);
131 134
132 service_worker_context_->GetUserDataForAllRegistrations( 135 service_worker_context_->GetUserDataForAllRegistrations(
133 kPaymentAppManifestDataKey, 136 kPaymentAppManifestDataKey,
134 base::Bind(&PaymentAppDatabase::DidReadAllManifests, 137 base::Bind(&PaymentAppDatabase::DidReadAllManifests,
135 weak_ptr_factory_.GetWeakPtr(), callback)); 138 weak_ptr_factory_.GetWeakPtr(), callback));
136 } 139 }
137 140
141 void PaymentAppDatabase::ReadAllPaymentApps(
142 ReadAllPaymentAppsCallback callback) {
143 DCHECK_CURRENTLY_ON(BrowserThread::IO);
144
145 service_worker_context_->GetUserDataForAllRegistrationsByKeyPrefix(
146 kPaymentInstrumentPrefix,
147 base::Bind(&PaymentAppDatabase::DidReadAllPaymentApps,
148 weak_ptr_factory_.GetWeakPtr(),
149 base::Passed(std::move(callback))));
150 }
151
138 void PaymentAppDatabase::DeletePaymentInstrument( 152 void PaymentAppDatabase::DeletePaymentInstrument(
139 const GURL& scope, 153 const GURL& scope,
140 const std::string& instrument_key, 154 const std::string& instrument_key,
141 DeletePaymentInstrumentCallback callback) { 155 DeletePaymentInstrumentCallback callback) {
142 DCHECK_CURRENTLY_ON(BrowserThread::IO); 156 DCHECK_CURRENTLY_ON(BrowserThread::IO);
143 157
144 service_worker_context_->FindReadyRegistrationForPattern( 158 service_worker_context_->FindReadyRegistrationForPattern(
145 scope, 159 scope,
146 base::Bind( 160 base::Bind(
147 &PaymentAppDatabase::DidFindRegistrationToDeletePaymentInstrument, 161 &PaymentAppDatabase::DidFindRegistrationToDeletePaymentInstrument,
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 if (!manifest) 335 if (!manifest)
322 continue; 336 continue;
323 337
324 manifests.push_back( 338 manifests.push_back(
325 ManifestWithID(item_of_raw_data.first, std::move(manifest))); 339 ManifestWithID(item_of_raw_data.first, std::move(manifest)));
326 } 340 }
327 341
328 callback.Run(std::move(manifests)); 342 callback.Run(std::move(manifests));
329 } 343 }
330 344
345 void PaymentAppDatabase::DidReadAllPaymentApps(
346 ReadAllPaymentAppsCallback callback,
347 const std::vector<std::pair<int64_t, std::string>>& raw_data,
348 ServiceWorkerStatusCode status) {
349 DCHECK_CURRENTLY_ON(BrowserThread::IO);
350 if (status != SERVICE_WORKER_OK) {
351 std::move(callback).Run(PaymentApps());
352 return;
353 }
354
355 PaymentApps apps;
356 for (const auto& item_of_raw_data : raw_data) {
357 PaymentInstrumentPtr instrument =
358 DeserializePaymentInstrument(item_of_raw_data.second);
359 if (!instrument)
360 continue;
361 if (!base::ContainsKey(apps, instrument->origin))
362 apps.insert(std::make_pair(instrument->origin, Instruments()));
363 apps[instrument->origin].push_back(std::move(instrument));
364 }
365
366 std::move(callback).Run(std::move(apps));
367 }
368
331 void PaymentAppDatabase::DidFindRegistrationToDeletePaymentInstrument( 369 void PaymentAppDatabase::DidFindRegistrationToDeletePaymentInstrument(
332 const std::string& instrument_key, 370 const std::string& instrument_key,
333 DeletePaymentInstrumentCallback callback, 371 DeletePaymentInstrumentCallback callback,
334 ServiceWorkerStatusCode status, 372 ServiceWorkerStatusCode status,
335 scoped_refptr<ServiceWorkerRegistration> registration) { 373 scoped_refptr<ServiceWorkerRegistration> registration) {
336 DCHECK_CURRENTLY_ON(BrowserThread::IO); 374 DCHECK_CURRENTLY_ON(BrowserThread::IO);
337 if (status != SERVICE_WORKER_OK) { 375 if (status != SERVICE_WORKER_OK) {
338 std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER); 376 std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER);
339 return; 377 return;
340 } 378 }
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 WritePaymentInstrumentCallback callback, 530 WritePaymentInstrumentCallback callback,
493 ServiceWorkerStatusCode status, 531 ServiceWorkerStatusCode status,
494 scoped_refptr<ServiceWorkerRegistration> registration) { 532 scoped_refptr<ServiceWorkerRegistration> registration) {
495 DCHECK_CURRENTLY_ON(BrowserThread::IO); 533 DCHECK_CURRENTLY_ON(BrowserThread::IO);
496 if (status != SERVICE_WORKER_OK) { 534 if (status != SERVICE_WORKER_OK) {
497 std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER); 535 std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER);
498 return; 536 return;
499 } 537 }
500 538
501 PaymentInstrumentProto instrument_proto; 539 PaymentInstrumentProto instrument_proto;
540 instrument_proto.set_registration_id(registration->id());
541 instrument_proto.set_instrument_key(instrument_key);
542 instrument_proto.set_origin(registration->pattern().GetOrigin().spec());
502 instrument_proto.set_name(instrument->name); 543 instrument_proto.set_name(instrument->name);
503 for (const auto& method : instrument->enabled_methods) { 544 for (const auto& method : instrument->enabled_methods) {
504 instrument_proto.add_enabled_methods(method); 545 instrument_proto.add_enabled_methods(method);
505 } 546 }
506 instrument_proto.set_stringified_capabilities( 547 instrument_proto.set_stringified_capabilities(
507 instrument->stringified_capabilities); 548 instrument->stringified_capabilities);
508 549
509 std::string serialized_instrument; 550 std::string serialized_instrument;
510 bool success = instrument_proto.SerializeToString(&serialized_instrument); 551 bool success = instrument_proto.SerializeToString(&serialized_instrument);
511 DCHECK(success); 552 DCHECK(success);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 void PaymentAppDatabase::DidClearPaymentInstruments( 626 void PaymentAppDatabase::DidClearPaymentInstruments(
586 ClearPaymentInstrumentsCallback callback, 627 ClearPaymentInstrumentsCallback callback,
587 ServiceWorkerStatusCode status) { 628 ServiceWorkerStatusCode status) {
588 DCHECK_CURRENTLY_ON(BrowserThread::IO); 629 DCHECK_CURRENTLY_ON(BrowserThread::IO);
589 return std::move(callback).Run(status == SERVICE_WORKER_OK 630 return std::move(callback).Run(status == SERVICE_WORKER_OK
590 ? PaymentHandlerStatus::SUCCESS 631 ? PaymentHandlerStatus::SUCCESS
591 : PaymentHandlerStatus::NOT_FOUND); 632 : PaymentHandlerStatus::NOT_FOUND);
592 } 633 }
593 634
594 } // namespace content 635 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/payments/payment_app_database.h ('k') | content/browser/payments/payment_app_provider_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698