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 "modules/budget/BudgetService.h" | 5 #include "modules/budget/BudgetService.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptPromise.h" | 7 #include "bindings/core/v8/ScriptPromise.h" |
| 8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
| 10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 ScriptPromise BudgetService::getCost(ScriptState* scriptState, | 58 ScriptPromise BudgetService::getCost(ScriptState* scriptState, |
| 59 const AtomicString& operation) { | 59 const AtomicString& operation) { |
| 60 DCHECK(m_service); | 60 DCHECK(m_service); |
| 61 | 61 |
| 62 String errorMessage; | 62 String errorMessage; |
| 63 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) | 63 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) |
| 64 return ScriptPromise::rejectWithDOMException( | 64 return ScriptPromise::rejectWithDOMException( |
| 65 scriptState, DOMException::create(SecurityError, errorMessage)); | 65 scriptState, DOMException::create(SecurityError, errorMessage)); |
| 66 | 66 |
| 67 mojom::blink::BudgetOperationType type = stringToOperationType(operation); | 67 mojom::blink::BudgetOperationType type = stringToOperationType(operation); |
| 68 if (type == mojom::blink::BudgetOperationType::INVALID_OPERATION) | 68 DCHECK(type != mojom::blink::BudgetOperationType::INVALID_OPERATION); |
|
Peter Beverloo
2016/12/12 14:22:00
Please check whether the following works instead:
harkness
2016/12/12 15:00:43
I didn't realize the macro was flexible enough to
| |
| 69 return ScriptPromise::rejectWithDOMException( | |
| 70 scriptState, DOMException::create(NotSupportedError, | |
| 71 "Invalid operation type specified")); | |
| 72 | 69 |
| 73 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 70 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 74 ScriptPromise promise = resolver->promise(); | 71 ScriptPromise promise = resolver->promise(); |
| 75 | 72 |
| 76 // Get the cost for the action from the browser BudgetService. | 73 // Get the cost for the action from the browser BudgetService. |
| 77 m_service->GetCost(type, convertToBaseCallback(WTF::bind( | 74 m_service->GetCost(type, convertToBaseCallback(WTF::bind( |
| 78 &BudgetService::gotCost, wrapPersistent(this), | 75 &BudgetService::gotCost, wrapPersistent(this), |
| 79 wrapPersistent(resolver)))); | 76 wrapPersistent(resolver)))); |
| 80 return promise; | 77 return promise; |
| 81 } | 78 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 new BudgetState(expectations[i]->budget_at, expectations[i]->time); | 119 new BudgetState(expectations[i]->budget_at, expectations[i]->time); |
| 123 | 120 |
| 124 resolver->resolve(budget); | 121 resolver->resolve(budget); |
| 125 } | 122 } |
| 126 | 123 |
| 127 ScriptPromise BudgetService::reserve(ScriptState* scriptState, | 124 ScriptPromise BudgetService::reserve(ScriptState* scriptState, |
| 128 const AtomicString& operation) { | 125 const AtomicString& operation) { |
| 129 DCHECK(m_service); | 126 DCHECK(m_service); |
| 130 | 127 |
| 131 mojom::blink::BudgetOperationType type = stringToOperationType(operation); | 128 mojom::blink::BudgetOperationType type = stringToOperationType(operation); |
| 132 if (type == mojom::blink::BudgetOperationType::INVALID_OPERATION) | 129 DCHECK(type != mojom::blink::BudgetOperationType::INVALID_OPERATION); |
| 133 return ScriptPromise::rejectWithDOMException( | |
| 134 scriptState, DOMException::create(NotSupportedError, | |
| 135 "Invalid operation type specified")); | |
| 136 | 130 |
| 137 String errorMessage; | 131 String errorMessage; |
| 138 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) | 132 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) |
| 139 return ScriptPromise::rejectWithDOMException( | 133 return ScriptPromise::rejectWithDOMException( |
| 140 scriptState, DOMException::create(SecurityError, errorMessage)); | 134 scriptState, DOMException::create(SecurityError, errorMessage)); |
| 141 | 135 |
| 142 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 136 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 143 ScriptPromise promise = resolver->promise(); | 137 ScriptPromise promise = resolver->promise(); |
| 144 | 138 |
| 145 // Call to the BudgetService to place the reservation. | 139 // Call to the BudgetService to place the reservation. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 162 | 156 |
| 163 resolver->resolve(success); | 157 resolver->resolve(success); |
| 164 } | 158 } |
| 165 | 159 |
| 166 void BudgetService::onConnectionError() { | 160 void BudgetService::onConnectionError() { |
| 167 LOG(ERROR) << "Unable to connect to the Mojo BudgetService."; | 161 LOG(ERROR) << "Unable to connect to the Mojo BudgetService."; |
| 168 // TODO(harkness): Reject in flight promises. | 162 // TODO(harkness): Reject in flight promises. |
| 169 } | 163 } |
| 170 | 164 |
| 171 } // namespace blink | 165 } // namespace blink |
| OLD | NEW |