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

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

Issue 2344653002: [Extensions] Convert some ChromeSyncExtensionFunctions (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « chrome/browser/extensions/api/omnibox/omnibox_api.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 pending_extensions_.clear(); 277 pending_extensions_.clear();
278 } 278 }
279 279
280 template <> 280 template <>
281 void BrowserContextKeyedAPIFactory<OmniboxAPI>::DeclareFactoryDependencies() { 281 void BrowserContextKeyedAPIFactory<OmniboxAPI>::DeclareFactoryDependencies() {
282 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); 282 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
283 DependsOn(ExtensionPrefsFactory::GetInstance()); 283 DependsOn(ExtensionPrefsFactory::GetInstance());
284 DependsOn(TemplateURLServiceFactory::GetInstance()); 284 DependsOn(TemplateURLServiceFactory::GetInstance());
285 } 285 }
286 286
287 bool OmniboxSendSuggestionsFunction::RunSync() { 287 ExtensionFunction::ResponseAction OmniboxSendSuggestionsFunction::Run() {
288 std::unique_ptr<SendSuggestions::Params> params( 288 std::unique_ptr<SendSuggestions::Params> params(
289 SendSuggestions::Params::Create(*args_)); 289 SendSuggestions::Params::Create(*args_));
290 EXTENSION_FUNCTION_VALIDATE(params); 290 EXTENSION_FUNCTION_VALIDATE(params);
291 291
292 content::NotificationService::current()->Notify( 292 content::NotificationService::current()->Notify(
293 extensions::NOTIFICATION_EXTENSION_OMNIBOX_SUGGESTIONS_READY, 293 extensions::NOTIFICATION_EXTENSION_OMNIBOX_SUGGESTIONS_READY,
294 content::Source<Profile>(GetProfile()->GetOriginalProfile()), 294 content::Source<Profile>(
295 Profile::FromBrowserContext(browser_context())->GetOriginalProfile()),
295 content::Details<SendSuggestions::Params>(params.get())); 296 content::Details<SendSuggestions::Params>(params.get()));
296 297
297 return true; 298 return RespondNow(NoArguments());
298 } 299 }
299 300
300 bool OmniboxSetDefaultSuggestionFunction::RunSync() { 301 ExtensionFunction::ResponseAction OmniboxSetDefaultSuggestionFunction::Run() {
301 std::unique_ptr<SetDefaultSuggestion::Params> params( 302 std::unique_ptr<SetDefaultSuggestion::Params> params(
302 SetDefaultSuggestion::Params::Create(*args_)); 303 SetDefaultSuggestion::Params::Create(*args_));
303 EXTENSION_FUNCTION_VALIDATE(params); 304 EXTENSION_FUNCTION_VALIDATE(params);
304 305
305 if (SetOmniboxDefaultSuggestion( 306 Profile* profile = Profile::FromBrowserContext(browser_context());
306 GetProfile(), extension_id(), params->suggestion)) { 307 if (SetOmniboxDefaultSuggestion(profile, extension_id(),
308 params->suggestion)) {
307 content::NotificationService::current()->Notify( 309 content::NotificationService::current()->Notify(
308 extensions::NOTIFICATION_EXTENSION_OMNIBOX_DEFAULT_SUGGESTION_CHANGED, 310 extensions::NOTIFICATION_EXTENSION_OMNIBOX_DEFAULT_SUGGESTION_CHANGED,
309 content::Source<Profile>(GetProfile()->GetOriginalProfile()), 311 content::Source<Profile>(profile->GetOriginalProfile()),
310 content::NotificationService::NoDetails()); 312 content::NotificationService::NoDetails());
311 } 313 }
312 314
313 return true; 315 return RespondNow(NoArguments());
314 } 316 }
315 317
316 // This function converts style information populated by the JSON schema 318 // This function converts style information populated by the JSON schema
317 // compiler into an ACMatchClassifications object. 319 // compiler into an ACMatchClassifications object.
318 ACMatchClassifications StyleTypesToACMatchClassifications( 320 ACMatchClassifications StyleTypesToACMatchClassifications(
319 const omnibox::SuggestResult &suggestion) { 321 const omnibox::SuggestResult &suggestion) {
320 ACMatchClassifications match_classifications; 322 ACMatchClassifications match_classifications;
321 if (suggestion.description_styles) { 323 if (suggestion.description_styles) {
322 base::string16 description = base::UTF8ToUTF16(suggestion.description); 324 base::string16 description = base::UTF8ToUTF16(suggestion.description);
323 std::vector<int> styles(description.length(), 0); 325 std::vector<int> styles(description.length(), 0);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 for (size_t i = 0; i < description_styles.size(); ++i) { 395 for (size_t i = 0; i < description_styles.size(); ++i) {
394 if (description_styles[i].offset > placeholder) 396 if (description_styles[i].offset > placeholder)
395 description_styles[i].offset += replacement.length() - 2; 397 description_styles[i].offset += replacement.length() - 2;
396 } 398 }
397 } 399 }
398 400
399 match->contents.assign(description); 401 match->contents.assign(description);
400 } 402 }
401 403
402 } // namespace extensions 404 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/omnibox/omnibox_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698