1 // Copyright 2013 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_EXTENSIONS_API_PREFERENCE_CHROME_DIRECT_SETTING_API_H__ 6 #define CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_CHROME_DIRECT_SETTING_API_H__ 7 8 #include "base/prefs/pref_change_registrar.h" 9 #include "extensions/browser/browser_context_keyed_api_factory.h" 10 #include "extensions/browser/event_router.h" 11 12 class Profile; 13 14 namespace content { 15 class BrowserContext; 16 } 17 18 namespace extensions { 19 namespace chromedirectsetting { 20 21 class ChromeDirectSettingAPI : public BrowserContextKeyedAPI, 22 public EventRouter::Observer { 23 public: 24 explicit ChromeDirectSettingAPI(content::BrowserContext* context); 25 26 virtual ~ChromeDirectSettingAPI(); 27 28 // KeyedService implementation. 29 virtual void Shutdown() OVERRIDE; 30 31 // BrowserContextKeyedAPI implementation. 32 static BrowserContextKeyedAPIFactory<ChromeDirectSettingAPI>* 33 GetFactoryInstance(); 34 35 // EventRouter::Observer implementation. 36 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; 37 38 // Returns true if the preference is on the whitelist. 39 bool IsPreferenceOnWhitelist(const std::string& pref_key); 40 41 // Convenience method to get the ChromeDirectSettingAPI for a profile. 42 static ChromeDirectSettingAPI* Get(content::BrowserContext* context); 43 44 private: 45 friend class BrowserContextKeyedAPIFactory<ChromeDirectSettingAPI>; 46 47 // BrowserContextKeyedAPI implementation. 48 static const char* service_name(); 49 50 void OnPrefChanged(PrefService* pref_service, const std::string& pref_key); 51 52 static const bool kServiceIsNULLWhileTesting = true; 53 static const bool kServiceRedirectedInIncognito = false; 54 55 PrefChangeRegistrar registrar_; 56 Profile* profile_; 57 58 DISALLOW_COPY_AND_ASSIGN(ChromeDirectSettingAPI); 59 }; 60 61 } // namespace chromedirectsetting 62 } // namespace extensions 63 64 #endif // CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_CHROME_DIRECT_SETTING_API_H__ 65