Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "chrome/browser/extensions/api/tabs/tabs_event_router.h" | |
| 8 #include "chrome/browser/extensions/api/tabs/windows_event_router.h" | 9 #include "chrome/browser/extensions/api/tabs/windows_event_router.h" |
| 9 #include "chrome/browser/extensions/event_router.h" | 10 #include "chrome/browser/extensions/event_router.h" |
| 10 #include "chrome/browser/extensions/extension_system.h" | 11 #include "chrome/browser/extensions/extension_system.h" |
| 12 #include "chrome/common/extensions/api/tabs.h" | |
| 11 #include "chrome/common/extensions/api/windows.h" | 13 #include "chrome/common/extensions/api/windows.h" |
| 12 | 14 |
| 13 namespace extensions { | 15 namespace extensions { |
| 14 | 16 |
| 15 namespace windows = api::windows; | 17 TabsWindowsAPI::TabsWindowsAPI(Profile* profile) : profile_(profile) { |
| 18 // Tabs API Events. | |
| 19 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | |
| 20 this, api::tabs::OnCreated::kEventName); | |
| 21 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | |
| 22 this, api::tabs::OnUpdated::kEventName); | |
| 23 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | |
| 24 this, api::tabs::OnMoved::kEventName); | |
| 25 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | |
| 26 this, api::tabs::OnSelectionChanged::kEventName); | |
| 27 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | |
| 28 this, api::tabs::OnActiveChanged::kEventName); | |
| 29 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | |
| 30 this, api::tabs::OnActivated::kEventName); | |
| 31 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | |
| 32 this, api::tabs::OnHighlightChanged::kEventName); | |
| 33 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | |
| 34 this, api::tabs::OnHighlighted::kEventName); | |
| 35 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | |
| 36 this, api::tabs::OnDetached::kEventName); | |
| 37 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | |
| 38 this, api::tabs::OnAttached::kEventName); | |
| 39 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | |
| 40 this, api::tabs::OnRemoved::kEventName); | |
| 41 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | |
| 42 this, api::tabs::OnReplaced::kEventName); | |
| 16 | 43 |
| 17 TabsWindowsAPI::TabsWindowsAPI(Profile* profile) | 44 // Windows API Events. |
| 18 : profile_(profile) { | |
| 19 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 45 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
| 20 this, windows::OnCreated::kEventName); | 46 this, api::windows::OnCreated::kEventName); |
| 21 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 47 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
| 22 this, windows::OnRemoved::kEventName); | 48 this, api::windows::OnRemoved::kEventName); |
| 23 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 49 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
| 24 this, windows::OnFocusChanged::kEventName); | 50 this, api::windows::OnFocusChanged::kEventName); |
| 25 } | 51 } |
| 26 | 52 |
| 27 TabsWindowsAPI::~TabsWindowsAPI() { | 53 TabsWindowsAPI::~TabsWindowsAPI() { |
| 28 } | 54 } |
| 29 | 55 |
| 30 // static | 56 // static |
| 31 TabsWindowsAPI* TabsWindowsAPI::Get(Profile* profile) { | 57 TabsWindowsAPI* TabsWindowsAPI::Get(Profile* profile) { |
| 32 return ProfileKeyedAPIFactory<TabsWindowsAPI>::GetForProfile(profile); | 58 return ProfileKeyedAPIFactory<TabsWindowsAPI>::GetForProfile(profile); |
| 33 } | 59 } |
| 34 | 60 |
| 61 TabsEventRouter* TabsWindowsAPI::tabs_event_router() { | |
| 62 if (!tabs_event_router_.get()) | |
| 63 tabs_event_router_.reset(new TabsEventRouter(profile_)); | |
| 64 return tabs_event_router_.get(); | |
| 65 } | |
| 66 | |
| 35 WindowsEventRouter* TabsWindowsAPI::windows_event_router() { | 67 WindowsEventRouter* TabsWindowsAPI::windows_event_router() { |
| 36 if (!windows_event_router_) | 68 if (!windows_event_router_) |
| 37 windows_event_router_.reset(new WindowsEventRouter(profile_)); | 69 windows_event_router_.reset(new WindowsEventRouter(profile_)); |
| 38 return windows_event_router_.get(); | 70 return windows_event_router_.get(); |
| 39 } | 71 } |
| 40 | 72 |
| 41 void TabsWindowsAPI::Shutdown() { | 73 void TabsWindowsAPI::Shutdown() { |
| 42 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 74 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
| 43 } | 75 } |
| 44 | 76 |
| 45 static base::LazyInstance<ProfileKeyedAPIFactory<TabsWindowsAPI> > | 77 static base::LazyInstance<ProfileKeyedAPIFactory<TabsWindowsAPI> > |
| 46 g_factory = LAZY_INSTANCE_INITIALIZER; | 78 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 47 | 79 |
| 48 ProfileKeyedAPIFactory<TabsWindowsAPI>* TabsWindowsAPI::GetFactoryInstance() { | 80 ProfileKeyedAPIFactory<TabsWindowsAPI>* TabsWindowsAPI::GetFactoryInstance() { |
| 49 return &g_factory.Get(); | 81 return &g_factory.Get(); |
| 50 } | 82 } |
| 51 | 83 |
| 52 void TabsWindowsAPI::OnListenerAdded( | 84 void TabsWindowsAPI::OnListenerAdded(const EventListenerInfo& details) { |
| 53 const extensions::EventListenerInfo& details) { | 85 // Initialize the event routers. |
| 86 tabs_event_router(); | |
|
Devlin
2013/09/10 00:47:37
If we *really* wanted to, we could separate out in
| |
| 54 windows_event_router(); | 87 windows_event_router(); |
| 55 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 88 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
| 56 } | 89 } |
| 57 | 90 |
| 58 } // namespace extensions | 91 } // namespace extensions |
| OLD | NEW |