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 9ea8dc32b1df8428ff6489b867d36c957a28efe5..a38f81ca8804ea6679c5a50de46a5d907978ce69 100644 |
--- a/content/browser/payments/payment_app_manager.cc |
+++ b/content/browser/payments/payment_app_manager.cc |
@@ -107,4 +107,69 @@ void PaymentAppManager::DidSetManifest(const SetManifestCallback& callback, |
: payments::mojom::PaymentAppManifestError::STORE_MANIFEST_FAILED); |
} |
+void PaymentAppManager::GetManifest(const std::string& scope, |
+ const GetManifestCallback& callback) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ |
+ payment_app_context_->service_worker_context() |
+ ->FindReadyRegistrationForPattern( |
+ GURL(scope), |
+ base::Bind(&PaymentAppManager::DidFindRegistrationToGetManifest, |
+ weak_ptr_factory_.GetWeakPtr(), callback)); |
+} |
+ |
+void PaymentAppManager::DidFindRegistrationToGetManifest( |
+ const GetManifestCallback& callback, |
+ ServiceWorkerStatusCode status, |
+ scoped_refptr<ServiceWorkerRegistration> registration) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ if (status != SERVICE_WORKER_OK) { |
+ callback.Run(payments::mojom::PaymentAppManifest::New(), |
+ payments::mojom::PaymentAppManifestError::NO_ACTIVE_WORKER); |
+ return; |
+ } |
+ |
+ payment_app_context_->service_worker_context()->GetRegistrationUserData( |
+ registration->id(), {kPaymentAppManifestDataKey}, |
+ base::Bind(&PaymentAppManager::DidGetManifest, |
+ weak_ptr_factory_.GetWeakPtr(), callback)); |
+} |
+ |
+void PaymentAppManager::DidGetManifest(const GetManifestCallback& callback, |
+ const std::vector<std::string>& data, |
+ ServiceWorkerStatusCode status) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ if (status != SERVICE_WORKER_OK) { |
+ callback.Run( |
+ payments::mojom::PaymentAppManifest::New(), |
+ payments::mojom::PaymentAppManifestError::STORE_MANIFEST_FAILED); |
please use gerrit instead
2016/11/21 22:02:13
Change this error message to either GET_MANIFST_FA
zino
2016/11/21 23:48:40
Done.
|
+ return; |
+ } |
+ |
+ DCHECK(data.size() == 1); |
please use gerrit instead
2016/11/21 22:02:13
Data on disk can be corrupted. I'm not aware of an
zino
2016/11/21 23:48:40
Done.
|
+ PaymentAppManifestProto manifest_proto; |
+ bool success = manifest_proto.ParseFromString(data[0]); |
please use gerrit instead
2016/11/21 22:02:13
Let's also gracefully handle !success, because dat
zino
2016/11/21 23:48:40
Done.
|
+ DCHECK(success); |
+ |
+ payments::mojom::PaymentAppManifestPtr manifest = |
+ payments::mojom::PaymentAppManifest::New(); |
+ manifest->label = manifest_proto.label(); |
+ if (manifest_proto.has_icon()) |
+ manifest->icon = manifest_proto.icon(); |
+ for (const auto& option_proto : manifest_proto.options()) { |
+ payments::mojom::PaymentAppOptionPtr option = |
+ payments::mojom::PaymentAppOption::New(); |
+ option->label = option_proto.label(); |
+ if (option_proto.has_icon()) |
+ option->icon = option_proto.icon(); |
+ option->id = option_proto.id(); |
+ for (int i = 0; i < option_proto.enabled_methods_size(); i++) |
please use gerrit instead
2016/11/21 22:02:13
Can we use "const auto&" loop?
zino
2016/11/21 23:48:40
Done.
|
+ option->enabled_methods.push_back(option_proto.enabled_methods(i)); |
+ manifest->options.push_back(std::move(option)); |
+ } |
+ |
+ callback.Run(std::move(manifest), |
+ payments::mojom::PaymentAppManifestError::NONE); |
+} |
+ |
} // namespace content |