1// Copyright 2014 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#ifndef CHROME_BROWSER_SPEECH_EXTENSION_API_TTS_ENGINE_EXTENSION_OBSERVER_H_ 6#define CHROME_BROWSER_SPEECH_EXTENSION_API_TTS_ENGINE_EXTENSION_OBSERVER_H_ 7 8#include "base/scoped_observer.h" 9#include "components/keyed_service/core/keyed_service.h" 10#include "extensions/browser/event_router.h" 11#include "extensions/browser/extension_registry.h" 12#include "extensions/browser/extension_registry_observer.h" 13 14class Profile; 15 16// Profile-keyed class that observes the extension registry to determine load of 17// extension-based tts engines. 18class TtsEngineExtensionObserver 19 : public KeyedService, 20 public extensions::EventRouter::Observer, 21 public extensions::ExtensionRegistryObserver { 22 public: 23 static TtsEngineExtensionObserver* GetInstance(Profile* profile); 24 25 // Returns if this observer saw the given extension load. Adds |extension_id| 26 // as loaded immediately if |update| is set to true. 27 bool SawExtensionLoad(const std::string& extension_id, bool update); 28 29 // Implementation of KeyedService. 30 virtual void Shutdown() OVERRIDE; 31 32 // Implementation of extensions::EventRouter::Observer. 33 virtual void OnListenerAdded( 34 const extensions::EventListenerInfo& details) OVERRIDE; 35 36 // extensions::ExtensionRegistryObserver overrides. 37 virtual void OnExtensionUnloaded( 38 content::BrowserContext* browser_context, 39 const extensions::Extension* extension, 40 extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE; 41 42 private: 43 explicit TtsEngineExtensionObserver(Profile* profile); 44 virtual ~TtsEngineExtensionObserver(); 45 46 bool IsLoadedTtsEngine(const std::string& extension_id); 47 48 ScopedObserver<extensions::ExtensionRegistry, 49 extensions::ExtensionRegistryObserver> 50 extension_registry_observer_; 51 52 Profile* profile_; 53 54 std::set<std::string> engine_extension_ids_; 55 56 friend class TtsEngineExtensionObserverFactory; 57 58 DISALLOW_COPY_AND_ASSIGN(TtsEngineExtensionObserver); 59}; 60 61#endif // CHROME_BROWSER_SPEECH_EXTENSION_API_TTS_ENGINE_EXTENSION_OBSERVER_H_ 62