Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: chrome/browser/extensions/api/omnibox/omnibox_api.cc

Issue 11682005: Remove some Profile-keyed factory boilerplate: management omnibox preference push_messaging. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } 149 }
151 150
152 OmniboxAPI::~OmniboxAPI() { 151 OmniboxAPI::~OmniboxAPI() {
153 } 152 }
154 153
155 void OmniboxAPI::Shutdown() { 154 void OmniboxAPI::Shutdown() {
156 } 155 }
157 156
158 // static 157 // static
159 OmniboxAPI* OmniboxAPI::Get(Profile* profile) { 158 OmniboxAPI* OmniboxAPI::Get(Profile* profile) {
160 return OmniboxAPIFactory::GetForProfile(profile); 159 return ProfileKeyedAPIFactory<OmniboxAPI>::GetForProfile(profile);
161 } 160 }
162 161
163 void OmniboxAPI::Observe(int type, 162 void OmniboxAPI::Observe(int type,
164 const content::NotificationSource& source, 163 const content::NotificationSource& source,
165 const content::NotificationDetails& details) { 164 const content::NotificationDetails& details) {
166 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { 165 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) {
167 const Extension* extension = 166 const Extension* extension =
168 content::Details<const Extension>(details).ptr(); 167 content::Details<const Extension>(details).ptr();
169 const std::string& keyword = OmniboxInfo::GetKeyword(extension); 168 const std::string& keyword = OmniboxInfo::GetKeyword(extension);
170 if (!keyword.empty()) { 169 if (!keyword.empty()) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 } 207 }
209 208
210 gfx::Image OmniboxAPI::GetOmniboxIcon(const std::string& extension_id) { 209 gfx::Image OmniboxAPI::GetOmniboxIcon(const std::string& extension_id) {
211 return gfx::Image(omnibox_icon_manager_.GetIcon(extension_id)); 210 return gfx::Image(omnibox_icon_manager_.GetIcon(extension_id));
212 } 211 }
213 212
214 gfx::Image OmniboxAPI::GetOmniboxPopupIcon(const std::string& extension_id) { 213 gfx::Image OmniboxAPI::GetOmniboxPopupIcon(const std::string& extension_id) {
215 return gfx::Image(omnibox_popup_icon_manager_.GetIcon(extension_id)); 214 return gfx::Image(omnibox_popup_icon_manager_.GetIcon(extension_id));
216 } 215 }
217 216
217 base::LazyInstance<ProfileKeyedAPIFactory<OmniboxAPI> >
218 g_factory = LAZY_INSTANCE_INITIALIZER;
219
220 template <>
221 ProfileKeyedAPIFactory<OmniboxAPI>*
222 ProfileKeyedAPIFactory<OmniboxAPI>::GetInstance() {
223 return &g_factory.Get();
224 }
225
218 bool OmniboxSendSuggestionsFunction::RunImpl() { 226 bool OmniboxSendSuggestionsFunction::RunImpl() {
219 ExtensionOmniboxSuggestions suggestions; 227 ExtensionOmniboxSuggestions suggestions;
220 ListValue* suggestions_value; 228 ListValue* suggestions_value;
221 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &suggestions.request_id)); 229 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &suggestions.request_id));
222 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &suggestions_value)); 230 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &suggestions_value));
223 231
224 suggestions.suggestions.resize(suggestions_value->GetSize()); 232 suggestions.suggestions.resize(suggestions_value->GetSize());
225 for (size_t i = 0; i < suggestions_value->GetSize(); ++i) { 233 for (size_t i = 0; i < suggestions_value->GetSize(); ++i) {
226 ExtensionOmniboxSuggestion& suggestion = suggestions.suggestions[i]; 234 ExtensionOmniboxSuggestion& suggestion = suggestions.suggestions[i];
227 DictionaryValue* suggestion_value; 235 DictionaryValue* suggestion_value;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 for (size_t i = 0; i < description_styles.size(); ++i) { 417 for (size_t i = 0; i < description_styles.size(); ++i) {
410 if (description_styles[i].offset > placeholder) 418 if (description_styles[i].offset > placeholder)
411 description_styles[i].offset += replacement.length() - 2; 419 description_styles[i].offset += replacement.length() - 2;
412 } 420 }
413 } 421 }
414 422
415 match->contents.assign(description); 423 match->contents.assign(description);
416 } 424 }
417 425
418 } // namespace extensions 426 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698