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

Side by Side Diff: third_party/WebKit/Source/modules/budget/BudgetService.cpp

Issue 2620393002: Refactor budget computation to be more tuneable. (Closed)
Patch Set: Changed LayoutTest to expect integral budgets. (Also rebased) Created 3 years, 11 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
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/budget/budget-service-mock.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.
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 // Return the largest integer less than the budget, so it's easier for
119 new BudgetState(expectations[i]->budget_at, expectations[i]->time); 119 // developer to reason about budget.
120 budget[i] = new BudgetState(floor(expectations[i]->budget_at),
121 expectations[i]->time);
122 }
120 123
121 resolver->resolve(budget); 124 resolver->resolve(budget);
122 } 125 }
123 126
124 ScriptPromise BudgetService::reserve(ScriptState* scriptState, 127 ScriptPromise BudgetService::reserve(ScriptState* scriptState,
125 const AtomicString& operation) { 128 const AtomicString& operation) {
126 DCHECK(m_service); 129 DCHECK(m_service);
127 130
128 mojom::blink::BudgetOperationType type = stringToOperationType(operation); 131 mojom::blink::BudgetOperationType type = stringToOperationType(operation);
129 DCHECK_NE(type, mojom::blink::BudgetOperationType::INVALID_OPERATION); 132 DCHECK_NE(type, mojom::blink::BudgetOperationType::INVALID_OPERATION);
(...skipping 26 matching lines...) Expand all
156 159
157 resolver->resolve(success); 160 resolver->resolve(success);
158 } 161 }
159 162
160 void BudgetService::onConnectionError() { 163 void BudgetService::onConnectionError() {
161 LOG(ERROR) << "Unable to connect to the Mojo BudgetService."; 164 LOG(ERROR) << "Unable to connect to the Mojo BudgetService.";
162 // TODO(harkness): Reject in flight promises. 165 // TODO(harkness): Reject in flight promises.
163 } 166 }
164 167
165 } // namespace blink 168 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/budget/budget-service-mock.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698