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

Side by Side Diff: content/browser/payments/payment_app_database.cc

Issue 2556433002: PaymentApp: Implement GetAllManifests() in PaymentAppContext. (Closed)
Patch Set: Created 4 years 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/payments/payment_app_database.h" 5 #include "content/browser/payments/payment_app_database.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/optional.h" 10 #include "base/optional.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 void PaymentAppDatabase::ReadManifest(const GURL& scope, 98 void PaymentAppDatabase::ReadManifest(const GURL& scope,
99 const ReadManifestCallback& callback) { 99 const ReadManifestCallback& callback) {
100 DCHECK_CURRENTLY_ON(BrowserThread::IO); 100 DCHECK_CURRENTLY_ON(BrowserThread::IO);
101 101
102 service_worker_context_->FindReadyRegistrationForPattern( 102 service_worker_context_->FindReadyRegistrationForPattern(
103 scope, base::Bind(&PaymentAppDatabase::DidFindRegistrationToReadManifest, 103 scope, base::Bind(&PaymentAppDatabase::DidFindRegistrationToReadManifest,
104 weak_ptr_factory_.GetWeakPtr(), callback)); 104 weak_ptr_factory_.GetWeakPtr(), callback));
105 } 105 }
106 106
107 void PaymentAppDatabase::ReadAllManifests(
108 const ReadAllManifestsCallback& callback) {
109 DCHECK_CURRENTLY_ON(BrowserThread::IO);
110
111 service_worker_context_->GetUserDataForAllRegistrations(
112 kPaymentAppManifestDataKey,
113 base::Bind(&PaymentAppDatabase::DidReadAllManifests,
114 weak_ptr_factory_.GetWeakPtr(), callback));
115 }
116
107 void PaymentAppDatabase::DidFindRegistrationToWriteManifest( 117 void PaymentAppDatabase::DidFindRegistrationToWriteManifest(
108 payments::mojom::PaymentAppManifestPtr manifest, 118 payments::mojom::PaymentAppManifestPtr manifest,
109 const WriteManifestCallback& callback, 119 const WriteManifestCallback& callback,
110 ServiceWorkerStatusCode status, 120 ServiceWorkerStatusCode status,
111 scoped_refptr<ServiceWorkerRegistration> registration) { 121 scoped_refptr<ServiceWorkerRegistration> registration) {
112 DCHECK_CURRENTLY_ON(BrowserThread::IO); 122 DCHECK_CURRENTLY_ON(BrowserThread::IO);
113 if (status != SERVICE_WORKER_OK) { 123 if (status != SERVICE_WORKER_OK) {
114 callback.Run(payments::mojom::PaymentAppManifestError::NO_ACTIVE_WORKER); 124 callback.Run(payments::mojom::PaymentAppManifestError::NO_ACTIVE_WORKER);
115 return; 125 return;
116 } 126 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 callback.Run(payments::mojom::PaymentAppManifest::New(), 178 callback.Run(payments::mojom::PaymentAppManifest::New(),
169 payments::mojom::PaymentAppManifestError:: 179 payments::mojom::PaymentAppManifestError::
170 MANIFEST_STORAGE_OPERATION_FAILED); 180 MANIFEST_STORAGE_OPERATION_FAILED);
171 return; 181 return;
172 } 182 }
173 183
174 callback.Run(std::move(manifest), 184 callback.Run(std::move(manifest),
175 payments::mojom::PaymentAppManifestError::NONE); 185 payments::mojom::PaymentAppManifestError::NONE);
176 } 186 }
177 187
188 void PaymentAppDatabase::DidReadAllManifests(
189 const ReadAllManifestsCallback& callback,
190 const std::vector<std::pair<int64_t, std::string>>& raw_data,
191 ServiceWorkerStatusCode status) {
192 DCHECK_CURRENTLY_ON(BrowserThread::IO);
193 if (status != SERVICE_WORKER_OK) {
194 callback.Run(Manifests());
195 return;
196 }
197
198 Manifests manifests;
199 for (auto& item_of_raw_data : raw_data) {
200 payments::mojom::PaymentAppManifestPtr manifest =
201 DeserializePaymentAppManifest(item_of_raw_data.second);
202 if (!manifest) {
203 continue;
204 }
205 manifests.push_back(
206 ManifestWithID(item_of_raw_data.first, std::move(manifest)));
207 }
208
209 callback.Run(std::move(manifests));
210 }
211
178 } // namespace content 212 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698