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