Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_manager.h" | 5 #include "content/browser/payments/payment_app_manager.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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 | 100 |
| 101 void PaymentAppManager::DidSetManifest(const SetManifestCallback& callback, | 101 void PaymentAppManager::DidSetManifest(const SetManifestCallback& callback, |
| 102 ServiceWorkerStatusCode status) { | 102 ServiceWorkerStatusCode status) { |
| 103 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 103 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 104 return callback.Run( | 104 return callback.Run( |
| 105 status == SERVICE_WORKER_OK | 105 status == SERVICE_WORKER_OK |
| 106 ? payments::mojom::PaymentAppManifestError::NONE | 106 ? payments::mojom::PaymentAppManifestError::NONE |
| 107 : payments::mojom::PaymentAppManifestError::STORE_MANIFEST_FAILED); | 107 : payments::mojom::PaymentAppManifestError::STORE_MANIFEST_FAILED); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void PaymentAppManager::GetManifest(const std::string& scope, | |
| 111 const GetManifestCallback& callback) { | |
| 112 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 113 | |
| 114 payment_app_context_->service_worker_context() | |
| 115 ->FindReadyRegistrationForPattern( | |
| 116 GURL(scope), | |
| 117 base::Bind(&PaymentAppManager::DidFindRegistrationToGetManifest, | |
| 118 weak_ptr_factory_.GetWeakPtr(), callback)); | |
| 119 } | |
| 120 | |
| 121 void PaymentAppManager::DidFindRegistrationToGetManifest( | |
| 122 const GetManifestCallback& callback, | |
| 123 ServiceWorkerStatusCode status, | |
| 124 scoped_refptr<ServiceWorkerRegistration> registration) { | |
| 125 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 126 if (status != SERVICE_WORKER_OK) { | |
| 127 callback.Run(payments::mojom::PaymentAppManifest::New(), | |
| 128 payments::mojom::PaymentAppManifestError::NO_ACTIVE_WORKER); | |
| 129 return; | |
| 130 } | |
| 131 | |
| 132 payment_app_context_->service_worker_context()->GetRegistrationUserData( | |
| 133 registration->id(), {kPaymentAppManifestDataKey}, | |
| 134 base::Bind(&PaymentAppManager::DidGetManifest, | |
| 135 weak_ptr_factory_.GetWeakPtr(), callback)); | |
| 136 } | |
| 137 | |
| 138 void PaymentAppManager::DidGetManifest(const GetManifestCallback& callback, | |
| 139 const std::vector<std::string>& data, | |
| 140 ServiceWorkerStatusCode status) { | |
| 141 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 142 if (status != SERVICE_WORKER_OK) { | |
| 143 callback.Run( | |
| 144 payments::mojom::PaymentAppManifest::New(), | |
| 145 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.
| |
| 146 return; | |
| 147 } | |
| 148 | |
| 149 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.
| |
| 150 PaymentAppManifestProto manifest_proto; | |
| 151 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.
| |
| 152 DCHECK(success); | |
| 153 | |
| 154 payments::mojom::PaymentAppManifestPtr manifest = | |
| 155 payments::mojom::PaymentAppManifest::New(); | |
| 156 manifest->label = manifest_proto.label(); | |
| 157 if (manifest_proto.has_icon()) | |
| 158 manifest->icon = manifest_proto.icon(); | |
| 159 for (const auto& option_proto : manifest_proto.options()) { | |
| 160 payments::mojom::PaymentAppOptionPtr option = | |
| 161 payments::mojom::PaymentAppOption::New(); | |
| 162 option->label = option_proto.label(); | |
| 163 if (option_proto.has_icon()) | |
| 164 option->icon = option_proto.icon(); | |
| 165 option->id = option_proto.id(); | |
| 166 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.
| |
| 167 option->enabled_methods.push_back(option_proto.enabled_methods(i)); | |
| 168 manifest->options.push_back(std::move(option)); | |
| 169 } | |
| 170 | |
| 171 callback.Run(std::move(manifest), | |
| 172 payments::mojom::PaymentAppManifestError::NONE); | |
| 173 } | |
| 174 | |
| 110 } // namespace content | 175 } // namespace content |
| OLD | NEW |