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

Side by Side Diff: chrome/browser/ui/app_list/recommended_apps.cc

Issue 298023009: Remove InstallTracker's extension load, unload observer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: OnShutdown Created 6 years, 6 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 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/recommended_apps.h" 5 #include "chrome/browser/ui/app_list/recommended_apps.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "chrome/browser/extensions/extension_ui_util.h" 11 #include "chrome/browser/extensions/extension_ui_util.h"
12 #include "chrome/browser/extensions/install_tracker.h"
13 #include "chrome/browser/extensions/install_tracker_factory.h"
14 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/app_list/recommended_apps_observer.h" 13 #include "chrome/browser/ui/app_list/recommended_apps_observer.h"
16 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
17 #include "extensions/browser/extension_prefs.h" 15 #include "extensions/browser/extension_prefs.h"
18 #include "extensions/browser/extension_registry.h" 16 #include "extensions/browser/extension_registry.h"
19 #include "extensions/browser/pref_names.h" 17 #include "extensions/browser/pref_names.h"
20 #include "extensions/common/extension.h" 18 #include "extensions/common/extension.h"
21 #include "extensions/common/extension_set.h" 19 #include "extensions/common/extension_set.h"
22 20
23 namespace app_list { 21 namespace app_list {
24 22
25 namespace { 23 namespace {
26 24
27 struct AppSortInfo { 25 struct AppSortInfo {
28 AppSortInfo() : app(NULL) {} 26 AppSortInfo() : app(NULL) {}
29 AppSortInfo(const extensions::Extension* app, 27 AppSortInfo(const extensions::Extension* app,
30 const base::Time& last_launch_time) 28 const base::Time& last_launch_time)
31 : app(app), last_launch_time(last_launch_time) {} 29 : app(app), last_launch_time(last_launch_time) {}
32 30
33 const extensions::Extension* app; 31 const extensions::Extension* app;
34 base::Time last_launch_time; 32 base::Time last_launch_time;
35 }; 33 };
36 34
37 bool AppLaunchedMoreRecent(const AppSortInfo& app1, const AppSortInfo& app2) { 35 bool AppLaunchedMoreRecent(const AppSortInfo& app1, const AppSortInfo& app2) {
38 return app1.last_launch_time > app2.last_launch_time; 36 return app1.last_launch_time > app2.last_launch_time;
39 } 37 }
40 38
41 } // namespace 39 } // namespace
42 40
43 RecommendedApps::RecommendedApps(Profile* profile) : profile_(profile) { 41 RecommendedApps::RecommendedApps(Profile* profile)
44 extensions::InstallTrackerFactory::GetForProfile(profile_)->AddObserver(this); 42 : profile_(profile), extension_registry_observer_(this) {
45
46 extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_); 43 extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_);
47 pref_change_registrar_.Init(prefs->pref_service()); 44 pref_change_registrar_.Init(prefs->pref_service());
48 pref_change_registrar_.Add(extensions::pref_names::kExtensions, 45 pref_change_registrar_.Add(extensions::pref_names::kExtensions,
49 base::Bind(&RecommendedApps::Update, 46 base::Bind(&RecommendedApps::Update,
50 base::Unretained(this))); 47 base::Unretained(this)));
51 48 extension_registry_observer_.Add(extensions::ExtensionRegistry::Get(profile));
52 Update(); 49 Update();
53 } 50 }
54 51
55 RecommendedApps::~RecommendedApps() { 52 RecommendedApps::~RecommendedApps() {
56 extensions::InstallTrackerFactory::GetForProfile(profile_)
57 ->RemoveObserver(this);
58 } 53 }
59 54
60 void RecommendedApps::AddObserver(RecommendedAppsObserver* observer) { 55 void RecommendedApps::AddObserver(RecommendedAppsObserver* observer) {
61 observers_.AddObserver(observer); 56 observers_.AddObserver(observer);
62 } 57 }
63 58
64 void RecommendedApps::RemoveObserver(RecommendedAppsObserver* observer) { 59 void RecommendedApps::RemoveObserver(RecommendedAppsObserver* observer) {
65 observers_.RemoveObserver(observer); 60 observers_.RemoveObserver(observer);
66 } 61 }
67 62
(...skipping 24 matching lines...) Expand all
92 87
93 const bool changed = apps_.size() != new_recommends.size() || 88 const bool changed = apps_.size() != new_recommends.size() ||
94 !std::equal(apps_.begin(), apps_.end(), new_recommends.begin()); 89 !std::equal(apps_.begin(), apps_.end(), new_recommends.begin());
95 if (changed) { 90 if (changed) {
96 apps_.swap(new_recommends); 91 apps_.swap(new_recommends);
97 FOR_EACH_OBSERVER( 92 FOR_EACH_OBSERVER(
98 RecommendedAppsObserver, observers_, OnRecommendedAppsChanged()); 93 RecommendedAppsObserver, observers_, OnRecommendedAppsChanged());
99 } 94 }
100 } 95 }
101 96
102 void RecommendedApps::OnExtensionInstalled(
103 const extensions::Extension* extension) {
104 Update();
105 }
106
107 void RecommendedApps::OnExtensionLoaded( 97 void RecommendedApps::OnExtensionLoaded(
98 content::BrowserContext* browser_context,
108 const extensions::Extension* extension) { 99 const extensions::Extension* extension) {
109 Update(); 100 Update();
110 } 101 }
111 102
112 void RecommendedApps::OnExtensionUnloaded( 103 void RecommendedApps::OnExtensionUnloaded(
113 const extensions::Extension* extension) { 104 content::BrowserContext* browser_context,
105 const extensions::Extension* extension,
106 extensions::UnloadedExtensionInfo::Reason reason) {
107 Update();
108 }
109
110 void RecommendedApps::OnExtensionWillBeInstalled(
111 content::BrowserContext* browser_context,
112 const extensions::Extension* extension,
113 bool is_update,
114 bool from_ephemeral,
115 const std::string& old_name) {
114 Update(); 116 Update();
115 } 117 }
116 118
117 void RecommendedApps::OnExtensionUninstalled( 119 void RecommendedApps::OnExtensionUninstalled(
120 content::BrowserContext* browser_context,
118 const extensions::Extension* extension) { 121 const extensions::Extension* extension) {
119 Update(); 122 Update();
120 } 123 }
121 124
122 } // namespace app_list 125 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698