app_list: Re-enable people search.
[chromium-blink-merge.git] / chrome / browser / extensions / settings_api_helpers.cc
blob2fcd9c8670c4f0c7dc0818e21bd8d8ad3342453b
1 // Copyright (c) 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.
5 #include "chrome/browser/extensions/settings_api_helpers.h"
7 #include "chrome/browser/extensions/api/preference/preference_api.h"
8 #include "chrome/common/pref_names.h"
9 #include "components/search_engines/search_engines_pref_names.h"
10 #include "extensions/browser/extension_pref_value_map.h"
11 #include "extensions/browser/extension_pref_value_map_factory.h"
12 #include "extensions/browser/extension_registry.h"
13 #include "extensions/common/extension_set.h"
15 namespace extensions {
17 namespace {
19 // Returns which |extension| (if any) is overriding a particular |type| of
20 // setting.
21 const Extension* FindOverridingExtension(
22 content::BrowserContext* browser_context,
23 SettingsApiOverrideType type) {
24 const ExtensionSet& extensions =
25 ExtensionRegistry::Get(browser_context)->enabled_extensions();
27 for (ExtensionSet::const_iterator it = extensions.begin();
28 it != extensions.end();
29 ++it) {
30 const SettingsOverrides* settings = SettingsOverrides::Get(it->get());
31 if (settings) {
32 if (type == BUBBLE_TYPE_HOME_PAGE && !settings->homepage)
33 continue;
34 if (type == BUBBLE_TYPE_STARTUP_PAGES && settings->startup_pages.empty())
35 continue;
36 if (type == BUBBLE_TYPE_SEARCH_ENGINE && !settings->search_engine)
37 continue;
39 std::string key;
40 switch (type) {
41 case BUBBLE_TYPE_HOME_PAGE:
42 key = prefs::kHomePage;
43 break;
44 case BUBBLE_TYPE_STARTUP_PAGES:
45 key = prefs::kRestoreOnStartup;
46 break;
47 case BUBBLE_TYPE_SEARCH_ENGINE:
48 key = prefs::kDefaultSearchProviderEnabled;
49 break;
52 // Found an extension overriding the current type, check if primary.
53 PreferenceAPI* preference_api = PreferenceAPI::Get(browser_context);
54 if (preference_api && // Expected to be NULL in unit tests.
55 !preference_api->DoesExtensionControlPref((*it)->id(), key, NULL))
56 continue; // Not primary.
58 // Found the primary extension.
59 return it->get();
63 return NULL;
66 } // namespace
68 const Extension* GetExtensionOverridingHomepage(
69 content::BrowserContext* browser_context) {
70 return FindOverridingExtension(browser_context, BUBBLE_TYPE_HOME_PAGE);
73 const Extension* GetExtensionOverridingStartupPages(
74 content::BrowserContext* browser_context) {
75 return FindOverridingExtension(browser_context, BUBBLE_TYPE_STARTUP_PAGES);
78 const Extension* GetExtensionOverridingSearchEngine(
79 content::BrowserContext* browser_context) {
80 return FindOverridingExtension(browser_context, BUBBLE_TYPE_SEARCH_ENGINE);
83 const Extension* GetExtensionOverridingProxy(
84 content::BrowserContext* browser_context) {
85 ExtensionPrefValueMap* extension_prefs_value_map =
86 ExtensionPrefValueMapFactory::GetForBrowserContext(browser_context);
87 if (!extension_prefs_value_map)
88 return NULL; // Can be null during testing.
89 std::string extension_id =
90 extension_prefs_value_map->GetExtensionControllingPref(prefs::kProxy);
91 if (extension_id.empty())
92 return NULL;
93 return ExtensionRegistry::Get(browser_context)->GetExtensionById(
94 extension_id, ExtensionRegistry::ENABLED);
97 } // namespace extensions