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

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

Issue 11446034: SupportsUserData and manifest handlers for Extension; use them for the Omnibox API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase + manifestdata Created 8 years 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/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/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
11 #include "base/guid.h" 11 #include "base/guid.h"
12 #include "base/i18n/case_conversion.h" 12 #include "base/i18n/case_conversion.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/string_number_conversions.h" 15 #include "base/string_number_conversions.h"
16 #include "base/string_split.h" 16 #include "base/string_split.h"
17 #include "base/string_util.h" 17 #include "base/string_util.h"
18 #include "base/time.h" 18 #include "base/time.h"
19 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
20 #include "chrome/browser/extensions/extension_service.h"
21 #include "chrome/browser/extensions/extension_system.h"
22 #include "chrome/browser/google/google_url_tracker.h" 20 #include "chrome/browser/google/google_url_tracker.h"
23 #include "chrome/browser/history/history.h" 21 #include "chrome/browser/history/history.h"
24 #include "chrome/browser/history/history_notifications.h" 22 #include "chrome/browser/history/history_notifications.h"
25 #include "chrome/browser/history/history_service_factory.h" 23 #include "chrome/browser/history/history_service_factory.h"
26 #include "chrome/browser/net/url_fixer_upper.h" 24 #include "chrome/browser/net/url_fixer_upper.h"
27 #include "chrome/browser/prefs/pref_service.h" 25 #include "chrome/browser/prefs/pref_service.h"
28 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/protector/base_setting_change.h" 27 #include "chrome/browser/protector/base_setting_change.h"
30 #include "chrome/browser/protector/protector_service.h" 28 #include "chrome/browser/protector/protector_service.h"
31 #include "chrome/browser/protector/protector_service_factory.h" 29 #include "chrome/browser/protector/protector_service_factory.h"
32 #include "chrome/browser/protector/protector_utils.h" 30 #include "chrome/browser/protector/protector_utils.h"
33 #include "chrome/browser/rlz/rlz.h" 31 #include "chrome/browser/rlz/rlz.h"
34 #include "chrome/browser/search_engines/search_host_to_urls_map.h" 32 #include "chrome/browser/search_engines/search_host_to_urls_map.h"
35 #include "chrome/browser/search_engines/search_terms_data.h" 33 #include "chrome/browser/search_engines/search_terms_data.h"
36 #include "chrome/browser/search_engines/template_url.h" 34 #include "chrome/browser/search_engines/template_url.h"
37 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" 35 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
38 #include "chrome/browser/search_engines/template_url_service_observer.h" 36 #include "chrome/browser/search_engines/template_url_service_observer.h"
39 #include "chrome/browser/search_engines/util.h" 37 #include "chrome/browser/search_engines/util.h"
40 #include "chrome/browser/webdata/web_data_service_factory.h" 38 #include "chrome/browser/webdata/web_data_service_factory.h"
41 #include "chrome/common/chrome_notification_types.h" 39 #include "chrome/common/chrome_notification_types.h"
42 #include "chrome/common/chrome_switches.h" 40 #include "chrome/common/chrome_switches.h"
43 #include "chrome/common/env_vars.h" 41 #include "chrome/common/env_vars.h"
44 #include "chrome/common/extensions/extension.h"
45 #include "chrome/common/pref_names.h" 42 #include "chrome/common/pref_names.h"
46 #include "chrome/common/url_constants.h" 43 #include "chrome/common/url_constants.h"
47 #include "content/public/browser/notification_service.h" 44 #include "content/public/browser/notification_service.h"
48 #include "extensions/common/constants.h" 45 #include "extensions/common/constants.h"
49 #include "net/base/net_util.h" 46 #include "net/base/net_util.h"
50 #include "sync/api/sync_change.h" 47 #include "sync/api/sync_change.h"
51 #include "sync/api/sync_error_factory.h" 48 #include "sync/api/sync_error_factory.h"
52 #include "sync/protocol/search_engine_specifics.pb.h" 49 #include "sync/protocol/search_engine_specifics.pb.h"
53 #include "sync/protocol/sync.pb.h" 50 #include "sync/protocol/sync.pb.h"
54 #include "ui/base/l10n/l10n_util.h" 51 #include "ui/base/l10n/l10n_util.h"
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 } else { 526 } else {
530 ++i; 527 ++i;
531 } 528 }
532 } 529 }
533 if (should_notify) 530 if (should_notify)
534 NotifyObservers(); 531 NotifyObservers();
535 } 532 }
536 533
537 534
538 void TemplateURLService::RegisterExtensionKeyword( 535 void TemplateURLService::RegisterExtensionKeyword(
539 const extensions::Extension* extension) { 536 const std::string& extension_id,
540 // TODO(mpcomplete): disable the keyword when the extension is disabled. 537 const std::string& extension_name,
541 if (extension->omnibox_keyword().empty()) 538 const std::string& keyword) {
542 return; 539 DCHECK(loaded_);
543 540
544 Load(); 541 if (!GetTemplateURLForExtension(extension_id)) {
545 if (!loaded_) {
546 pending_extension_ids_.push_back(extension->id());
547 return;
548 }
549
550 if (!GetTemplateURLForExtension(extension)) {
551 TemplateURLData data; 542 TemplateURLData data;
552 data.short_name = UTF8ToUTF16(extension->name()); 543 data.short_name = UTF8ToUTF16(extension_name);
553 data.SetKeyword(UTF8ToUTF16(extension->omnibox_keyword())); 544 data.SetKeyword(UTF8ToUTF16(keyword));
554 // This URL is not actually used for navigation. It holds the extension's 545 // This URL is not actually used for navigation. It holds the extension's
555 // ID, as well as forcing the TemplateURL to be treated as a search keyword. 546 // ID, as well as forcing the TemplateURL to be treated as a search keyword.
556 data.SetURL(std::string(extensions::kExtensionScheme) + "://" + 547 data.SetURL(std::string(extensions::kExtensionScheme) + "://" +
557 extension->id() + "/?q={searchTerms}"); 548 extension_id + "/?q={searchTerms}");
558 Add(new TemplateURL(profile_, data)); 549 Add(new TemplateURL(profile_, data));
559 } 550 }
560 } 551 }
561 552
562 void TemplateURLService::UnregisterExtensionKeyword( 553 void TemplateURLService::UnregisterExtensionKeyword(
563 const extensions::Extension* extension) { 554 const std::string& extension_id) {
564 if (loaded_) { 555 DCHECK(loaded_);
565 TemplateURL* url = GetTemplateURLForExtension(extension); 556 TemplateURL* url = GetTemplateURLForExtension(extension_id);
566 if (url) 557 if (url)
567 Remove(url); 558 Remove(url);
568 } else {
569 PendingExtensionIDs::iterator i = std::find(pending_extension_ids_.begin(),
570 pending_extension_ids_.end(), extension->id());
571 if (i != pending_extension_ids_.end())
572 pending_extension_ids_.erase(i);
573 }
574 } 559 }
575 560
576 TemplateURL* TemplateURLService::GetTemplateURLForExtension( 561 TemplateURL* TemplateURLService::GetTemplateURLForExtension(
577 const extensions::Extension* extension) { 562 const std::string& extension_id) {
578 for (TemplateURLVector::const_iterator i = template_urls_.begin(); 563 for (TemplateURLVector::const_iterator i = template_urls_.begin();
579 i != template_urls_.end(); ++i) { 564 i != template_urls_.end(); ++i) {
580 if ((*i)->IsExtensionKeyword() && 565 if ((*i)->IsExtensionKeyword() &&
581 ((*i)->url_ref().GetHost() == extension->id())) 566 ((*i)->url_ref().GetHost() == extension_id))
582 return *i; 567 return *i;
583 } 568 }
584 569
585 return NULL; 570 return NULL;
586 } 571 }
587 572
588 TemplateURLService::TemplateURLVector TemplateURLService::GetTemplateURLs() { 573 TemplateURLService::TemplateURLVector TemplateURLService::GetTemplateURLs() {
589 return template_urls_; 574 return template_urls_;
590 } 575 }
591 576
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after
1612 UIThreadSearchTermsData search_terms_data(profile_); 1597 UIThreadSearchTermsData search_terms_data(profile_);
1613 provider_map_->Init(template_urls_, search_terms_data); 1598 provider_map_->Init(template_urls_, search_terms_data);
1614 loaded_ = true; 1599 loaded_ = true;
1615 } 1600 }
1616 1601
1617 void TemplateURLService::NotifyLoaded() { 1602 void TemplateURLService::NotifyLoaded() {
1618 content::NotificationService::current()->Notify( 1603 content::NotificationService::current()->Notify(
1619 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, 1604 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED,
1620 content::Source<TemplateURLService>(this), 1605 content::Source<TemplateURLService>(this),
1621 content::NotificationService::NoDetails()); 1606 content::NotificationService::NoDetails());
1622
1623 for (PendingExtensionIDs::const_iterator i(pending_extension_ids_.begin());
1624 i != pending_extension_ids_.end(); ++i) {
1625 const extensions::Extension* extension =
1626 extensions::ExtensionSystem::Get(profile_)->extension_service()->
1627 GetExtensionById(*i, true);
1628 if (extension)
1629 RegisterExtensionKeyword(extension);
1630 }
1631 pending_extension_ids_.clear();
1632 } 1607 }
1633 1608
1634 void TemplateURLService::SaveDefaultSearchProviderToPrefs( 1609 void TemplateURLService::SaveDefaultSearchProviderToPrefs(
1635 const TemplateURL* t_url) { 1610 const TemplateURL* t_url) {
1636 PrefService* prefs = GetPrefs(); 1611 PrefService* prefs = GetPrefs();
1637 if (!prefs) 1612 if (!prefs)
1638 return; 1613 return;
1639 1614
1640 bool enabled = false; 1615 bool enabled = false;
1641 std::string search_url; 1616 std::string search_url;
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after
2563 // TODO(mpcomplete): If we allow editing extension keywords, then those 2538 // TODO(mpcomplete): If we allow editing extension keywords, then those
2564 // should be persisted to disk and synced. 2539 // should be persisted to disk and synced.
2565 if (template_url->sync_guid().empty() && 2540 if (template_url->sync_guid().empty() &&
2566 !template_url->IsExtensionKeyword()) { 2541 !template_url->IsExtensionKeyword()) {
2567 template_url->data_.sync_guid = base::GenerateGUID(); 2542 template_url->data_.sync_guid = base::GenerateGUID();
2568 if (service_.get()) 2543 if (service_.get())
2569 service_->UpdateKeyword(template_url->data()); 2544 service_->UpdateKeyword(template_url->data());
2570 } 2545 }
2571 } 2546 }
2572 } 2547 }
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url_service.h ('k') | chrome/browser/ui/app_list/search_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698