Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: chrome/browser/autocomplete/extension_app_provider.cc

Issue 271393003: Use ExtensionRegistryObserver instead of deprecated extension notification from autocomplete (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 handles use non-incognito profile itself.
Peter Kasting 2014/05/12 19:46:55 Is this comment trying to say "ExtensionRegistryOb
limasdf 2014/05/13 14:38:44 Yes, Exactly. I blame my English T.T Updated.
43 extension_registry_observer_.Add(
44 extensions::ExtensionRegistry::Get(profile_));
45
42 RefreshAppList(); 46 RefreshAppList();
43 } 47 }
44 48
45 // static. 49 // static.
46 void ExtensionAppProvider::LaunchAppFromOmnibox( 50 void ExtensionAppProvider::LaunchAppFromOmnibox(
47 const AutocompleteMatch& match, 51 const AutocompleteMatch& match,
48 Profile* profile, 52 Profile* profile,
49 WindowOpenDisposition disposition) { 53 WindowOpenDisposition disposition) {
50 const extensions::Extension* extension = 54 const extensions::Extension* extension =
51 extensions::ExtensionRegistry::Get(profile) 55 extensions::ExtensionRegistry::Get(profile)
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 base::UTF8ToUTF16(launch_url.spec()), 180 base::UTF8ToUTF16(launch_url.spec()),
177 // Only hosted apps have recognizable URLs that users might type in, 181 // Only hosted apps have recognizable URLs that users might type in,
178 // packaged apps and hosted apps use chrome-extension:// URLs that are 182 // packaged apps and hosted apps use chrome-extension:// URLs that are
179 // normally not shown to users. 183 // normally not shown to users.
180 app->is_hosted_app() 184 app->is_hosted_app()
181 }; 185 };
182 extension_apps_.push_back(extension_app); 186 extension_apps_.push_back(extension_app);
183 } 187 }
184 } 188 }
185 189
190 void ExtensionAppProvider::OnExtensionLoaded(
191 content::BrowserContext* browser_context,
192 const extensions::Extension* extension) {
193 RefreshAppList();
194 }
195
186 void ExtensionAppProvider::Observe(int type, 196 void ExtensionAppProvider::Observe(int type,
187 const content::NotificationSource& source, 197 const content::NotificationSource& source,
188 const content::NotificationDetails& details) { 198 const content::NotificationDetails& details) {
199 DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_UNINSTALLED);
Peter Kasting 2014/05/12 19:46:55 Nit: (expected, actual)
limasdf 2014/05/13 14:38:44 Done.
189 RefreshAppList(); 200 RefreshAppList();
190 } 201 }
191 202
192 int ExtensionAppProvider::CalculateRelevance(AutocompleteInput::Type type, 203 int ExtensionAppProvider::CalculateRelevance(AutocompleteInput::Type type,
193 int input_length, 204 int input_length,
194 int target_length, 205 int target_length,
195 const GURL& url) { 206 const GURL& url) {
196 // If you update the algorithm here, please remember to update the tables in 207 // If you update the algorithm here, please remember to update the tables in
197 // autocomplete.h also. 208 // autocomplete.h also.
198 const int kMaxRelevance = 1425; 209 const int kMaxRelevance = 1425;
(...skipping 19 matching lines...) Expand all
218 history::URLRow info; 229 history::URLRow info;
219 url_db->GetRowForURL(url, &info); 230 url_db->GetRowForURL(url, &info);
220 type_count_boost = 231 type_count_boost =
221 400 * (1.0 - (std::pow(static_cast<double>(2), -info.typed_count()))); 232 400 * (1.0 - (std::pow(static_cast<double>(2), -info.typed_count())));
222 } 233 }
223 int relevance = 575 + static_cast<int>(type_count_boost) + 234 int relevance = 575 + static_cast<int>(type_count_boost) +
224 static_cast<int>(fraction_boost); 235 static_cast<int>(fraction_boost);
225 DCHECK_LE(relevance, kMaxRelevance); 236 DCHECK_LE(relevance, kMaxRelevance);
226 return relevance; 237 return relevance;
227 } 238 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698