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" |
(...skipping 11 matching lines...) Expand all Loading... |
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_registry.h" |
24 #include "extensions/browser/extension_system.h" | 24 #include "extensions/browser/extension_system.h" |
25 #include "extensions/common/extension.h" | 25 #include "extensions/common/extension.h" |
26 #include "extensions/common/extension_set.h" | 26 #include "extensions/common/extension_set.h" |
27 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
28 | 28 |
29 ExtensionAppProvider::ExtensionAppProvider( | 29 ExtensionAppProvider::ExtensionAppProvider( |
30 AutocompleteProviderListener* listener, | 30 AutocompleteProviderListener* listener, |
31 Profile* profile) | 31 Profile* profile) |
32 : AutocompleteProvider(listener, | 32 : AutocompleteProvider(listener, profile, |
33 profile, | 33 AutocompleteProvider::TYPE_EXTENSION_APP) { |
34 AutocompleteProvider::TYPE_EXTENSION_APP), | |
35 extension_registry_observer_(this) { | |
36 // Notifications of extensions loading and unloading always come from the | 34 // Notifications of extensions loading and unloading always come from the |
37 // 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 |
38 // windows can be affected. | 36 // windows can be affected. |
| 37 registrar_.Add(this, |
| 38 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| 39 content::Source<Profile>(profile_->GetOriginalProfile())); |
39 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | 40 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
40 content::Source<Profile>(profile_->GetOriginalProfile())); | 41 content::Source<Profile>(profile_->GetOriginalProfile())); |
41 | |
42 // ExtensionRegistryObserver will handle getting the original profile itself | |
43 // as necessary. | |
44 extension_registry_observer_.Add( | |
45 extensions::ExtensionRegistry::Get(profile_)); | |
46 | |
47 RefreshAppList(); | 42 RefreshAppList(); |
48 } | 43 } |
49 | 44 |
50 // static. | 45 // static. |
51 void ExtensionAppProvider::LaunchAppFromOmnibox( | 46 void ExtensionAppProvider::LaunchAppFromOmnibox( |
52 const AutocompleteMatch& match, | 47 const AutocompleteMatch& match, |
53 Profile* profile, | 48 Profile* profile, |
54 WindowOpenDisposition disposition) { | 49 WindowOpenDisposition disposition) { |
55 const extensions::Extension* extension = | 50 const extensions::Extension* extension = |
56 extensions::ExtensionRegistry::Get(profile) | 51 extensions::ExtensionRegistry::Get(profile) |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 base::UTF8ToUTF16(launch_url.spec()), | 176 base::UTF8ToUTF16(launch_url.spec()), |
182 // Only hosted apps have recognizable URLs that users might type in, | 177 // Only hosted apps have recognizable URLs that users might type in, |
183 // packaged apps and hosted apps use chrome-extension:// URLs that are | 178 // packaged apps and hosted apps use chrome-extension:// URLs that are |
184 // normally not shown to users. | 179 // normally not shown to users. |
185 app->is_hosted_app() | 180 app->is_hosted_app() |
186 }; | 181 }; |
187 extension_apps_.push_back(extension_app); | 182 extension_apps_.push_back(extension_app); |
188 } | 183 } |
189 } | 184 } |
190 | 185 |
191 void ExtensionAppProvider::OnExtensionLoaded( | |
192 content::BrowserContext* browser_context, | |
193 const extensions::Extension* extension) { | |
194 RefreshAppList(); | |
195 } | |
196 | |
197 void ExtensionAppProvider::Observe(int type, | 186 void ExtensionAppProvider::Observe(int type, |
198 const content::NotificationSource& source, | 187 const content::NotificationSource& source, |
199 const content::NotificationDetails& details)
{ | 188 const content::NotificationDetails& details)
{ |
200 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNINSTALLED, type); | |
201 RefreshAppList(); | 189 RefreshAppList(); |
202 } | 190 } |
203 | 191 |
204 int ExtensionAppProvider::CalculateRelevance(AutocompleteInput::Type type, | 192 int ExtensionAppProvider::CalculateRelevance(AutocompleteInput::Type type, |
205 int input_length, | 193 int input_length, |
206 int target_length, | 194 int target_length, |
207 const GURL& url) { | 195 const GURL& url) { |
208 // If you update the algorithm here, please remember to update the tables in | 196 // If you update the algorithm here, please remember to update the tables in |
209 // autocomplete.h also. | 197 // autocomplete.h also. |
210 const int kMaxRelevance = 1425; | 198 const int kMaxRelevance = 1425; |
(...skipping 19 matching lines...) Expand all Loading... |
230 history::URLRow info; | 218 history::URLRow info; |
231 url_db->GetRowForURL(url, &info); | 219 url_db->GetRowForURL(url, &info); |
232 type_count_boost = | 220 type_count_boost = |
233 400 * (1.0 - (std::pow(static_cast<double>(2), -info.typed_count()))); | 221 400 * (1.0 - (std::pow(static_cast<double>(2), -info.typed_count()))); |
234 } | 222 } |
235 int relevance = 575 + static_cast<int>(type_count_boost) + | 223 int relevance = 575 + static_cast<int>(type_count_boost) + |
236 static_cast<int>(fraction_boost); | 224 static_cast<int>(fraction_boost); |
237 DCHECK_LE(relevance, kMaxRelevance); | 225 DCHECK_LE(relevance, kMaxRelevance); |
238 return relevance; | 226 return relevance; |
239 } | 227 } |
OLD | NEW |