Chromium Code Reviews| Index: chrome/browser/ui/app_list/search/app_search_provider.cc |
| diff --git a/chrome/browser/ui/app_list/search/app_search_provider.cc b/chrome/browser/ui/app_list/search/app_search_provider.cc |
| index 431493332ea662ac2d5cb1ed0a90081d5a4317eb..a45e4d9c19a4b14ee0e7cad18674d9cfb1e6fdbf 100644 |
| --- a/chrome/browser/ui/app_list/search/app_search_provider.cc |
| +++ b/chrome/browser/ui/app_list/search/app_search_provider.cc |
| @@ -6,6 +6,8 @@ |
| #include <string> |
| +#include "base/bind.h" |
| +#include "base/message_loop/message_loop.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/time/clock.h" |
| #include "chrome/browser/extensions/extension_service.h" |
| @@ -52,7 +54,8 @@ AppSearchProvider::AppSearchProvider(Profile* profile, |
| : profile_(profile), |
| list_controller_(list_controller), |
| extension_registry_observer_(this), |
| - clock_(clock.Pass()) { |
| + clock_(clock.Pass()), |
| + update_results_factory_(this) { |
| extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); |
| RefreshApps(); |
| } |
| @@ -101,6 +104,8 @@ void AppSearchProvider::UpdateResults() { |
| } |
| Add(result.Pass()); |
| } |
| + |
| + 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
|
| } |
| void AppSearchProvider::AddApps(const extensions::ExtensionSet& extensions) { |
| @@ -132,7 +137,12 @@ void AppSearchProvider::OnExtensionLoaded( |
| content::BrowserContext* browser_context, |
| const extensions::Extension* extension) { |
| RefreshApps(); |
| - UpdateResults(); |
| + if (!update_results_factory_.HasWeakPtrs()) { |
| + base::MessageLoop::current()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&AppSearchProvider::UpdateResults, |
| + update_results_factory_.GetWeakPtr())); |
| + } |
| } |
| void AppSearchProvider::OnExtensionUninstalled( |
| @@ -140,7 +150,12 @@ void AppSearchProvider::OnExtensionUninstalled( |
| const extensions::Extension* extension, |
| extensions::UninstallReason reason) { |
| RefreshApps(); |
| - UpdateResults(); |
| + if (!update_results_factory_.HasWeakPtrs()) { |
| + base::MessageLoop::current()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&AppSearchProvider::UpdateResults, |
| + update_results_factory_.GetWeakPtr())); |
| + } |
| } |
| } // namespace app_list |