- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / settings_overrides / settings_overrides_api.h
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_SETTINGS_OVERRIDES_SETTINGS_OVERRIDES_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SETTINGS_OVERRIDES_SETTINGS_OVERRIDES_API_H_
7
8 #include <set>
9 #include <string>
10
11 #include "base/basictypes.h"
12 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
13 #include "chrome/browser/search_engines/template_url_service.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
16
17 class TemplateURL;
18
19 namespace extensions {
20
21 class SettingsOverridesAPI : public ProfileKeyedAPI,
22                              public content::NotificationObserver {
23  public:
24   explicit SettingsOverridesAPI(Profile* profile);
25   virtual ~SettingsOverridesAPI();
26
27   // ProfileKeyedAPI implementation.
28   static ProfileKeyedAPIFactory<SettingsOverridesAPI>* GetFactoryInstance();
29
30  private:
31   friend class ProfileKeyedAPIFactory<SettingsOverridesAPI>;
32
33   typedef std::set<scoped_refptr<const Extension> > PendingExtensions;
34
35   // Wrappers around PreferenceAPI.
36   void SetPref(const std::string& extension_id,
37                const std::string& pref_key,
38                base::Value* value);
39   void UnsetPref(const std::string& extension_id,
40                  const std::string& pref_key);
41   // content::NotificationObserver implementation.
42   virtual void Observe(int type,
43                        const content::NotificationSource& source,
44                        const content::NotificationDetails& details) OVERRIDE;
45   // BrowserContextKeyedService implementation.
46   virtual void Shutdown() OVERRIDE;
47
48   void OnTemplateURLsLoaded();
49
50   void RegisterSearchProvider(const Extension* extension) const;
51   // ProfileKeyedAPI implementation.
52   static const char* service_name() { return "SettingsOverridesAPI"; }
53
54   Profile* profile_;
55   TemplateURLService* url_service_;
56
57   // List of extensions waiting for the TemplateURLService to Load to
58   // have search provider registered.
59   PendingExtensions pending_extensions_;
60
61   content::NotificationRegistrar registrar_;
62   scoped_ptr<TemplateURLService::Subscription> template_url_sub_;
63
64   DISALLOW_COPY_AND_ASSIGN(SettingsOverridesAPI);
65 };
66
67 template <>
68 void ProfileKeyedAPIFactory<SettingsOverridesAPI>::DeclareFactoryDependencies();
69
70 }  // namespace extensions
71
72 #endif  // CHROME_BROWSER_EXTENSIONS_API_SETTINGS_OVERRIDES_SETTINGS_OVERRIDES_API_H_