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

Unified Diff: third_party/WebKit/Source/modules/budget_service/NavigatorBudget.cpp

Issue 2110833002: Basic framework for Budget API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added BudgetChunk.idl Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/budget_service/NavigatorBudget.cpp
diff --git a/third_party/WebKit/Source/modules/budget_service/NavigatorBudget.cpp b/third_party/WebKit/Source/modules/budget_service/NavigatorBudget.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0fc56bcf5f01578df595df6c3f633502420709c6
--- /dev/null
+++ b/third_party/WebKit/Source/modules/budget_service/NavigatorBudget.cpp
@@ -0,0 +1,77 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "modules/budget_service/NavigatorBudget.h"
+
+#include "bindings/core/v8/ScriptPromise.h"
+#include "bindings/core/v8/ScriptPromiseResolver.h"
+#include "bindings/core/v8/ScriptState.h"
Peter Beverloo 2016/07/01 13:21:59 unused
harkness 2016/07/20 09:41:48 It's used now.
+#include "core/dom/ExceptionCode.h"
Peter Beverloo 2016/07/01 13:21:59 unused
harkness 2016/07/20 09:41:48 It's used now. :)
+#include "core/frame/Navigator.h"
+
+namespace blink {
+
+NavigatorBudget::NavigatorBudget(Navigator& navigator)
+{
+}
+
+NavigatorBudget::~NavigatorBudget() {}
+
+// Static
Peter Beverloo 2016/07/01 13:21:59 nit: // static (no capital) dito on lines 27, 41
harkness 2016/07/20 09:41:48 Done.
+const char* NavigatorBudget::supplementName()
+{
+ return "NavigatorBudget";
+}
+
+// Static
+NavigatorBudget& NavigatorBudget::from(Navigator& navigator)
+{
+ // Get the unique NavigatorBudget associated with this navigator.
+ NavigatorBudget* navigatorBudget = static_cast<NavigatorBudget*>(Supplement<Navigator>::from(navigator, supplementName()));
+ if (!navigatorBudget) {
+ // If there has not already been a NavigatorBudget created for
+ // this navigator, create one now and associate it.
+ navigatorBudget = new NavigatorBudget(navigator);
+ Supplement<Navigator>::provideTo(navigator, supplementName(), navigatorBudget);
+ }
+ return *navigatorBudget;
+}
+
+// Static
+ScriptPromise NavigatorBudget::getCost(ScriptState* state,
+ Navigator& navigator,
+ const AtomicString& actionType)
Peter Beverloo 2016/07/01 13:21:59 nit: here (and with the other method definitions):
harkness 2016/07/20 09:41:48 Done.
+{
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(state);
+ ScriptPromise promise = resolver->promise();
+
+ // TODO(harkness): Trigger the cost calculation.
+ return promise;
+}
+
+// Static
+ScriptPromise NavigatorBudget::getBudget(ScriptState* state,
+ Navigator& navigator,
+ ExceptionState& exception)
+{
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(state);
+ ScriptPromise promise = resolver->promise();
+
+ // TODO(harkness): Trigger the budget calculation.
+ return promise;
+}
+
+// Static
+ScriptPromise NavigatorBudget::getBudgetDetails(ScriptState* state,
+ Navigator& navigator,
+ ExceptionState& exception)
+{
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(state);
+ ScriptPromise promise = resolver->promise();
+
+ // TODO(harkness): Trigger the budget calculation.
+ return promise;
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698