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

Unified Diff: content/browser/payments/payment_app_manager.cc

Issue 2497983002: PaymentApp: Implement PaymentAppManager.setManifest(). (Closed)
Patch Set: rebase Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
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..9ea8dc32b1df8428ff6489b867d36c957a28efe5 100644
--- a/content/browser/payments/payment_app_manager.cc
+++ b/content/browser/payments/payment_app_manager.cc
@@ -7,10 +7,19 @@
#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 {
+namespace {
+
+const char kPaymentAppManifestDataKey[] = "PaymentAppManifestData";
+
+} // namespace
PaymentAppManager::~PaymentAppManager() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -39,7 +48,63 @@ 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 see http://crbug.com/665949.
+
+ 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);
+ return callback.Run(
+ status == SERVICE_WORKER_OK
+ ? payments::mojom::PaymentAppManifestError::NONE
+ : payments::mojom::PaymentAppManifestError::STORE_MANIFEST_FAILED);
}
} // namespace content
« no previous file with comments | « content/browser/payments/payment_app_manager.h ('k') | content/browser/payments/payment_app_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698