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 dc98a02c3c7ce4a920a584e938a16e4233201057..52b3c7d170cede2814da910837e41ebbcea7dfdb 100644 |
| --- a/content/browser/payments/payment_app_manager.cc |
| +++ b/content/browser/payments/payment_app_manager.cc |
| @@ -10,16 +10,12 @@ |
| #include "base/optional.h" |
| #include "content/browser/payments/payment_app.pb.h" |
| #include "content/browser/payments/payment_app_context_impl.h" |
| +#include "content/browser/payments/payment_app_database.h" |
|
please use gerrit instead
2016/12/15 19:24:31
Does not seem necessary.
zino
2016/12/15 23:33:56
It's necessary to call WriteManifest() and ReadMan
please use gerrit instead
2016/12/16 14:25:55
Acknowledged.
|
| #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,10 +35,6 @@ PaymentAppManager::PaymentAppManager( |
| base::Unretained(this))); |
| } |
| -void PaymentAppManager::OnConnectionError() { |
| - payment_app_context_->ServiceHadConnectionError(this); |
| -} |
| - |
| void PaymentAppManager::SetManifest( |
| const std::string& scope, |
| payments::mojom::PaymentAppManifestPtr manifest, |
| @@ -52,128 +44,21 @@ void PaymentAppManager::SetManifest( |
| // 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)); |
| + payment_app_context_->payment_app_database()->WriteManifest( |
| + GURL(scope), std::move(manifest), callback); |
| } |
| 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::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:: |
| - MANIFEST_STORAGE_OPERATION_FAILED); |
| -} |
| - |
| -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)); |
| + payment_app_context_->payment_app_database()->ReadManifest(GURL(scope), |
| + callback); |
| } |
| -void PaymentAppManager::DidGetManifest(const GetManifestCallback& callback, |
| - const std::vector<std::string>& data, |
| - ServiceWorkerStatusCode status) { |
| +void PaymentAppManager::OnConnectionError() { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| - if (status != SERVICE_WORKER_OK || data.size() != 1) { |
| - callback.Run(payments::mojom::PaymentAppManifest::New(), |
| - payments::mojom::PaymentAppManifestError:: |
| - MANIFEST_STORAGE_OPERATION_FAILED); |
| - return; |
| - } |
| - |
| - PaymentAppManifestProto manifest_proto; |
| - bool success = manifest_proto.ParseFromString(data[0]); |
| - if (!success) { |
| - callback.Run(payments::mojom::PaymentAppManifest::New(), |
| - payments::mojom::PaymentAppManifestError:: |
| - MANIFEST_STORAGE_OPERATION_FAILED); |
| - return; |
| - } |
| - |
| - 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 (const auto& method : option_proto.enabled_methods()) |
| - option->enabled_methods.push_back(method); |
| - manifest->options.push_back(std::move(option)); |
| - } |
| - |
| - callback.Run(std::move(manifest), |
| - payments::mojom::PaymentAppManifestError::NONE); |
| + payment_app_context_->PaymentAppManagerHadConnectionError(this); |
| } |
| } // namespace content |