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

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

Issue 2646383002: Use a new Supplement constructor for (Worker)Navigator supplements (Closed)
Patch Set: temp 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
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/NavigatorBudget.h" 5 #include "modules/budget/NavigatorBudget.h"
6 6
7 #include "core/frame/Navigator.h" 7 #include "core/frame/Navigator.h"
8 #include "modules/budget/BudgetService.h" 8 #include "modules/budget/BudgetService.h"
9 9
10 namespace blink { 10 namespace blink {
11 11
12 NavigatorBudget::NavigatorBudget() {} 12 NavigatorBudget::NavigatorBudget(Navigator& navigator)
13 : Supplement<Navigator>(navigator) {}
13 14
14 // static 15 // static
15 const char* NavigatorBudget::supplementName() { 16 const char* NavigatorBudget::supplementName() {
16 return "NavigatorBudget"; 17 return "NavigatorBudget";
17 } 18 }
18 19
19 // static 20 // static
20 NavigatorBudget& NavigatorBudget::from(Navigator& navigator) { 21 NavigatorBudget& NavigatorBudget::from(Navigator& navigator) {
21 // Get the unique NavigatorBudget associated with this navigator. 22 // Get the unique NavigatorBudget associated with this navigator.
22 NavigatorBudget* navigatorBudget = static_cast<NavigatorBudget*>( 23 NavigatorBudget* navigatorBudget = static_cast<NavigatorBudget*>(
23 Supplement<Navigator>::from(navigator, supplementName())); 24 Supplement<Navigator>::from(navigator, supplementName()));
24 if (!navigatorBudget) { 25 if (!navigatorBudget) {
25 // If there isn't one already, create it now and associate it. 26 // If there isn't one already, create it now and associate it.
26 navigatorBudget = new NavigatorBudget(); 27 navigatorBudget = new NavigatorBudget(navigator);
27 Supplement<Navigator>::provideTo(navigator, supplementName(), 28 Supplement<Navigator>::provideTo(navigator, supplementName(),
28 navigatorBudget); 29 navigatorBudget);
29 } 30 }
30 return *navigatorBudget; 31 return *navigatorBudget;
31 } 32 }
32 33
33 BudgetService* NavigatorBudget::budget() { 34 BudgetService* NavigatorBudget::budget() {
34 if (!m_budget) 35 if (!m_budget)
35 m_budget = BudgetService::create(); 36 m_budget = BudgetService::create();
36 return m_budget.get(); 37 return m_budget.get();
37 } 38 }
38 39
39 // static 40 // static
40 BudgetService* NavigatorBudget::budget(Navigator& navigator) { 41 BudgetService* NavigatorBudget::budget(Navigator& navigator) {
41 return NavigatorBudget::from(navigator).budget(); 42 return NavigatorBudget::from(navigator).budget();
42 } 43 }
43 44
44 DEFINE_TRACE(NavigatorBudget) { 45 DEFINE_TRACE(NavigatorBudget) {
45 visitor->trace(m_budget); 46 visitor->trace(m_budget);
46 Supplement<Navigator>::trace(visitor); 47 Supplement<Navigator>::trace(visitor);
47 } 48 }
48 49
49 } // namespace blink 50 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698