Home | History | Annotate | Download | only in tabs
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h"
      6 
      7 #include "base/lazy_instance.h"
      8 #include "chrome/browser/extensions/api/tabs/windows_event_router.h"
      9 #include "chrome/browser/extensions/event_names.h"
     10 #include "chrome/browser/extensions/event_router.h"
     11 #include "chrome/browser/extensions/extension_system.h"
     12 
     13 namespace extensions {
     14 
     15 TabsWindowsAPI::TabsWindowsAPI(Profile* profile)
     16     : profile_(profile) {
     17   ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
     18       this, event_names::kOnWindowCreated);
     19   ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
     20       this, event_names::kOnWindowRemoved);
     21   ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
     22       this, event_names::kOnWindowFocusedChanged);
     23 }
     24 
     25 TabsWindowsAPI::~TabsWindowsAPI() {
     26 }
     27 
     28 // static
     29 TabsWindowsAPI* TabsWindowsAPI::Get(Profile* profile) {
     30   return ProfileKeyedAPIFactory<TabsWindowsAPI>::GetForProfile(profile);
     31 }
     32 
     33 WindowsEventRouter* TabsWindowsAPI::windows_event_router() {
     34   if (!windows_event_router_)
     35     windows_event_router_.reset(new WindowsEventRouter(profile_));
     36   return windows_event_router_.get();
     37 }
     38 
     39 void TabsWindowsAPI::Shutdown() {
     40   ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
     41 }
     42 
     43 static base::LazyInstance<ProfileKeyedAPIFactory<TabsWindowsAPI> >
     44 g_factory = LAZY_INSTANCE_INITIALIZER;
     45 
     46 ProfileKeyedAPIFactory<TabsWindowsAPI>* TabsWindowsAPI::GetFactoryInstance() {
     47   return &g_factory.Get();
     48 }
     49 
     50 void TabsWindowsAPI::OnListenerAdded(
     51     const extensions::EventListenerInfo& details) {
     52   windows_event_router();
     53   ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
     54 }
     55 
     56 }  // namespace extensions
     57