| 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/string16.h" | 10 #include "base/string16.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/extension_system_factory.h" | 13 #include "chrome/browser/extensions/extension_system_factory.h" |
| 14 #include "chrome/browser/history/history_service.h" | 14 #include "chrome/browser/history/history_service.h" |
| 15 #include "chrome/browser/history/history_service_factory.h" | 15 #include "chrome/browser/history/history_service_factory.h" |
| 16 #include "chrome/browser/history/url_database.h" | 16 #include "chrome/browser/history/url_database.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/extensions/application_launch.h" | 18 #include "chrome/browser/ui/extensions/application_launch.h" |
| 19 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 19 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
| 20 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "chrome/common/extensions/app_launcher_info.h" |
| 21 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
| 22 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 24 | 25 |
| 25 ExtensionAppProvider::ExtensionAppProvider( | 26 ExtensionAppProvider::ExtensionAppProvider( |
| 26 AutocompleteProviderListener* listener, | 27 AutocompleteProviderListener* listener, |
| 27 Profile* profile) | 28 Profile* profile) |
| 28 : AutocompleteProvider(listener, profile, | 29 : AutocompleteProvider(listener, profile, |
| 29 AutocompleteProvider::TYPE_EXTENSION_APP) { | 30 AutocompleteProvider::TYPE_EXTENSION_APP) { |
| 30 // Notifications of extensions loading and unloading always come from the | 31 // Notifications of extensions loading and unloading always come from the |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 const extensions::Extension* app = *iter; | 157 const extensions::Extension* app = *iter; |
| 157 if (!app->ShouldDisplayInAppLauncher()) | 158 if (!app->ShouldDisplayInAppLauncher()) |
| 158 continue; | 159 continue; |
| 159 // Note: Apps that appear in the NTP only are not added here since this | 160 // Note: Apps that appear in the NTP only are not added here since this |
| 160 // provider is currently only used in the app launcher. | 161 // provider is currently only used in the app launcher. |
| 161 | 162 |
| 162 if (profile_->IsOffTheRecord() && | 163 if (profile_->IsOffTheRecord() && |
| 163 !extension_service->CanLoadInIncognito(app)) | 164 !extension_service->CanLoadInIncognito(app)) |
| 164 continue; | 165 continue; |
| 165 | 166 |
| 166 GURL launch_url = | 167 GURL launch_url = app->is_platform_app() ? |
| 167 app->is_platform_app() ? app->url() : app->GetFullLaunchURL(); | 168 app->url() : extensions::AppLauncherInfo::GetFullLaunchURL(app); |
| 168 DCHECK(launch_url.is_valid()); | 169 DCHECK(launch_url.is_valid()); |
| 169 | 170 |
| 170 ExtensionApp extension_app = { | 171 ExtensionApp extension_app = { |
| 171 UTF8ToUTF16(app->name()), | 172 UTF8ToUTF16(app->name()), |
| 172 UTF8ToUTF16(launch_url.spec()), | 173 UTF8ToUTF16(launch_url.spec()), |
| 173 // Only hosted apps have recognizable URLs that users might type in, | 174 // Only hosted apps have recognizable URLs that users might type in, |
| 174 // packaged apps and hosted apps use chrome-extension:// URLs that are | 175 // packaged apps and hosted apps use chrome-extension:// URLs that are |
| 175 // normally not shown to users. | 176 // normally not shown to users. |
| 176 app->is_hosted_app() | 177 app->is_hosted_app() |
| 177 }; | 178 }; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 history::URLRow info; | 215 history::URLRow info; |
| 215 url_db->GetRowForURL(url, &info); | 216 url_db->GetRowForURL(url, &info); |
| 216 type_count_boost = | 217 type_count_boost = |
| 217 400 * (1.0 - (std::pow(static_cast<double>(2), -info.typed_count()))); | 218 400 * (1.0 - (std::pow(static_cast<double>(2), -info.typed_count()))); |
| 218 } | 219 } |
| 219 int relevance = 575 + static_cast<int>(type_count_boost) + | 220 int relevance = 575 + static_cast<int>(type_count_boost) + |
| 220 static_cast<int>(fraction_boost); | 221 static_cast<int>(fraction_boost); |
| 221 DCHECK_LE(relevance, kMaxRelevance); | 222 DCHECK_LE(relevance, kMaxRelevance); |
| 222 return relevance; | 223 return relevance; |
| 223 } | 224 } |
| OLD | NEW |