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

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_windows_api.cc

Issue 11649053: Banish boilerplate. Profile-keyed API factory for extension API classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: jyasskin's Created 7 years, 12 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/tabs/tabs_windows_api.h" 5 #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h"
6 6
7 #include "chrome/browser/extensions/api/tabs/tabs_windows_api_factory.h" 7 #include "base/lazy_instance.h"
8 #include "chrome/browser/extensions/api/tabs/windows_event_router.h" 8 #include "chrome/browser/extensions/api/tabs/windows_event_router.h"
9 #include "chrome/browser/extensions/event_names.h" 9 #include "chrome/browser/extensions/event_names.h"
10 #include "chrome/browser/extensions/event_router.h" 10 #include "chrome/browser/extensions/event_router.h"
11 #include "chrome/browser/extensions/extension_system.h" 11 #include "chrome/browser/extensions/extension_system.h"
12 12
13 namespace extensions { 13 namespace extensions {
14 14
15 TabsWindowsAPI::TabsWindowsAPI(Profile* profile) 15 TabsWindowsAPI::TabsWindowsAPI(Profile* profile)
16 : profile_(profile) { 16 : profile_(profile) {
17 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( 17 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
18 this, event_names::kOnWindowCreated); 18 this, event_names::kOnWindowCreated);
19 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( 19 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
20 this, event_names::kOnWindowRemoved); 20 this, event_names::kOnWindowRemoved);
21 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( 21 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
22 this, event_names::kOnWindowFocusedChanged); 22 this, event_names::kOnWindowFocusedChanged);
23 } 23 }
24 24
25 TabsWindowsAPI::~TabsWindowsAPI() { 25 TabsWindowsAPI::~TabsWindowsAPI() {
26 } 26 }
27 27
28 // static 28 // static
29 TabsWindowsAPI* TabsWindowsAPI::Get(Profile* profile) { 29 TabsWindowsAPI* TabsWindowsAPI::Get(Profile* profile) {
30 return TabsWindowsAPIFactory::GetForProfile(profile); 30 return ProfileKeyedAPIFactory<TabsWindowsAPI>::GetForProfile(profile);
31 } 31 }
32 32
33 WindowsEventRouter* TabsWindowsAPI::windows_event_router() { 33 WindowsEventRouter* TabsWindowsAPI::windows_event_router() {
34 if (!windows_event_router_) 34 if (!windows_event_router_)
35 windows_event_router_.reset(new WindowsEventRouter(profile_)); 35 windows_event_router_.reset(new WindowsEventRouter(profile_));
36 return windows_event_router_.get(); 36 return windows_event_router_.get();
37 } 37 }
38 38
39 void TabsWindowsAPI::Shutdown() { 39 void TabsWindowsAPI::Shutdown() {
40 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); 40 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
41 } 41 }
42 42
43 void TabsWindowsAPI::OnListenerAdded( 43 void TabsWindowsAPI::OnListenerAdded(
44 const extensions::EventListenerInfo& details) { 44 const extensions::EventListenerInfo& details) {
45 windows_event_router(); 45 windows_event_router();
46 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); 46 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
47 } 47 }
48 48
49 static base::LazyInstance<ProfileKeyedAPIFactory<TabsWindowsAPI> >
50 g_factory = LAZY_INSTANCE_INITIALIZER;
51
52 template <>
53 ProfileKeyedAPIFactory<TabsWindowsAPI>*
54 ProfileKeyedAPIFactory<TabsWindowsAPI>::GetInstance() {
55 return &g_factory.Get();
56 }
57
49 } // namespace extensions 58 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs_windows_api.h ('k') | chrome/browser/extensions/api/tabs/tabs_windows_api_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698