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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 | 105 |
| 106 void BudgetService::gotBudget( | 106 void BudgetService::gotBudget( |
| 107 ScriptPromiseResolver* resolver, | 107 ScriptPromiseResolver* resolver, |
| 108 mojom::blink::BudgetServiceErrorType error, | 108 mojom::blink::BudgetServiceErrorType error, |
| 109 const WTF::Vector<mojom::blink::BudgetStatePtr> expectations) const { | 109 const WTF::Vector<mojom::blink::BudgetStatePtr> expectations) const { |
| 110 if (error != mojom::blink::BudgetServiceErrorType::NONE) { | 110 if (error != mojom::blink::BudgetServiceErrorType::NONE) { |
| 111 resolver->reject(errorTypeToException(error)); | 111 resolver->reject(errorTypeToException(error)); |
| 112 return; | 112 return; |
| 113 } | 113 } |
| 114 | 114 |
| 115 // Copy the chunks into the budget array. | 115 // Copy the chunks into the budget array. |
|
Peter Beverloo
2017/01/12 14:40:04
nit: Please document why we're flooring.
harkness
2017/01/12 17:44:15
Done.
| |
| 116 HeapVector<Member<BudgetState>> budget(expectations.size()); | 116 HeapVector<Member<BudgetState>> budget(expectations.size()); |
| 117 for (size_t i = 0; i < expectations.size(); i++) | 117 for (size_t i = 0; i < expectations.size(); i++) { |
| 118 budget[i] = | 118 budget[i] = new BudgetState(floor(expectations[i]->budget_at), |
| 119 new BudgetState(expectations[i]->budget_at, expectations[i]->time); | 119 expectations[i]->time); |
| 120 } | |
| 120 | 121 |
| 121 resolver->resolve(budget); | 122 resolver->resolve(budget); |
| 122 } | 123 } |
| 123 | 124 |
| 124 ScriptPromise BudgetService::reserve(ScriptState* scriptState, | 125 ScriptPromise BudgetService::reserve(ScriptState* scriptState, |
| 125 const AtomicString& operation) { | 126 const AtomicString& operation) { |
| 126 DCHECK(m_service); | 127 DCHECK(m_service); |
| 127 | 128 |
| 128 mojom::blink::BudgetOperationType type = stringToOperationType(operation); | 129 mojom::blink::BudgetOperationType type = stringToOperationType(operation); |
| 129 DCHECK_NE(type, mojom::blink::BudgetOperationType::INVALID_OPERATION); | 130 DCHECK_NE(type, mojom::blink::BudgetOperationType::INVALID_OPERATION); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 156 | 157 |
| 157 resolver->resolve(success); | 158 resolver->resolve(success); |
| 158 } | 159 } |
| 159 | 160 |
| 160 void BudgetService::onConnectionError() { | 161 void BudgetService::onConnectionError() { |
| 161 LOG(ERROR) << "Unable to connect to the Mojo BudgetService."; | 162 LOG(ERROR) << "Unable to connect to the Mojo BudgetService."; |
| 162 // TODO(harkness): Reject in flight promises. | 163 // TODO(harkness): Reject in flight promises. |
| 163 } | 164 } |
| 164 | 165 |
| 165 } // namespace blink | 166 } // namespace blink |
| OLD | NEW |