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..ca1ff5c9685efcea8f46b0d5981a2fe3c792aa9d |
--- /dev/null |
+++ b/third_party/WebKit/Source/modules/budget/NavigatorBudget.cpp |
@@ -0,0 +1,61 @@ |
+// 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(Navigator* navigator) |
+ : m_navigator(navigator) |
+{ |
+} |
+ |
+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 has not already been a NavigatorBudget created for |
+ // this navigator, create one now and associate it. |
Peter Beverloo
2016/08/03 13:25:55
nit: the comment on line 33/34 doesn't really add
harkness
2016/08/04 14:18:23
It's not a huge value, but I do think it makes the
|
+ navigatorBudget = new NavigatorBudget(&navigator); |
+ Supplement<Navigator>::provideTo(navigator, supplementName(), navigatorBudget); |
+ } |
+ return *navigatorBudget; |
+} |
+ |
+// static |
+Budget* NavigatorBudget::budget() |
+{ |
+ if (!m_budget) |
+ m_budget = Budget::create(m_navigator); |
+ return m_budget.get(); |
+} |
+ |
+Budget* NavigatorBudget::budget(Navigator& navigator) |
+{ |
+ return NavigatorBudget::from(navigator).budget(); |
+} |
+ |
+DEFINE_TRACE(NavigatorBudget) |
+{ |
+ visitor->trace(m_navigator); |
+ visitor->trace(m_budget); |
+ Supplement<Navigator>::trace(visitor); |
+} |
+ |
+} // namespace blink |