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

Unified Diff: components/payments/android/payment_manifest_web_data_service.cc

Issue 2838433002: [Payments] Cache payment manifests. (Closed)
Patch Set: fix tests Created 3 years, 8 months 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: components/payments/android/payment_manifest_web_data_service.cc
diff --git a/components/payments/android/payment_manifest_web_data_service.cc b/components/payments/android/payment_manifest_web_data_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..959b98b6c721bc55fa988f098ac04d4d51f53a2d
--- /dev/null
+++ b/components/payments/android/payment_manifest_web_data_service.cc
@@ -0,0 +1,117 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/payments/android/payment_manifest_web_data_service.h"
+
+#include "base/bind.h"
+#include "base/location.h"
+
+namespace payments {
+
+PaymentManifestWebDataService::PaymentManifestWebDataService(
+ scoped_refptr<WebDatabaseService> wdbs,
+ const ProfileErrorCallback& callback,
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread)
+ : WebDataServiceBase(wdbs, callback, ui_thread) {}
+
+PaymentManifestWebDataService::~PaymentManifestWebDataService() {}
+
+void PaymentManifestWebDataService::AddPaymentWebAppManifest(
+ const std::vector<mojom::WebAppManifestSectionPtr>& manifest) {
please use gerrit instead 2017/04/24 18:22:32 I recommend that you change the type of this param
gogerald1 2017/04/26 13:46:33 I can not move it since the input manifest is also
+ // Make a copy of |manifest| to be used in DB thread.
+ // Note that mojom::WebAppManifestSectionPtr is DISALLOW_COPY_AND_ASSIGN.
please use gerrit instead 2017/04/24 18:22:32 Actually, mojom::WebAppManifestSectionPtr is a mov
gogerald1 2017/04/26 13:46:33 Acknowledged.
+ std::vector<mojom::WebAppManifestSectionPtr> manifest_copy;
+ for (size_t i = 0; i < manifest.size(); i++) {
+ manifest_copy.emplace_back(manifest[i].Clone());
+ }
+
+ wdbs_->ScheduleDBTask(
+ FROM_HERE,
+ base::Bind(&PaymentManifestWebDataService::AddPaymentWebAppManifestImpl,
+ this, std::move(manifest_copy)));
+}
+
+WebDatabase::State PaymentManifestWebDataService::AddPaymentWebAppManifestImpl(
+ const std::vector<mojom::WebAppManifestSectionPtr>& manifest,
+ WebDatabase* db) {
+ if (WebAppManifestSectionTable::FromWebDatabase(db)->AddWebAppManifest(
+ manifest)) {
+ return WebDatabase::COMMIT_NEEDED;
+ }
+
+ return WebDatabase::COMMIT_NOT_NEEDED;
+}
+
+WebDataServiceBase::Handle
+PaymentManifestWebDataService::GetPaymentWebAppManifest(
+ const std::string& web_app,
+ WebDataServiceConsumer* consumer) {
+ return wdbs_->ScheduleDBTaskWithResult(
+ FROM_HERE,
+ base::Bind(&PaymentManifestWebDataService::GetPaymentWebAppManifestImpl,
+ this, web_app),
+ consumer);
+}
+
+std::unique_ptr<WDTypedResult>
+PaymentManifestWebDataService::GetPaymentWebAppManifestImpl(
+ const std::string& web_app,
+ WebDatabase* db) {
+ std::unique_ptr<WDTypedResult> result_ptr;
+
+ result_ptr.reset(new WDResult<std::vector<mojom::WebAppManifestSectionPtr>>(
please use gerrit instead 2017/04/24 18:22:32 Use base::MakeUnique. return base::MakeUnique<WDR
gogerald1 2017/04/26 13:46:33 Done.
+ PAYMENT_WEB_APP_MANIFEST,
+ WebAppManifestSectionTable::FromWebDatabase(db)->GetWebAppManifest(
+ web_app)));
+
+ return result_ptr;
+}
+
+void PaymentManifestWebDataService::AddPaymentMethodManifest(
+ const std::string& payment_method,
+ const std::vector<std::string>& web_app_ids) {
+ wdbs_->ScheduleDBTask(
+ FROM_HERE,
+ base::Bind(&PaymentManifestWebDataService::AddPaymentMethodManifestImpl,
+ this, payment_method, web_app_ids));
+}
+
+WebDatabase::State PaymentManifestWebDataService::AddPaymentMethodManifestImpl(
+ const std::string& payment_method,
+ const std::vector<std::string>& web_app_ids,
+ WebDatabase* db) {
+ if (PaymentMethodManifestTable::FromWebDatabase(db)->AddManifest(
+ payment_method, web_app_ids)) {
+ return WebDatabase::COMMIT_NEEDED;
+ }
+
+ return WebDatabase::COMMIT_NOT_NEEDED;
+}
+
+WebDataServiceBase::Handle
+PaymentManifestWebDataService::GetPaymentMethodManifest(
+ const std::string& payment_method,
+ WebDataServiceConsumer* consumer) {
+ return wdbs_->ScheduleDBTaskWithResult(
+ FROM_HERE,
+ base::Bind(&PaymentManifestWebDataService::GetPaymentMethodManifestImpl,
+ this, payment_method),
+ consumer);
+}
+
+std::unique_ptr<WDTypedResult>
+PaymentManifestWebDataService::GetPaymentMethodManifestImpl(
+ const std::string& payment_method,
+ WebDatabase* db) {
+ std::unique_ptr<WDTypedResult> result_ptr;
+
+ result_ptr.reset(new WDResult<std::vector<std::string>>(
please use gerrit instead 2017/04/24 18:22:32 Ditto.
gogerald1 2017/04/26 13:46:33 Done.
+ PAYMENT_METHOD_MANIFEST,
+ PaymentMethodManifestTable::FromWebDatabase(db)->GetManifest(
+ payment_method)));
+
+ return result_ptr;
+}
+
+} // namespace payments

Powered by Google App Engine
This is Rietveld 408576698