| 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/autocomplete/extension_app_provider.h" | 5 #include "chrome/browser/autocomplete/extension_app_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/extensions/extension_util.h" | 14 #include "chrome/browser/extensions/extension_util.h" |
| 15 #include "chrome/browser/history/history_service.h" | 15 #include "chrome/browser/history/history_service.h" |
| 16 #include "chrome/browser/history/history_service_factory.h" | 16 #include "chrome/browser/history/history_service_factory.h" |
| 17 #include "chrome/browser/history/url_database.h" | 17 #include "chrome/browser/history/url_database.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/extensions/application_launch.h" | 19 #include "chrome/browser/ui/extensions/application_launch.h" |
| 20 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h" | 20 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h" |
| 21 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 21 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 22 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
| 23 #include "extensions/browser/extension_registry.h" |
| 23 #include "extensions/browser/extension_system.h" | 24 #include "extensions/browser/extension_system.h" |
| 24 #include "extensions/common/extension.h" | 25 #include "extensions/common/extension.h" |
| 25 #include "extensions/common/extension_set.h" | 26 #include "extensions/common/extension_set.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 27 | 28 |
| 28 ExtensionAppProvider::ExtensionAppProvider( | 29 ExtensionAppProvider::ExtensionAppProvider( |
| 29 AutocompleteProviderListener* listener, | 30 AutocompleteProviderListener* listener, |
| 30 Profile* profile) | 31 Profile* profile) |
| 31 : AutocompleteProvider(listener, profile, | 32 : AutocompleteProvider(listener, profile, |
| 32 AutocompleteProvider::TYPE_EXTENSION_APP) { | 33 AutocompleteProvider::TYPE_EXTENSION_APP) { |
| 33 // Notifications of extensions loading and unloading always come from the | 34 // Notifications of extensions loading and unloading always come from the |
| 34 // non-incognito profile, but we need to see them regardless, as the incognito | 35 // non-incognito profile, but we need to see them regardless, as the incognito |
| 35 // windows can be affected. | 36 // windows can be affected. |
| 36 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 37 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 37 content::Source<Profile>(profile_->GetOriginalProfile())); | 38 content::Source<Profile>(profile_->GetOriginalProfile())); |
| 38 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | 39 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
| 39 content::Source<Profile>(profile_->GetOriginalProfile())); | 40 content::Source<Profile>(profile_->GetOriginalProfile())); |
| 40 RefreshAppList(); | 41 RefreshAppList(); |
| 41 } | 42 } |
| 42 | 43 |
| 43 // static. | 44 // static. |
| 44 void ExtensionAppProvider::LaunchAppFromOmnibox( | 45 void ExtensionAppProvider::LaunchAppFromOmnibox( |
| 45 const AutocompleteMatch& match, | 46 const AutocompleteMatch& match, |
| 46 Profile* profile, | 47 Profile* profile, |
| 47 WindowOpenDisposition disposition) { | 48 WindowOpenDisposition disposition) { |
| 48 ExtensionService* service = | |
| 49 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
| 50 const extensions::Extension* extension = | 49 const extensions::Extension* extension = |
| 51 service->GetInstalledApp(match.destination_url); | 50 extensions::ExtensionRegistry::Get(profile) |
| 51 ->enabled_extensions().GetAppByURL(match.destination_url); |
| 52 // While the Omnibox popup is open, the extension can be updated, changing | 52 // While the Omnibox popup is open, the extension can be updated, changing |
| 53 // its URL and leaving us with no extension being found. In this case, we | 53 // its URL and leaving us with no extension being found. In this case, we |
| 54 // ignore the request. | 54 // ignore the request. |
| 55 if (!extension) | 55 if (!extension) |
| 56 return; | 56 return; |
| 57 | 57 |
| 58 CoreAppLauncherHandler::RecordAppLaunchType( | 58 CoreAppLauncherHandler::RecordAppLaunchType( |
| 59 extension_misc::APP_LAUNCH_OMNIBOX_APP, | 59 extension_misc::APP_LAUNCH_OMNIBOX_APP, |
| 60 extension->GetType()); | 60 extension->GetType()); |
| 61 | 61 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 history::URLRow info; | 217 history::URLRow info; |
| 218 url_db->GetRowForURL(url, &info); | 218 url_db->GetRowForURL(url, &info); |
| 219 type_count_boost = | 219 type_count_boost = |
| 220 400 * (1.0 - (std::pow(static_cast<double>(2), -info.typed_count()))); | 220 400 * (1.0 - (std::pow(static_cast<double>(2), -info.typed_count()))); |
| 221 } | 221 } |
| 222 int relevance = 575 + static_cast<int>(type_count_boost) + | 222 int relevance = 575 + static_cast<int>(type_count_boost) + |
| 223 static_cast<int>(fraction_boost); | 223 static_cast<int>(fraction_boost); |
| 224 DCHECK_LE(relevance, kMaxRelevance); | 224 DCHECK_LE(relevance, kMaxRelevance); |
| 225 return relevance; | 225 return relevance; |
| 226 } | 226 } |
| OLD | NEW |