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

Side by Side Diff: chrome/browser/search_engines/template_url_service.cc

Issue 10375021: Move Extension into extensions namespace (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Take 2 Created 8 years, 7 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
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/search_engines/template_url_service.h" 5 #include "chrome/browser/search_engines/template_url_service.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/environment.h" 9 #include "base/environment.h"
10 #include "base/i18n/case_conversion.h" 10 #include "base/i18n/case_conversion.h"
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 should_notify = true; 409 should_notify = true;
410 } else { 410 } else {
411 ++i; 411 ++i;
412 } 412 }
413 } 413 }
414 if (should_notify) 414 if (should_notify)
415 NotifyObservers(); 415 NotifyObservers();
416 } 416 }
417 417
418 418
419 void TemplateURLService::RegisterExtensionKeyword(const Extension* extension) { 419 void TemplateURLService::RegisterExtensionKeyword(
420 const extensions::Extension* extension) {
420 // TODO(mpcomplete): disable the keyword when the extension is disabled. 421 // TODO(mpcomplete): disable the keyword when the extension is disabled.
421 if (extension->omnibox_keyword().empty()) 422 if (extension->omnibox_keyword().empty())
422 return; 423 return;
423 424
424 Load(); 425 Load();
425 if (!loaded_) { 426 if (!loaded_) {
426 pending_extension_ids_.push_back(extension->id()); 427 pending_extension_ids_.push_back(extension->id());
427 return; 428 return;
428 } 429 }
429 430
430 if (!GetTemplateURLForExtension(extension)) { 431 if (!GetTemplateURLForExtension(extension)) {
431 TemplateURLData data; 432 TemplateURLData data;
432 data.short_name = UTF8ToUTF16(extension->name()); 433 data.short_name = UTF8ToUTF16(extension->name());
433 data.SetKeyword(UTF8ToUTF16(extension->omnibox_keyword())); 434 data.SetKeyword(UTF8ToUTF16(extension->omnibox_keyword()));
434 // This URL is not actually used for navigation. It holds the extension's 435 // This URL is not actually used for navigation. It holds the extension's
435 // ID, as well as forcing the TemplateURL to be treated as a search keyword. 436 // ID, as well as forcing the TemplateURL to be treated as a search keyword.
436 data.SetURL(std::string(chrome::kExtensionScheme) + "://" + 437 data.SetURL(std::string(chrome::kExtensionScheme) + "://" +
437 extension->id() + "/?q={searchTerms}"); 438 extension->id() + "/?q={searchTerms}");
438 Add(new TemplateURL(profile_, data)); 439 Add(new TemplateURL(profile_, data));
439 } 440 }
440 } 441 }
441 442
442 void TemplateURLService::UnregisterExtensionKeyword( 443 void TemplateURLService::UnregisterExtensionKeyword(
443 const Extension* extension) { 444 const extensions::Extension* extension) {
444 if (loaded_) { 445 if (loaded_) {
445 TemplateURL* url = GetTemplateURLForExtension(extension); 446 TemplateURL* url = GetTemplateURLForExtension(extension);
446 if (url) 447 if (url)
447 Remove(url); 448 Remove(url);
448 } else { 449 } else {
449 PendingExtensionIDs::iterator i = std::find(pending_extension_ids_.begin(), 450 PendingExtensionIDs::iterator i = std::find(pending_extension_ids_.begin(),
450 pending_extension_ids_.end(), extension->id()); 451 pending_extension_ids_.end(), extension->id());
451 if (i != pending_extension_ids_.end()) 452 if (i != pending_extension_ids_.end())
452 pending_extension_ids_.erase(i); 453 pending_extension_ids_.erase(i);
453 } 454 }
454 } 455 }
455 456
456 TemplateURL* TemplateURLService::GetTemplateURLForExtension( 457 TemplateURL* TemplateURLService::GetTemplateURLForExtension(
457 const Extension* extension) { 458 const extensions::Extension* extension) {
458 for (TemplateURLVector::const_iterator i = template_urls_.begin(); 459 for (TemplateURLVector::const_iterator i = template_urls_.begin();
459 i != template_urls_.end(); ++i) { 460 i != template_urls_.end(); ++i) {
460 if ((*i)->IsExtensionKeyword() && 461 if ((*i)->IsExtensionKeyword() &&
461 ((*i)->url_ref().GetHost() == extension->id())) 462 ((*i)->url_ref().GetHost() == extension->id()))
462 return *i; 463 return *i;
463 } 464 }
464 465
465 return NULL; 466 return NULL;
466 } 467 }
467 468
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 } 1353 }
1353 1354
1354 void TemplateURLService::NotifyLoaded() { 1355 void TemplateURLService::NotifyLoaded() {
1355 content::NotificationService::current()->Notify( 1356 content::NotificationService::current()->Notify(
1356 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, 1357 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED,
1357 content::Source<TemplateURLService>(this), 1358 content::Source<TemplateURLService>(this),
1358 content::NotificationService::NoDetails()); 1359 content::NotificationService::NoDetails());
1359 1360
1360 for (PendingExtensionIDs::const_iterator i(pending_extension_ids_.begin()); 1361 for (PendingExtensionIDs::const_iterator i(pending_extension_ids_.begin());
1361 i != pending_extension_ids_.end(); ++i) { 1362 i != pending_extension_ids_.end(); ++i) {
1362 const Extension* extension = 1363 const extensions::Extension* extension =
1363 profile_->GetExtensionService()->GetExtensionById(*i, true); 1364 profile_->GetExtensionService()->GetExtensionById(*i, true);
1364 if (extension) 1365 if (extension)
1365 RegisterExtensionKeyword(extension); 1366 RegisterExtensionKeyword(extension);
1366 } 1367 }
1367 pending_extension_ids_.clear(); 1368 pending_extension_ids_.clear();
1368 } 1369 }
1369 1370
1370 void TemplateURLService::SaveDefaultSearchProviderToPrefs( 1371 void TemplateURLService::SaveDefaultSearchProviderToPrefs(
1371 const TemplateURL* t_url) { 1372 const TemplateURL* t_url) {
1372 PrefService* prefs = GetPrefs(); 1373 PrefService* prefs = GetPrefs();
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after
2203 // TODO(mpcomplete): If we allow editing extension keywords, then those 2204 // TODO(mpcomplete): If we allow editing extension keywords, then those
2204 // should be persisted to disk and synced. 2205 // should be persisted to disk and synced.
2205 if (template_url->sync_guid().empty() && 2206 if (template_url->sync_guid().empty() &&
2206 !template_url->IsExtensionKeyword()) { 2207 !template_url->IsExtensionKeyword()) {
2207 template_url->data_.sync_guid = guid::GenerateGUID(); 2208 template_url->data_.sync_guid = guid::GenerateGUID();
2208 if (service_.get()) 2209 if (service_.get())
2209 service_->UpdateKeyword(template_url->data()); 2210 service_->UpdateKeyword(template_url->data());
2210 } 2211 }
2211 } 2212 }
2212 } 2213 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698