Chromium Code Reviews| Index: content/browser/payments/payment_app_manager.cc |
| diff --git a/content/browser/payments/payment_app_manager.cc b/content/browser/payments/payment_app_manager.cc |
| index 0f0c9ecde16b864bfae94a229dd81287e03d1b5a..76567420b2e5dfd75edbbea53f76b28e5d82f854 100644 |
| --- a/content/browser/payments/payment_app_manager.cc |
| +++ b/content/browser/payments/payment_app_manager.cc |
| @@ -7,11 +7,21 @@ |
| #include <utility> |
| #include "base/bind.h" |
| +#include "base/optional.h" |
| +#include "content/browser/payments/payment_app.pb.h" |
| #include "content/browser/payments/payment_app_context.h" |
| +#include "content/browser/service_worker/service_worker_context_wrapper.h" |
| +#include "content/browser/service_worker/service_worker_registration.h" |
| #include "content/public/browser/browser_thread.h" |
| namespace content { |
|
please use gerrit instead
2016/11/15 20:04:26
Usually we don't put newlines between two nested n
zino
2016/11/16 18:12:58
Done.
|
| +namespace { |
| + |
| +const char kPaymentAppManifestDataKey[] = "PaymentAppManifestData"; |
| + |
| +} |
|
please use gerrit instead
2016/11/15 20:04:26
Anonymous namespace should end with "} // namespa
zino
2016/11/16 18:12:58
Done.
|
| + |
| PaymentAppManager::~PaymentAppManager() { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| } |
| @@ -39,7 +49,67 @@ void PaymentAppManager::SetManifest( |
| payments::mojom::PaymentAppManifestPtr manifest, |
| const SetManifestCallback& callback) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| - callback.Run(payments::mojom::PaymentAppManifestError::NOT_IMPLEMENTED); |
| + |
| + // TODO(zino): Should implement requesting a permission for users to allow |
| + // the payment app to be registered. |
|
please use gerrit instead
2016/11/15 20:04:26
All TODOs should have a bug link. The linked bug s
zino
2016/11/16 18:12:58
Done.
|
| + |
| + payment_app_context_->service_worker_context() |
| + ->FindReadyRegistrationForPattern( |
| + GURL(scope), |
| + base::Bind(&PaymentAppManager::DidFindRegistrationToSetManifest, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + base::Passed(std::move(manifest)), callback)); |
| +} |
| + |
| +void PaymentAppManager::DidFindRegistrationToSetManifest( |
| + payments::mojom::PaymentAppManifestPtr manifest, |
| + const SetManifestCallback& callback, |
| + ServiceWorkerStatusCode status, |
| + scoped_refptr<ServiceWorkerRegistration> registration) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + if (status != SERVICE_WORKER_OK) { |
| + callback.Run(payments::mojom::PaymentAppManifestError::NO_ACTIVE_WORKER); |
| + return; |
| + } |
| + |
| + PaymentAppManifestProto manifest_proto; |
| + manifest_proto.set_label(manifest->label); |
| + if (manifest->icon) |
| + manifest_proto.set_icon(manifest->icon.value()); |
| + |
| + for (const auto& option : manifest->options) { |
| + PaymentAppOptionProto* option_proto = manifest_proto.add_options(); |
| + option_proto->set_label(option->label); |
| + if (option->icon) |
| + option_proto->set_icon(option->icon.value()); |
| + option_proto->set_id(option->id); |
| + for (const auto& method : option->enabled_methods) { |
| + option_proto->add_enabled_methods(method); |
| + } |
| + } |
| + |
| + std::string serialized; |
| + bool success = manifest_proto.SerializeToString(&serialized); |
| + DCHECK(success); |
| + |
| + payment_app_context_->service_worker_context()->StoreRegistrationUserData( |
| + registration->id(), registration->pattern().GetOrigin(), |
| + {{kPaymentAppManifestDataKey, serialized}}, |
| + base::Bind(&PaymentAppManager::DidSetManifest, |
| + weak_ptr_factory_.GetWeakPtr(), callback)); |
| +} |
| + |
| +void PaymentAppManager::DidSetManifest(const SetManifestCallback& callback, |
| + ServiceWorkerStatusCode status) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + if (status != SERVICE_WORKER_OK) { |
| + callback.Run( |
| + payments::mojom::PaymentAppManifestError::STORE_MANIFEST_FAILED); |
| + return; |
| + } |
| + |
| + // Success |
| + callback.Run(payments::mojom::PaymentAppManifestError::NONE); |
|
please use gerrit instead
2016/11/15 20:04:26
Cleaner to use a single statement with a ternary c
zino
2016/11/16 18:12:58
Done.
|
| } |
| } // namespace content |