11e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
21e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
31e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// found in the LICENSE file.
41e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#ifndef CHROME_BROWSER_EXTENSIONS_API_SETTINGS_OVERRIDES_SETTINGS_OVERRIDES_API_H_
61e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#define CHROME_BROWSER_EXTENSIONS_API_SETTINGS_OVERRIDES_SETTINGS_OVERRIDES_API_H_
71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include <set>
91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include <string>
101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/basictypes.h"
121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/search_engines/template_url_service.h"
141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "content/public/browser/notification_observer.h"
151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "content/public/browser/notification_registrar.h"
161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TemplateURL;
181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace extensions {
201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class SettingsOverridesAPI : public ProfileKeyedAPI,
221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                             public content::NotificationObserver {
231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public:
241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  explicit SettingsOverridesAPI(Profile* profile);
251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual ~SettingsOverridesAPI();
261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // ProfileKeyedAPI implementation.
281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  static ProfileKeyedAPIFactory<SettingsOverridesAPI>* GetFactoryInstance();
291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) private:
311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  friend class ProfileKeyedAPIFactory<SettingsOverridesAPI>;
321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  typedef std::set<scoped_refptr<const Extension> > PendingExtensions;
341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Wrappers around PreferenceAPI.
361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void SetPref(const std::string& extension_id,
371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)               const std::string& pref_key,
381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)               base::Value* value);
391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void UnsetPref(const std::string& extension_id,
401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                 const std::string& pref_key);
411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // content::NotificationObserver implementation.
421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void Observe(int type,
431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                       const content::NotificationSource& source,
441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                       const content::NotificationDetails& details) OVERRIDE;
451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // BrowserContextKeyedService implementation.
461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void Shutdown() OVERRIDE;
471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void OnTemplateURLsLoaded();
491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void RegisterSearchProvider(const Extension* extension) const;
511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // ProfileKeyedAPI implementation.
521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  static const char* service_name() { return "SettingsOverridesAPI"; }
531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  Profile* profile_;
551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TemplateURLService* url_service_;
561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // List of extensions waiting for the TemplateURLService to Load to
581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // have search provider registered.
591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  PendingExtensions pending_extensions_;
601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  content::NotificationRegistrar registrar_;
621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  scoped_ptr<TemplateURLService::Subscription> template_url_sub_;
631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SettingsOverridesAPI);
651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)};
661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
67f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)template <>
68f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void ProfileKeyedAPIFactory<SettingsOverridesAPI>::DeclareFactoryDependencies();
69f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}  // namespace extensions
711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#endif  // CHROME_BROWSER_EXTENSIONS_API_SETTINGS_OVERRIDES_SETTINGS_OVERRIDES_API_H_
73