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

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 6 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 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 should_notify = true; 429 should_notify = true;
430 } else { 430 } else {
431 ++i; 431 ++i;
432 } 432 }
433 } 433 }
434 if (should_notify) 434 if (should_notify)
435 NotifyObservers(); 435 NotifyObservers();
436 } 436 }
437 437
438 438
439 void TemplateURLService::RegisterExtensionKeyword(const Extension* extension) { 439 void TemplateURLService::RegisterExtensionKeyword(
440 const extensions::Extension* extension) {
440 // TODO(mpcomplete): disable the keyword when the extension is disabled. 441 // TODO(mpcomplete): disable the keyword when the extension is disabled.
441 if (extension->omnibox_keyword().empty()) 442 if (extension->omnibox_keyword().empty())
442 return; 443 return;
443 444
444 Load(); 445 Load();
445 if (!loaded_) { 446 if (!loaded_) {
446 pending_extension_ids_.push_back(extension->id()); 447 pending_extension_ids_.push_back(extension->id());
447 return; 448 return;
448 } 449 }
449 450
450 if (!GetTemplateURLForExtension(extension)) { 451 if (!GetTemplateURLForExtension(extension)) {
451 TemplateURLData data; 452 TemplateURLData data;
452 data.short_name = UTF8ToUTF16(extension->name()); 453 data.short_name = UTF8ToUTF16(extension->name());
453 data.SetKeyword(UTF8ToUTF16(extension->omnibox_keyword())); 454 data.SetKeyword(UTF8ToUTF16(extension->omnibox_keyword()));
454 // This URL is not actually used for navigation. It holds the extension's 455 // This URL is not actually used for navigation. It holds the extension's
455 // ID, as well as forcing the TemplateURL to be treated as a search keyword. 456 // ID, as well as forcing the TemplateURL to be treated as a search keyword.
456 data.SetURL(std::string(chrome::kExtensionScheme) + "://" + 457 data.SetURL(std::string(chrome::kExtensionScheme) + "://" +
457 extension->id() + "/?q={searchTerms}"); 458 extension->id() + "/?q={searchTerms}");
458 Add(new TemplateURL(profile_, data)); 459 Add(new TemplateURL(profile_, data));
459 } 460 }
460 } 461 }
461 462
462 void TemplateURLService::UnregisterExtensionKeyword( 463 void TemplateURLService::UnregisterExtensionKeyword(
463 const Extension* extension) { 464 const extensions::Extension* extension) {
464 if (loaded_) { 465 if (loaded_) {
465 TemplateURL* url = GetTemplateURLForExtension(extension); 466 TemplateURL* url = GetTemplateURLForExtension(extension);
466 if (url) 467 if (url)
467 Remove(url); 468 Remove(url);
468 } else { 469 } else {
469 PendingExtensionIDs::iterator i = std::find(pending_extension_ids_.begin(), 470 PendingExtensionIDs::iterator i = std::find(pending_extension_ids_.begin(),
470 pending_extension_ids_.end(), extension->id()); 471 pending_extension_ids_.end(), extension->id());
471 if (i != pending_extension_ids_.end()) 472 if (i != pending_extension_ids_.end())
472 pending_extension_ids_.erase(i); 473 pending_extension_ids_.erase(i);
473 } 474 }
474 } 475 }
475 476
476 TemplateURL* TemplateURLService::GetTemplateURLForExtension( 477 TemplateURL* TemplateURLService::GetTemplateURLForExtension(
477 const Extension* extension) { 478 const extensions::Extension* extension) {
478 for (TemplateURLVector::const_iterator i = template_urls_.begin(); 479 for (TemplateURLVector::const_iterator i = template_urls_.begin();
479 i != template_urls_.end(); ++i) { 480 i != template_urls_.end(); ++i) {
480 if ((*i)->IsExtensionKeyword() && 481 if ((*i)->IsExtensionKeyword() &&
481 ((*i)->url_ref().GetHost() == extension->id())) 482 ((*i)->url_ref().GetHost() == extension->id()))
482 return *i; 483 return *i;
483 } 484 }
484 485
485 return NULL; 486 return NULL;
486 } 487 }
487 488
(...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after
1390 } 1391 }
1391 1392
1392 void TemplateURLService::NotifyLoaded() { 1393 void TemplateURLService::NotifyLoaded() {
1393 content::NotificationService::current()->Notify( 1394 content::NotificationService::current()->Notify(
1394 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, 1395 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED,
1395 content::Source<TemplateURLService>(this), 1396 content::Source<TemplateURLService>(this),
1396 content::NotificationService::NoDetails()); 1397 content::NotificationService::NoDetails());
1397 1398
1398 for (PendingExtensionIDs::const_iterator i(pending_extension_ids_.begin()); 1399 for (PendingExtensionIDs::const_iterator i(pending_extension_ids_.begin());
1399 i != pending_extension_ids_.end(); ++i) { 1400 i != pending_extension_ids_.end(); ++i) {
1400 const Extension* extension = 1401 const extensions::Extension* extension =
1401 profile_->GetExtensionService()->GetExtensionById(*i, true); 1402 profile_->GetExtensionService()->GetExtensionById(*i, true);
1402 if (extension) 1403 if (extension)
1403 RegisterExtensionKeyword(extension); 1404 RegisterExtensionKeyword(extension);
1404 } 1405 }
1405 pending_extension_ids_.clear(); 1406 pending_extension_ids_.clear();
1406 } 1407 }
1407 1408
1408 void TemplateURLService::SaveDefaultSearchProviderToPrefs( 1409 void TemplateURLService::SaveDefaultSearchProviderToPrefs(
1409 const TemplateURL* t_url) { 1410 const TemplateURL* t_url) {
1410 PrefService* prefs = GetPrefs(); 1411 PrefService* prefs = GetPrefs();
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
2253 // TODO(mpcomplete): If we allow editing extension keywords, then those 2254 // TODO(mpcomplete): If we allow editing extension keywords, then those
2254 // should be persisted to disk and synced. 2255 // should be persisted to disk and synced.
2255 if (template_url->sync_guid().empty() && 2256 if (template_url->sync_guid().empty() &&
2256 !template_url->IsExtensionKeyword()) { 2257 !template_url->IsExtensionKeyword()) {
2257 template_url->data_.sync_guid = guid::GenerateGUID(); 2258 template_url->data_.sync_guid = guid::GenerateGUID();
2258 if (service_.get()) 2259 if (service_.get())
2259 service_->UpdateKeyword(template_url->data()); 2260 service_->UpdateKeyword(template_url->data());
2260 } 2261 }
2261 } 2262 }
2262 } 2263 }
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url_service.h ('k') | chrome/browser/sessions/tab_restore_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698