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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 // the payment app to be registered. Please see http://crbug.com/665949. | 53 // the payment app to be registered. Please see http://crbug.com/665949. |
| 54 | 54 |
| 55 payment_app_context_->service_worker_context() | 55 payment_app_context_->service_worker_context() |
| 56 ->FindReadyRegistrationForPattern( | 56 ->FindReadyRegistrationForPattern( |
| 57 GURL(scope), | 57 GURL(scope), |
| 58 base::Bind(&PaymentAppManager::DidFindRegistrationToSetManifest, | 58 base::Bind(&PaymentAppManager::DidFindRegistrationToSetManifest, |
| 59 weak_ptr_factory_.GetWeakPtr(), | 59 weak_ptr_factory_.GetWeakPtr(), |
| 60 base::Passed(std::move(manifest)), callback)); | 60 base::Passed(std::move(manifest)), callback)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void PaymentAppManager::GetManifest(const std::string& scope, | |
| 64 const GetManifestCallback& callback) { | |
| 65 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 66 | |
| 67 payment_app_context_->service_worker_context() | |
| 68 ->FindReadyRegistrationForPattern( | |
| 69 GURL(scope), | |
| 70 base::Bind(&PaymentAppManager::DidFindRegistrationToGetManifest, | |
| 71 weak_ptr_factory_.GetWeakPtr(), callback)); | |
| 72 } | |
| 73 | |
| 63 void PaymentAppManager::DidFindRegistrationToSetManifest( | 74 void PaymentAppManager::DidFindRegistrationToSetManifest( |
| 64 payments::mojom::PaymentAppManifestPtr manifest, | 75 payments::mojom::PaymentAppManifestPtr manifest, |
| 65 const SetManifestCallback& callback, | 76 const SetManifestCallback& callback, |
| 66 ServiceWorkerStatusCode status, | 77 ServiceWorkerStatusCode status, |
| 67 scoped_refptr<ServiceWorkerRegistration> registration) { | 78 scoped_refptr<ServiceWorkerRegistration> registration) { |
| 68 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 79 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 69 if (status != SERVICE_WORKER_OK) { | 80 if (status != SERVICE_WORKER_OK) { |
| 70 callback.Run(payments::mojom::PaymentAppManifestError::NO_ACTIVE_WORKER); | 81 callback.Run(payments::mojom::PaymentAppManifestError::NO_ACTIVE_WORKER); |
| 71 return; | 82 return; |
| 72 } | 83 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 94 payment_app_context_->service_worker_context()->StoreRegistrationUserData( | 105 payment_app_context_->service_worker_context()->StoreRegistrationUserData( |
| 95 registration->id(), registration->pattern().GetOrigin(), | 106 registration->id(), registration->pattern().GetOrigin(), |
| 96 {{kPaymentAppManifestDataKey, serialized}}, | 107 {{kPaymentAppManifestDataKey, serialized}}, |
| 97 base::Bind(&PaymentAppManager::DidSetManifest, | 108 base::Bind(&PaymentAppManager::DidSetManifest, |
| 98 weak_ptr_factory_.GetWeakPtr(), callback)); | 109 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 99 } | 110 } |
| 100 | 111 |
| 101 void PaymentAppManager::DidSetManifest(const SetManifestCallback& callback, | 112 void PaymentAppManager::DidSetManifest(const SetManifestCallback& callback, |
| 102 ServiceWorkerStatusCode status) { | 113 ServiceWorkerStatusCode status) { |
| 103 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 114 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 104 return callback.Run( | 115 return callback.Run(status == SERVICE_WORKER_OK |
| 105 status == SERVICE_WORKER_OK | 116 ? payments::mojom::PaymentAppManifestError::NONE |
| 106 ? payments::mojom::PaymentAppManifestError::NONE | 117 : payments::mojom::PaymentAppManifestError:: |
| 107 : payments::mojom::PaymentAppManifestError::STORE_MANIFEST_FAILED); | 118 MANIFEST_STORAGE_OPERATION_FAILED); |
| 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 && data.size() != 1) { | |
|
please use gerrit instead
2016/11/22 00:42:08
&& should be ||.
| |
| 143 callback.Run(payments::mojom::PaymentAppManifest::New(), | |
| 144 payments::mojom::PaymentAppManifestError:: | |
| 145 MANIFEST_STORAGE_OPERATION_FAILED); | |
| 146 return; | |
| 147 } | |
| 148 | |
| 149 PaymentAppManifestProto manifest_proto; | |
| 150 bool success = manifest_proto.ParseFromString(data[0]); | |
| 151 if (!success) { | |
| 152 callback.Run(payments::mojom::PaymentAppManifest::New(), | |
| 153 payments::mojom::PaymentAppManifestError:: | |
| 154 MANIFEST_STORAGE_OPERATION_FAILED); | |
| 155 return; | |
| 156 } | |
| 157 | |
| 158 payments::mojom::PaymentAppManifestPtr manifest = | |
| 159 payments::mojom::PaymentAppManifest::New(); | |
| 160 manifest->label = manifest_proto.label(); | |
| 161 if (manifest_proto.has_icon()) | |
| 162 manifest->icon = manifest_proto.icon(); | |
| 163 for (const auto& option_proto : manifest_proto.options()) { | |
| 164 payments::mojom::PaymentAppOptionPtr option = | |
| 165 payments::mojom::PaymentAppOption::New(); | |
| 166 option->label = option_proto.label(); | |
| 167 if (option_proto.has_icon()) | |
| 168 option->icon = option_proto.icon(); | |
| 169 option->id = option_proto.id(); | |
| 170 for (const auto& method : option_proto.enabled_methods()) | |
| 171 option->enabled_methods.push_back(method); | |
| 172 manifest->options.push_back(std::move(option)); | |
| 173 } | |
| 174 | |
| 175 callback.Run(std::move(manifest), | |
| 176 payments::mojom::PaymentAppManifestError::NONE); | |
| 108 } | 177 } |
| 109 | 178 |
| 110 } // namespace content | 179 } // namespace content |
| OLD | NEW |