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

Side by Side Diff: components/payments/android/payment_manifest_web_data_service.cc

Issue 2838433002: [Payments] Cache payment manifests. (Closed)
Patch Set: rebase Created 3 years, 7 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/payments/android/payment_manifest_web_data_service.h"
6
7 #include "base/bind.h"
8 #include "base/location.h"
9
10 namespace payments {
11
12 PaymentManifestWebDataService::PaymentManifestWebDataService(
13 scoped_refptr<WebDatabaseService> wdbs,
14 const ProfileErrorCallback& callback,
15 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread)
16 : WebDataServiceBase(wdbs, callback, ui_thread) {}
17
18 PaymentManifestWebDataService::~PaymentManifestWebDataService() {}
19
20 void PaymentManifestWebDataService::AddPaymentWebAppManifest(
21 std::vector<mojom::WebAppManifestSectionPtr> manifest) {
22 wdbs_->ScheduleDBTask(
23 FROM_HERE,
24 base::Bind(&PaymentManifestWebDataService::AddPaymentWebAppManifestImpl,
25 this, std::move(manifest)));
26 }
27
28 WebDatabase::State PaymentManifestWebDataService::AddPaymentWebAppManifestImpl(
29 const std::vector<mojom::WebAppManifestSectionPtr>& manifest,
30 WebDatabase* db) {
31 if (WebAppManifestSectionTable::FromWebDatabase(db)->AddWebAppManifest(
32 manifest)) {
33 return WebDatabase::COMMIT_NEEDED;
34 }
35
36 return WebDatabase::COMMIT_NOT_NEEDED;
37 }
38
39 void PaymentManifestWebDataService::AddPaymentMethodManifest(
40 const std::string& payment_method,
41 std::vector<std::string> app_package_names) {
42 wdbs_->ScheduleDBTask(
43 FROM_HERE,
44 base::Bind(&PaymentManifestWebDataService::AddPaymentMethodManifestImpl,
45 this, payment_method, std::move(app_package_names)));
46 }
47
48 WebDatabase::State PaymentManifestWebDataService::AddPaymentMethodManifestImpl(
49 const std::string& payment_method,
50 const std::vector<std::string>& app_package_names,
51 WebDatabase* db) {
52 if (PaymentMethodManifestTable::FromWebDatabase(db)->AddManifest(
53 payment_method, app_package_names)) {
54 return WebDatabase::COMMIT_NEEDED;
55 }
56
57 return WebDatabase::COMMIT_NOT_NEEDED;
58 }
59
60 WebDataServiceBase::Handle
61 PaymentManifestWebDataService::GetPaymentWebAppManifest(
62 const std::string& web_app,
63 WebDataServiceConsumer* consumer) {
64 return wdbs_->ScheduleDBTaskWithResult(
65 FROM_HERE,
66 base::Bind(&PaymentManifestWebDataService::GetPaymentWebAppManifestImpl,
67 this, web_app),
68 consumer);
69 }
70
71 std::unique_ptr<WDTypedResult>
72 PaymentManifestWebDataService::GetPaymentWebAppManifestImpl(
73 const std::string& web_app,
74 WebDatabase* db) {
75 return base::MakeUnique<
76 WDResult<std::vector<mojom::WebAppManifestSectionPtr>>>(
77 PAYMENT_WEB_APP_MANIFEST,
78 WebAppManifestSectionTable::FromWebDatabase(db)->GetWebAppManifest(
79 web_app));
80 }
81
82 WebDataServiceBase::Handle
83 PaymentManifestWebDataService::GetPaymentMethodManifest(
84 const std::string& payment_method,
85 WebDataServiceConsumer* consumer) {
86 return wdbs_->ScheduleDBTaskWithResult(
87 FROM_HERE,
88 base::Bind(&PaymentManifestWebDataService::GetPaymentMethodManifestImpl,
89 this, payment_method),
90 consumer);
91 }
92
93 std::unique_ptr<WDTypedResult>
94 PaymentManifestWebDataService::GetPaymentMethodManifestImpl(
95 const std::string& payment_method,
96 WebDatabase* db) {
97 return base::MakeUnique<WDResult<std::vector<std::string>>>(
98 PAYMENT_METHOD_MANIFEST,
99 PaymentMethodManifestTable::FromWebDatabase(db)->GetManifest(
100 payment_method));
101 }
102
103 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698