Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/app_list/search/app_search_provider.h" | 5 #include "chrome/browser/ui/app_list/search/app_search_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | |
| 10 #include "base/message_loop/message_loop.h" | |
| 9 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/time/clock.h" | 12 #include "base/time/clock.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/extension_ui_util.h" | 14 #include "chrome/browser/extensions/extension_ui_util.h" |
| 13 #include "chrome/browser/extensions/extension_util.h" | 15 #include "chrome/browser/extensions/extension_util.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/app_list/search/app_result.h" | 17 #include "chrome/browser/ui/app_list/search/app_result.h" |
| 16 #include "extensions/browser/extension_prefs.h" | 18 #include "extensions/browser/extension_prefs.h" |
| 17 #include "extensions/browser/extension_registry.h" | 19 #include "extensions/browser/extension_registry.h" |
| 18 #include "extensions/browser/extension_system.h" | 20 #include "extensions/browser/extension_system.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 45 | 47 |
| 46 DISALLOW_COPY_AND_ASSIGN(App); | 48 DISALLOW_COPY_AND_ASSIGN(App); |
| 47 }; | 49 }; |
| 48 | 50 |
| 49 AppSearchProvider::AppSearchProvider(Profile* profile, | 51 AppSearchProvider::AppSearchProvider(Profile* profile, |
| 50 AppListControllerDelegate* list_controller, | 52 AppListControllerDelegate* list_controller, |
| 51 scoped_ptr<base::Clock> clock) | 53 scoped_ptr<base::Clock> clock) |
| 52 : profile_(profile), | 54 : profile_(profile), |
| 53 list_controller_(list_controller), | 55 list_controller_(list_controller), |
| 54 extension_registry_observer_(this), | 56 extension_registry_observer_(this), |
| 55 clock_(clock.Pass()) { | 57 clock_(clock.Pass()), |
| 58 update_results_factory_(this) { | |
| 56 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); | 59 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); |
| 57 RefreshApps(); | 60 RefreshApps(); |
| 58 } | 61 } |
| 59 | 62 |
| 60 AppSearchProvider::~AppSearchProvider() {} | 63 AppSearchProvider::~AppSearchProvider() {} |
| 61 | 64 |
| 62 void AppSearchProvider::Start(bool /*is_voice_query*/, | 65 void AppSearchProvider::Start(bool /*is_voice_query*/, |
| 63 const base::string16& query) { | 66 const base::string16& query) { |
| 64 query_ = query; | 67 query_ = query; |
| 65 const TokenizedString query_terms(query); | 68 const TokenizedString query_terms(query); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 94 (*app_it)->last_launch_time()); | 97 (*app_it)->last_launch_time()); |
| 95 } else { | 98 } else { |
| 96 TokenizedStringMatch match; | 99 TokenizedStringMatch match; |
| 97 if (!match.Calculate(query_terms, (*app_it)->indexed_name())) | 100 if (!match.Calculate(query_terms, (*app_it)->indexed_name())) |
| 98 continue; | 101 continue; |
| 99 | 102 |
| 100 result->UpdateFromMatch((*app_it)->indexed_name(), match); | 103 result->UpdateFromMatch((*app_it)->indexed_name(), match); |
| 101 } | 104 } |
| 102 Add(result.Pass()); | 105 Add(result.Pass()); |
| 103 } | 106 } |
| 107 | |
| 108 update_results_factory_.InvalidateWeakPtrs(); | |
|
tapted
2015/01/07 04:12:30
TBH I haven't used WeakPtrs in Chrome all that muc
xiyuan
2015/01/07 04:51:57
WeakPtrFactory::InvalidateWeakPtrs would mark the
| |
| 104 } | 109 } |
| 105 | 110 |
| 106 void AppSearchProvider::AddApps(const extensions::ExtensionSet& extensions) { | 111 void AppSearchProvider::AddApps(const extensions::ExtensionSet& extensions) { |
| 107 extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_); | 112 extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_); |
| 108 for (extensions::ExtensionSet::const_iterator iter = extensions.begin(); | 113 for (extensions::ExtensionSet::const_iterator iter = extensions.begin(); |
| 109 iter != extensions.end(); ++iter) { | 114 iter != extensions.end(); ++iter) { |
| 110 const extensions::Extension* app = iter->get(); | 115 const extensions::Extension* app = iter->get(); |
| 111 | 116 |
| 112 if (!extensions::ui_util::ShouldDisplayInAppLauncher(app, profile_)) | 117 if (!extensions::ui_util::ShouldDisplayInAppLauncher(app, profile_)) |
| 113 continue; | 118 continue; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 125 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); | 130 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); |
| 126 AddApps(registry->enabled_extensions()); | 131 AddApps(registry->enabled_extensions()); |
| 127 AddApps(registry->disabled_extensions()); | 132 AddApps(registry->disabled_extensions()); |
| 128 AddApps(registry->terminated_extensions()); | 133 AddApps(registry->terminated_extensions()); |
| 129 } | 134 } |
| 130 | 135 |
| 131 void AppSearchProvider::OnExtensionLoaded( | 136 void AppSearchProvider::OnExtensionLoaded( |
| 132 content::BrowserContext* browser_context, | 137 content::BrowserContext* browser_context, |
| 133 const extensions::Extension* extension) { | 138 const extensions::Extension* extension) { |
| 134 RefreshApps(); | 139 RefreshApps(); |
| 135 UpdateResults(); | 140 if (!update_results_factory_.HasWeakPtrs()) { |
| 141 base::MessageLoop::current()->PostTask( | |
| 142 FROM_HERE, | |
| 143 base::Bind(&AppSearchProvider::UpdateResults, | |
| 144 update_results_factory_.GetWeakPtr())); | |
| 145 } | |
| 136 } | 146 } |
| 137 | 147 |
| 138 void AppSearchProvider::OnExtensionUninstalled( | 148 void AppSearchProvider::OnExtensionUninstalled( |
| 139 content::BrowserContext* browser_context, | 149 content::BrowserContext* browser_context, |
| 140 const extensions::Extension* extension, | 150 const extensions::Extension* extension, |
| 141 extensions::UninstallReason reason) { | 151 extensions::UninstallReason reason) { |
| 142 RefreshApps(); | 152 RefreshApps(); |
| 143 UpdateResults(); | 153 if (!update_results_factory_.HasWeakPtrs()) { |
| 154 base::MessageLoop::current()->PostTask( | |
| 155 FROM_HERE, | |
| 156 base::Bind(&AppSearchProvider::UpdateResults, | |
| 157 update_results_factory_.GetWeakPtr())); | |
| 158 } | |
| 144 } | 159 } |
| 145 | 160 |
| 146 } // namespace app_list | 161 } // namespace app_list |
| OLD | NEW |