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

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

Issue 2847533003: PaymentHandler: Add a key prefix to avoid key conflicts with others. (Closed)
Patch Set: PaymentHandler: Add a key prefix to avoid key conflicts with others. 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/optional.h" 10 #include "base/optional.h"
11 #include "content/browser/payments/payment_app.pb.h" 11 #include "content/browser/payments/payment_app.pb.h"
12 #include "content/browser/payments/payment_app_context_impl.h" 12 #include "content/browser/payments/payment_app_context_impl.h"
13 #include "content/browser/service_worker/service_worker_context_wrapper.h" 13 #include "content/browser/service_worker/service_worker_context_wrapper.h"
14 #include "content/browser/service_worker/service_worker_registration.h" 14 #include "content/browser/service_worker/service_worker_registration.h"
15 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
16 16
17 namespace content { 17 namespace content {
18 namespace { 18 namespace {
19 19
20 using ::payments::mojom::PaymentHandlerStatus; 20 using ::payments::mojom::PaymentHandlerStatus;
21 using ::payments::mojom::PaymentInstrument; 21 using ::payments::mojom::PaymentInstrument;
22 using ::payments::mojom::PaymentInstrumentPtr; 22 using ::payments::mojom::PaymentInstrumentPtr;
23 23
24 const char kPaymentAppManifestDataKey[] = "PaymentAppManifestData"; 24 const char kPaymentAppManifestDataKey[] = "PaymentAppManifestData";
25 const char kPaymentInstrumentKeyPrefix[] = "PaymentInstrument:";
26
27 std::string CreatePaymentInstrumentKey(const std::string& instrument_key) {
28 return kPaymentInstrumentKeyPrefix + instrument_key;
29 }
25 30
26 payments::mojom::PaymentAppManifestPtr DeserializePaymentAppManifest( 31 payments::mojom::PaymentAppManifestPtr DeserializePaymentAppManifest(
27 const std::string& input) { 32 const std::string& input) {
28 PaymentAppManifestProto manifest_proto; 33 PaymentAppManifestProto manifest_proto;
29 if (!manifest_proto.ParseFromString(input)) 34 if (!manifest_proto.ParseFromString(input))
30 return nullptr; 35 return nullptr;
31 36
32 payments::mojom::PaymentAppManifestPtr manifest = 37 payments::mojom::PaymentAppManifestPtr manifest =
33 payments::mojom::PaymentAppManifest::New(); 38 payments::mojom::PaymentAppManifest::New();
34 manifest->name = manifest_proto.name(); 39 manifest->name = manifest_proto.name();
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 DeletePaymentInstrumentCallback callback, 286 DeletePaymentInstrumentCallback callback,
282 ServiceWorkerStatusCode status, 287 ServiceWorkerStatusCode status,
283 scoped_refptr<ServiceWorkerRegistration> registration) { 288 scoped_refptr<ServiceWorkerRegistration> registration) {
284 DCHECK_CURRENTLY_ON(BrowserThread::IO); 289 DCHECK_CURRENTLY_ON(BrowserThread::IO);
285 if (status != SERVICE_WORKER_OK) { 290 if (status != SERVICE_WORKER_OK) {
286 std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER); 291 std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER);
287 return; 292 return;
288 } 293 }
289 294
290 service_worker_context_->GetRegistrationUserData( 295 service_worker_context_->GetRegistrationUserData(
291 registration->id(), {instrument_key}, 296 registration->id(), {CreatePaymentInstrumentKey(instrument_key)},
292 base::Bind(&PaymentAppDatabase::DidFindPaymentInstrument, 297 base::Bind(&PaymentAppDatabase::DidFindPaymentInstrument,
293 weak_ptr_factory_.GetWeakPtr(), registration->id(), 298 weak_ptr_factory_.GetWeakPtr(), registration->id(),
294 instrument_key, base::Passed(std::move(callback)))); 299 instrument_key, base::Passed(std::move(callback))));
295 } 300 }
296 301
297 void PaymentAppDatabase::DidFindPaymentInstrument( 302 void PaymentAppDatabase::DidFindPaymentInstrument(
298 int64_t registration_id, 303 int64_t registration_id,
299 const std::string& instrument_key, 304 const std::string& instrument_key,
300 DeletePaymentInstrumentCallback callback, 305 DeletePaymentInstrumentCallback callback,
301 const std::vector<std::string>& data, 306 const std::vector<std::string>& data,
302 ServiceWorkerStatusCode status) { 307 ServiceWorkerStatusCode status) {
303 DCHECK_CURRENTLY_ON(BrowserThread::IO); 308 DCHECK_CURRENTLY_ON(BrowserThread::IO);
304 if (status != SERVICE_WORKER_OK || data.size() != 1) { 309 if (status != SERVICE_WORKER_OK || data.size() != 1) {
305 std::move(callback).Run(PaymentHandlerStatus::NOT_FOUND); 310 std::move(callback).Run(PaymentHandlerStatus::NOT_FOUND);
306 return; 311 return;
307 } 312 }
308 313
309 service_worker_context_->ClearRegistrationUserData( 314 service_worker_context_->ClearRegistrationUserData(
310 registration_id, {instrument_key}, 315 registration_id, {CreatePaymentInstrumentKey(instrument_key)},
311 base::Bind(&PaymentAppDatabase::DidDeletePaymentInstrument, 316 base::Bind(&PaymentAppDatabase::DidDeletePaymentInstrument,
312 weak_ptr_factory_.GetWeakPtr(), 317 weak_ptr_factory_.GetWeakPtr(),
313 base::Passed(std::move(callback)))); 318 base::Passed(std::move(callback))));
314 } 319 }
315 320
316 void PaymentAppDatabase::DidDeletePaymentInstrument( 321 void PaymentAppDatabase::DidDeletePaymentInstrument(
317 DeletePaymentInstrumentCallback callback, 322 DeletePaymentInstrumentCallback callback,
318 ServiceWorkerStatusCode status) { 323 ServiceWorkerStatusCode status) {
319 DCHECK_CURRENTLY_ON(BrowserThread::IO); 324 DCHECK_CURRENTLY_ON(BrowserThread::IO);
320 return std::move(callback).Run(status == SERVICE_WORKER_OK 325 return std::move(callback).Run(status == SERVICE_WORKER_OK
321 ? PaymentHandlerStatus::SUCCESS 326 ? PaymentHandlerStatus::SUCCESS
322 : PaymentHandlerStatus::NOT_FOUND); 327 : PaymentHandlerStatus::NOT_FOUND);
323 } 328 }
324 329
325 void PaymentAppDatabase::DidFindRegistrationToReadPaymentInstrument( 330 void PaymentAppDatabase::DidFindRegistrationToReadPaymentInstrument(
326 const std::string& instrument_key, 331 const std::string& instrument_key,
327 ReadPaymentInstrumentCallback callback, 332 ReadPaymentInstrumentCallback callback,
328 ServiceWorkerStatusCode status, 333 ServiceWorkerStatusCode status,
329 scoped_refptr<ServiceWorkerRegistration> registration) { 334 scoped_refptr<ServiceWorkerRegistration> registration) {
330 DCHECK_CURRENTLY_ON(BrowserThread::IO); 335 DCHECK_CURRENTLY_ON(BrowserThread::IO);
331 if (status != SERVICE_WORKER_OK) { 336 if (status != SERVICE_WORKER_OK) {
332 std::move(callback).Run(PaymentInstrument::New(), 337 std::move(callback).Run(PaymentInstrument::New(),
333 PaymentHandlerStatus::NO_ACTIVE_WORKER); 338 PaymentHandlerStatus::NO_ACTIVE_WORKER);
334 return; 339 return;
335 } 340 }
336 341
337 service_worker_context_->GetRegistrationUserData( 342 service_worker_context_->GetRegistrationUserData(
338 registration->id(), {instrument_key}, 343 registration->id(), {CreatePaymentInstrumentKey(instrument_key)},
339 base::Bind(&PaymentAppDatabase::DidReadPaymentInstrument, 344 base::Bind(&PaymentAppDatabase::DidReadPaymentInstrument,
340 weak_ptr_factory_.GetWeakPtr(), 345 weak_ptr_factory_.GetWeakPtr(),
341 base::Passed(std::move(callback)))); 346 base::Passed(std::move(callback))));
342 } 347 }
343 348
344 void PaymentAppDatabase::DidReadPaymentInstrument( 349 void PaymentAppDatabase::DidReadPaymentInstrument(
345 ReadPaymentInstrumentCallback callback, 350 ReadPaymentInstrumentCallback callback,
346 const std::vector<std::string>& data, 351 const std::vector<std::string>& data,
347 ServiceWorkerStatusCode status) { 352 ServiceWorkerStatusCode status) {
348 DCHECK_CURRENTLY_ON(BrowserThread::IO); 353 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 18 matching lines...) Expand all
367 HasPaymentInstrumentCallback callback, 372 HasPaymentInstrumentCallback callback,
368 ServiceWorkerStatusCode status, 373 ServiceWorkerStatusCode status,
369 scoped_refptr<ServiceWorkerRegistration> registration) { 374 scoped_refptr<ServiceWorkerRegistration> registration) {
370 DCHECK_CURRENTLY_ON(BrowserThread::IO); 375 DCHECK_CURRENTLY_ON(BrowserThread::IO);
371 if (status != SERVICE_WORKER_OK) { 376 if (status != SERVICE_WORKER_OK) {
372 std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER); 377 std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER);
373 return; 378 return;
374 } 379 }
375 380
376 service_worker_context_->GetRegistrationUserData( 381 service_worker_context_->GetRegistrationUserData(
377 registration->id(), {instrument_key}, 382 registration->id(), {CreatePaymentInstrumentKey(instrument_key)},
378 base::Bind(&PaymentAppDatabase::DidHasPaymentInstrument, 383 base::Bind(&PaymentAppDatabase::DidHasPaymentInstrument,
379 weak_ptr_factory_.GetWeakPtr(), registration->id(), 384 weak_ptr_factory_.GetWeakPtr(), registration->id(),
380 instrument_key, base::Passed(std::move(callback)))); 385 instrument_key, base::Passed(std::move(callback))));
381 } 386 }
382 387
383 void PaymentAppDatabase::DidHasPaymentInstrument( 388 void PaymentAppDatabase::DidHasPaymentInstrument(
384 int64_t registration_id, 389 int64_t registration_id,
385 const std::string& instrument_key, 390 const std::string& instrument_key,
386 DeletePaymentInstrumentCallback callback, 391 DeletePaymentInstrumentCallback callback,
387 const std::vector<std::string>& data, 392 const std::vector<std::string>& data,
(...skipping 26 matching lines...) Expand all
414 } 419 }
415 instrument_proto.set_stringified_capabilities( 420 instrument_proto.set_stringified_capabilities(
416 instrument->stringified_capabilities); 421 instrument->stringified_capabilities);
417 422
418 std::string serialized; 423 std::string serialized;
419 bool success = instrument_proto.SerializeToString(&serialized); 424 bool success = instrument_proto.SerializeToString(&serialized);
420 DCHECK(success); 425 DCHECK(success);
421 426
422 service_worker_context_->StoreRegistrationUserData( 427 service_worker_context_->StoreRegistrationUserData(
423 registration->id(), registration->pattern().GetOrigin(), 428 registration->id(), registration->pattern().GetOrigin(),
424 {{instrument_key, serialized}}, 429 {{CreatePaymentInstrumentKey(instrument_key), serialized}},
425 base::Bind(&PaymentAppDatabase::DidWritePaymentInstrument, 430 base::Bind(&PaymentAppDatabase::DidWritePaymentInstrument,
426 weak_ptr_factory_.GetWeakPtr(), 431 weak_ptr_factory_.GetWeakPtr(),
427 base::Passed(std::move(callback)))); 432 base::Passed(std::move(callback))));
428 } 433 }
429 434
430 void PaymentAppDatabase::DidWritePaymentInstrument( 435 void PaymentAppDatabase::DidWritePaymentInstrument(
431 WritePaymentInstrumentCallback callback, 436 WritePaymentInstrumentCallback callback,
432 ServiceWorkerStatusCode status) { 437 ServiceWorkerStatusCode status) {
433 DCHECK_CURRENTLY_ON(BrowserThread::IO); 438 DCHECK_CURRENTLY_ON(BrowserThread::IO);
434 return std::move(callback).Run( 439 return std::move(callback).Run(
435 status == SERVICE_WORKER_OK 440 status == SERVICE_WORKER_OK
436 ? PaymentHandlerStatus::SUCCESS 441 ? PaymentHandlerStatus::SUCCESS
437 : PaymentHandlerStatus::STORAGE_OPERATION_FAILED); 442 : PaymentHandlerStatus::STORAGE_OPERATION_FAILED);
438 } 443 }
439 444
440 } // namespace content 445 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698