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

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

Issue 2110833002: Basic framework for Budget API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed Exposed lines and fixed build error. Created 4 years, 4 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/NavigatorBudget.cpp
diff --git a/third_party/WebKit/Source/modules/budget/NavigatorBudget.cpp b/third_party/WebKit/Source/modules/budget/NavigatorBudget.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..a7f36bd4e44463adbcdc8c6e382f2e1e39033442
--- /dev/null
+++ b/third_party/WebKit/Source/modules/budget/NavigatorBudget.cpp
@@ -0,0 +1,54 @@
+// 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/NavigatorBudget.h"
+
+#include "core/frame/Navigator.h"
+#include "modules/budget/Budget.h"
+
+namespace blink {
+
+NavigatorBudget::NavigatorBudget()
+{
+}
+
+// static
+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 isn't one already, create it now and associate it.
+ navigatorBudget = new NavigatorBudget();
+ Supplement<Navigator>::provideTo(navigator, supplementName(), navigatorBudget);
+ }
+ return *navigatorBudget;
+}
+
+Budget* NavigatorBudget::budget()
+{
+ if (!m_budget)
+ m_budget = Budget::create();
+ return m_budget.get();
+}
+
+// static
+Budget* NavigatorBudget::budget(Navigator& navigator)
+{
+ return NavigatorBudget::from(navigator).budget();
+}
+
+DEFINE_TRACE(NavigatorBudget)
+{
+ visitor->trace(m_budget);
+ Supplement<Navigator>::trace(visitor);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698