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