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

Side by Side Diff: third_party/WebKit/Source/modules/payments/PaymentManager.cpp

Issue 2785523003: PaymentHandler: Rename PaymentAppManager to PaymentManager. (Closed)
Patch Set: PaymentHandler: Rename PaymentAppManager to PaymentManager. 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 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 "modules/payments/PaymentAppManager.h" 5 #include "modules/payments/PaymentManager.h"
6 6
7 #include "bindings/core/v8/ScriptPromise.h" 7 #include "bindings/core/v8/ScriptPromise.h"
8 #include "bindings/core/v8/ScriptState.h" 8 #include "bindings/core/v8/ScriptState.h"
9 #include "core/dom/DOMException.h" 9 #include "core/dom/DOMException.h"
10 #include "modules/payments/PaymentAppManifest.h" 10 #include "modules/payments/PaymentAppManifest.h"
11 #include "modules/payments/PaymentAppOption.h" 11 #include "modules/payments/PaymentAppOption.h"
12 #include "modules/serviceworkers/ServiceWorkerRegistration.h" 12 #include "modules/serviceworkers/ServiceWorkerRegistration.h"
13 #include "platform/mojo/MojoHelper.h" 13 #include "platform/mojo/MojoHelper.h"
14 #include "public/platform/InterfaceProvider.h" 14 #include "public/platform/InterfaceProvider.h"
15 #include "public/platform/Platform.h" 15 #include "public/platform/Platform.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } 79 }
80 output.setEnabledMethods(enabledMethods); 80 output.setEnabledMethods(enabledMethods);
81 return output; 81 return output;
82 } 82 }
83 }; 83 };
84 84
85 } // namespace mojo 85 } // namespace mojo
86 86
87 namespace blink { 87 namespace blink {
88 88
89 PaymentAppManager* PaymentAppManager::create( 89 PaymentManager* PaymentManager::create(
90 ServiceWorkerRegistration* registration) { 90 ServiceWorkerRegistration* registration) {
91 return new PaymentAppManager(registration); 91 return new PaymentManager(registration);
92 } 92 }
93 93
94 ScriptPromise PaymentAppManager::setManifest( 94 ScriptPromise PaymentManager::setManifest(ScriptState* scriptState,
95 ScriptState* scriptState, 95 const PaymentAppManifest& manifest) {
96 const PaymentAppManifest& manifest) {
97 if (!m_manager) { 96 if (!m_manager) {
98 return ScriptPromise::rejectWithDOMException( 97 return ScriptPromise::rejectWithDOMException(
99 scriptState, DOMException::create(InvalidStateError, 98 scriptState, DOMException::create(InvalidStateError,
100 "Payment app manager unavailable.")); 99 "Payment app manager unavailable."));
101 } 100 }
102 101
103 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 102 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
104 ScriptPromise promise = resolver->promise(); 103 ScriptPromise promise = resolver->promise();
105 104
106 m_manager->SetManifest( 105 m_manager->SetManifest(
107 payments::mojom::blink::PaymentAppManifest::From(manifest), 106 payments::mojom::blink::PaymentAppManifest::From(manifest),
108 convertToBaseCallback(WTF::bind(&PaymentAppManager::onSetManifest, 107 convertToBaseCallback(WTF::bind(&PaymentManager::onSetManifest,
109 wrapPersistent(this), 108 wrapPersistent(this),
110 wrapPersistent(resolver)))); 109 wrapPersistent(resolver))));
111 110
112 return promise; 111 return promise;
113 } 112 }
114 113
115 ScriptPromise PaymentAppManager::getManifest(ScriptState* scriptState) { 114 ScriptPromise PaymentManager::getManifest(ScriptState* scriptState) {
116 if (!m_manager) { 115 if (!m_manager) {
117 return ScriptPromise::rejectWithDOMException( 116 return ScriptPromise::rejectWithDOMException(
118 scriptState, DOMException::create(InvalidStateError, 117 scriptState, DOMException::create(InvalidStateError,
119 "Payment app manager unavailable.")); 118 "Payment app manager unavailable."));
120 } 119 }
121 120
122 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 121 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
123 ScriptPromise promise = resolver->promise(); 122 ScriptPromise promise = resolver->promise();
124 123
125 m_manager->GetManifest(convertToBaseCallback( 124 m_manager->GetManifest(convertToBaseCallback(
126 WTF::bind(&PaymentAppManager::onGetManifest, wrapPersistent(this), 125 WTF::bind(&PaymentManager::onGetManifest, wrapPersistent(this),
127 wrapPersistent(resolver)))); 126 wrapPersistent(resolver))));
128 127
129 return promise; 128 return promise;
130 } 129 }
131 130
132 DEFINE_TRACE(PaymentAppManager) { 131 DEFINE_TRACE(PaymentManager) {
133 visitor->trace(m_registration); 132 visitor->trace(m_registration);
134 } 133 }
135 134
136 PaymentAppManager::PaymentAppManager(ServiceWorkerRegistration* registration) 135 PaymentManager::PaymentManager(ServiceWorkerRegistration* registration)
137 : m_registration(registration) { 136 : m_registration(registration) {
138 DCHECK(registration); 137 DCHECK(registration);
139 Platform::current()->interfaceProvider()->getInterface( 138 Platform::current()->interfaceProvider()->getInterface(
140 mojo::MakeRequest(&m_manager)); 139 mojo::MakeRequest(&m_manager));
141 140
142 m_manager.set_connection_error_handler(convertToBaseCallback(WTF::bind( 141 m_manager.set_connection_error_handler(convertToBaseCallback(WTF::bind(
143 &PaymentAppManager::onServiceConnectionError, wrapWeakPersistent(this)))); 142 &PaymentManager::onServiceConnectionError, wrapWeakPersistent(this))));
144 143
145 m_manager->Init(m_registration->scope()); 144 m_manager->Init(m_registration->scope());
146 } 145 }
147 146
148 void PaymentAppManager::onSetManifest( 147 void PaymentManager::onSetManifest(
149 ScriptPromiseResolver* resolver, 148 ScriptPromiseResolver* resolver,
150 payments::mojom::blink::PaymentAppManifestError error) { 149 payments::mojom::blink::PaymentAppManifestError error) {
151 DCHECK(resolver); 150 DCHECK(resolver);
152 switch (error) { 151 switch (error) {
153 case payments::mojom::blink::PaymentAppManifestError::NONE: 152 case payments::mojom::blink::PaymentAppManifestError::NONE:
154 resolver->resolve(); 153 resolver->resolve();
155 break; 154 break;
156 case payments::mojom::blink::PaymentAppManifestError::NOT_IMPLEMENTED: 155 case payments::mojom::blink::PaymentAppManifestError::NOT_IMPLEMENTED:
157 resolver->reject( 156 resolver->reject(
158 DOMException::create(NotSupportedError, "Not implemented yet.")); 157 DOMException::create(NotSupportedError, "Not implemented yet."));
159 break; 158 break;
160 case payments::mojom::blink::PaymentAppManifestError::NO_ACTIVE_WORKER: 159 case payments::mojom::blink::PaymentAppManifestError::NO_ACTIVE_WORKER:
161 resolver->reject( 160 resolver->reject(
162 DOMException::create(InvalidStateError, "No active service worker.")); 161 DOMException::create(InvalidStateError, "No active service worker."));
163 break; 162 break;
164 case payments::mojom::blink::PaymentAppManifestError:: 163 case payments::mojom::blink::PaymentAppManifestError::
165 MANIFEST_STORAGE_OPERATION_FAILED: 164 MANIFEST_STORAGE_OPERATION_FAILED:
166 resolver->reject(DOMException::create( 165 resolver->reject(DOMException::create(
167 InvalidStateError, "Storing manifest data is failed.")); 166 InvalidStateError, "Storing manifest data is failed."));
168 break; 167 break;
169 } 168 }
170 } 169 }
171 170
172 void PaymentAppManager::onGetManifest( 171 void PaymentManager::onGetManifest(
173 ScriptPromiseResolver* resolver, 172 ScriptPromiseResolver* resolver,
174 payments::mojom::blink::PaymentAppManifestPtr manifest, 173 payments::mojom::blink::PaymentAppManifestPtr manifest,
175 payments::mojom::blink::PaymentAppManifestError error) { 174 payments::mojom::blink::PaymentAppManifestError error) {
176 DCHECK(resolver); 175 DCHECK(resolver);
177 switch (error) { 176 switch (error) {
178 case payments::mojom::blink::PaymentAppManifestError::NONE: 177 case payments::mojom::blink::PaymentAppManifestError::NONE:
179 resolver->resolve( 178 resolver->resolve(
180 mojo::ConvertTo<PaymentAppManifest>(std::move(manifest))); 179 mojo::ConvertTo<PaymentAppManifest>(std::move(manifest)));
181 break; 180 break;
182 case payments::mojom::blink::PaymentAppManifestError::NOT_IMPLEMENTED: 181 case payments::mojom::blink::PaymentAppManifestError::NOT_IMPLEMENTED:
183 resolver->reject( 182 resolver->reject(
184 DOMException::create(NotSupportedError, "Not implemented yet.")); 183 DOMException::create(NotSupportedError, "Not implemented yet."));
185 break; 184 break;
186 case payments::mojom::blink::PaymentAppManifestError::NO_ACTIVE_WORKER: 185 case payments::mojom::blink::PaymentAppManifestError::NO_ACTIVE_WORKER:
187 case payments::mojom::blink::PaymentAppManifestError:: 186 case payments::mojom::blink::PaymentAppManifestError::
188 MANIFEST_STORAGE_OPERATION_FAILED: 187 MANIFEST_STORAGE_OPERATION_FAILED:
189 resolver->reject(DOMException::create( 188 resolver->reject(DOMException::create(
190 AbortError, 189 AbortError,
191 "No payment app manifest associated with the service worker.")); 190 "No payment app manifest associated with the service worker."));
192 break; 191 break;
193 } 192 }
194 } 193 }
195 194
196 void PaymentAppManager::onServiceConnectionError() { 195 void PaymentManager::onServiceConnectionError() {
197 m_manager.reset(); 196 m_manager.reset();
198 } 197 }
199 198
200 } // namespace blink 199 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698