| OLD | NEW |
| 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/api/omnibox/omnibox_api.h" |
| 20 #include "chrome/browser/extensions/extension_service.h" | 21 #include "chrome/browser/extensions/extension_service.h" |
| 21 #include "chrome/browser/extensions/extension_system.h" | 22 #include "chrome/browser/extensions/extension_system.h" |
| 22 #include "chrome/browser/google/google_url_tracker.h" | 23 #include "chrome/browser/google/google_url_tracker.h" |
| 23 #include "chrome/browser/history/history.h" | 24 #include "chrome/browser/history/history.h" |
| 24 #include "chrome/browser/history/history_notifications.h" | 25 #include "chrome/browser/history/history_notifications.h" |
| 25 #include "chrome/browser/history/history_service_factory.h" | 26 #include "chrome/browser/history/history_service_factory.h" |
| 26 #include "chrome/browser/net/url_fixer_upper.h" | 27 #include "chrome/browser/net/url_fixer_upper.h" |
| 27 #include "chrome/browser/prefs/pref_service.h" | 28 #include "chrome/browser/prefs/pref_service.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/protector/base_setting_change.h" | 30 #include "chrome/browser/protector/base_setting_change.h" |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 } | 532 } |
| 532 } | 533 } |
| 533 if (should_notify) | 534 if (should_notify) |
| 534 NotifyObservers(); | 535 NotifyObservers(); |
| 535 } | 536 } |
| 536 | 537 |
| 537 | 538 |
| 538 void TemplateURLService::RegisterExtensionKeyword( | 539 void TemplateURLService::RegisterExtensionKeyword( |
| 539 const extensions::Extension* extension) { | 540 const extensions::Extension* extension) { |
| 540 // TODO(mpcomplete): disable the keyword when the extension is disabled. | 541 // TODO(mpcomplete): disable the keyword when the extension is disabled. |
| 541 if (extension->omnibox_keyword().empty()) | 542 if (extensions::OmniboxAPI::GetKeyword(extension).empty()) |
| 542 return; | 543 return; |
| 543 | 544 |
| 544 Load(); | 545 Load(); |
| 545 if (!loaded_) { | 546 if (!loaded_) { |
| 546 pending_extension_ids_.push_back(extension->id()); | 547 pending_extension_ids_.push_back(extension->id()); |
| 547 return; | 548 return; |
| 548 } | 549 } |
| 549 | 550 |
| 550 if (!GetTemplateURLForExtension(extension)) { | 551 if (!GetTemplateURLForExtension(extension)) { |
| 551 TemplateURLData data; | 552 TemplateURLData data; |
| 552 data.short_name = UTF8ToUTF16(extension->name()); | 553 data.short_name = UTF8ToUTF16(extension->name()); |
| 553 data.SetKeyword(UTF8ToUTF16(extension->omnibox_keyword())); | 554 data.SetKeyword(UTF8ToUTF16(extensions::OmniboxAPI::GetKeyword(extension))); |
| 554 // This URL is not actually used for navigation. It holds the extension's | 555 // 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. | 556 // ID, as well as forcing the TemplateURL to be treated as a search keyword. |
| 556 data.SetURL(std::string(extensions::kExtensionScheme) + "://" + | 557 data.SetURL(std::string(extensions::kExtensionScheme) + "://" + |
| 557 extension->id() + "/?q={searchTerms}"); | 558 extension->id() + "/?q={searchTerms}"); |
| 558 Add(new TemplateURL(profile_, data)); | 559 Add(new TemplateURL(profile_, data)); |
| 559 } | 560 } |
| 560 } | 561 } |
| 561 | 562 |
| 562 void TemplateURLService::UnregisterExtensionKeyword( | 563 void TemplateURLService::UnregisterExtensionKeyword( |
| 563 const extensions::Extension* extension) { | 564 const extensions::Extension* extension) { |
| (...skipping 1999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2563 // TODO(mpcomplete): If we allow editing extension keywords, then those | 2564 // TODO(mpcomplete): If we allow editing extension keywords, then those |
| 2564 // should be persisted to disk and synced. | 2565 // should be persisted to disk and synced. |
| 2565 if (template_url->sync_guid().empty() && | 2566 if (template_url->sync_guid().empty() && |
| 2566 !template_url->IsExtensionKeyword()) { | 2567 !template_url->IsExtensionKeyword()) { |
| 2567 template_url->data_.sync_guid = base::GenerateGUID(); | 2568 template_url->data_.sync_guid = base::GenerateGUID(); |
| 2568 if (service_.get()) | 2569 if (service_.get()) |
| 2569 service_->UpdateKeyword(template_url->data()); | 2570 service_->UpdateKeyword(template_url->data()); |
| 2570 } | 2571 } |
| 2571 } | 2572 } |
| 2572 } | 2573 } |
| OLD | NEW |