OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" | 5 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/extensions/api/omnibox/omnibox_api_factory.h" | |
14 #include "chrome/browser/extensions/event_router.h" | 13 #include "chrome/browser/extensions/event_router.h" |
15 #include "chrome/browser/extensions/extension_prefs.h" | 14 #include "chrome/browser/extensions/extension_prefs.h" |
16 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
17 #include "chrome/browser/extensions/extension_system.h" | 16 #include "chrome/browser/extensions/extension_system.h" |
18 #include "chrome/browser/extensions/tab_helper.h" | 17 #include "chrome/browser/extensions/tab_helper.h" |
19 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/search_engines/template_url.h" | 19 #include "chrome/browser/search_engines/template_url.h" |
21 #include "chrome/browser/search_engines/template_url_service.h" | 20 #include "chrome/browser/search_engines/template_url_service.h" |
22 #include "chrome/browser/search_engines/template_url_service_factory.h" | 21 #include "chrome/browser/search_engines/template_url_service_factory.h" |
23 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // Use monochrome icons for Omnibox icons. | 144 // Use monochrome icons for Omnibox icons. |
146 omnibox_popup_icon_manager_.set_monochrome(true); | 145 omnibox_popup_icon_manager_.set_monochrome(true); |
147 omnibox_icon_manager_.set_monochrome(true); | 146 omnibox_icon_manager_.set_monochrome(true); |
148 omnibox_icon_manager_.set_padding(gfx::Insets(0, kOmniboxIconPaddingLeft, | 147 omnibox_icon_manager_.set_padding(gfx::Insets(0, kOmniboxIconPaddingLeft, |
149 0, kOmniboxIconPaddingRight)); | 148 0, kOmniboxIconPaddingRight)); |
150 } | 149 } |
151 | 150 |
152 OmniboxAPI::~OmniboxAPI() { | 151 OmniboxAPI::~OmniboxAPI() { |
153 } | 152 } |
154 | 153 |
155 void OmniboxAPI::Shutdown() { | 154 base::LazyInstance<ProfileKeyedAPIFactory<OmniboxAPI> > |
| 155 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 156 |
| 157 // static |
| 158 ProfileKeyedAPIFactory<OmniboxAPI>* OmniboxAPI::GetFactoryInstance() { |
| 159 return &g_factory.Get(); |
156 } | 160 } |
157 | 161 |
158 // static | 162 // static |
159 OmniboxAPI* OmniboxAPI::Get(Profile* profile) { | 163 OmniboxAPI* OmniboxAPI::Get(Profile* profile) { |
160 return OmniboxAPIFactory::GetForProfile(profile); | 164 return ProfileKeyedAPIFactory<OmniboxAPI>::GetForProfile(profile); |
161 } | 165 } |
162 | 166 |
163 void OmniboxAPI::Observe(int type, | 167 void OmniboxAPI::Observe(int type, |
164 const content::NotificationSource& source, | 168 const content::NotificationSource& source, |
165 const content::NotificationDetails& details) { | 169 const content::NotificationDetails& details) { |
166 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { | 170 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { |
167 const Extension* extension = | 171 const Extension* extension = |
168 content::Details<const Extension>(details).ptr(); | 172 content::Details<const Extension>(details).ptr(); |
169 const std::string& keyword = OmniboxInfo::GetKeyword(extension); | 173 const std::string& keyword = OmniboxInfo::GetKeyword(extension); |
170 if (!keyword.empty()) { | 174 if (!keyword.empty()) { |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 for (size_t i = 0; i < description_styles.size(); ++i) { | 413 for (size_t i = 0; i < description_styles.size(); ++i) { |
410 if (description_styles[i].offset > placeholder) | 414 if (description_styles[i].offset > placeholder) |
411 description_styles[i].offset += replacement.length() - 2; | 415 description_styles[i].offset += replacement.length() - 2; |
412 } | 416 } |
413 } | 417 } |
414 | 418 |
415 match->contents.assign(description); | 419 match->contents.assign(description); |
416 } | 420 } |
417 | 421 |
418 } // namespace extensions | 422 } // namespace extensions |
OLD | NEW |