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

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

Issue 12298015: Change NotifyAppList*() functions into observers on a ProfileKeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
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/ui/app_list/apps_model_builder.h" 5 #include "chrome/browser/ui/app_list/apps_model_builder.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "chrome/browser/extensions/extension_prefs.h" 11 #include "chrome/browser/extensions/extension_prefs.h"
12 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/extensions/extension_system.h" 13 #include "chrome/browser/extensions/extension_system.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/app_list/extension_app_item.h" 15 #include "chrome/browser/ui/app_list/extension_app_item.h"
16 #include "chrome/common/chrome_notification_types.h" 16 #include "chrome/common/chrome_notification_types.h"
17 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
18 #include "content/public/browser/notification_service.h" 18 #include "content/public/browser/notification_service.h"
19 #include "ui/gfx/image/image_skia.h" 19 #include "ui/gfx/image/image_skia.h"
20 20
21 using extensions::Extension; 21 using extensions::Extension;
22 using extensions::ExtensionInstallingDetails;
22 23
23 namespace { 24 namespace {
24 25
25 bool AppPrecedes(const ExtensionAppItem* app1, const ExtensionAppItem* app2) { 26 bool AppPrecedes(const ExtensionAppItem* app1, const ExtensionAppItem* app2) {
26 const syncer::StringOrdinal& page1 = app1->GetPageOrdinal(); 27 const syncer::StringOrdinal& page1 = app1->GetPageOrdinal();
27 const syncer::StringOrdinal& page2 = app2->GetPageOrdinal(); 28 const syncer::StringOrdinal& page2 = app2->GetPageOrdinal();
28 if (page1.LessThan(page2)) 29 if (page1.LessThan(page2))
29 return true; 30 return true;
30 31
31 if (page1.Equals(page2)) 32 if (page1.Equals(page2))
(...skipping 14 matching lines...) Expand all
46 extensions::ExtensionPrefs* extension_prefs = 47 extensions::ExtensionPrefs* extension_prefs =
47 extensions::ExtensionSystem::Get(profile_)->extension_service()-> 48 extensions::ExtensionSystem::Get(profile_)->extension_service()->
48 extension_prefs(); 49 extension_prefs();
49 50
50 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 51 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
51 content::Source<Profile>(profile_)); 52 content::Source<Profile>(profile_));
52 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 53 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
53 content::Source<Profile>(profile_)); 54 content::Source<Profile>(profile_));
54 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, 55 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED,
55 content::Source<ExtensionSorting>(extension_prefs->extension_sorting())); 56 content::Source<ExtensionSorting>(extension_prefs->extension_sorting()));
57 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_BEGIN,
58 content::Source<Profile>(profile_));
59 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_PROGRESS,
60 content::Source<Profile>(profile_));
61 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_FAIL,
62 content::Source<Profile>(profile_));
56 registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST, 63 registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST,
57 content::Source<Profile>(profile_)); 64 content::Source<Profile>(profile_));
58 65
59 pref_change_registrar_.Init(extension_prefs->pref_service()); 66 pref_change_registrar_.Init(extension_prefs->pref_service());
60 pref_change_registrar_.Add(extensions::ExtensionPrefs::kExtensionsPref, 67 pref_change_registrar_.Add(extensions::ExtensionPrefs::kExtensionsPref,
61 base::Bind(&AppsModelBuilder::ResortApps, 68 base::Bind(&AppsModelBuilder::ResortApps,
62 base::Unretained(this))); 69 base::Unretained(this)));
63 70
64 model_->AddObserver(this); 71 model_->AddObserver(this);
65 } 72 }
66 73
67 AppsModelBuilder::~AppsModelBuilder() { 74 AppsModelBuilder::~AppsModelBuilder() {
68 model_->RemoveObserver(this); 75 model_->RemoveObserver(this);
69 } 76 }
70 77
71 void AppsModelBuilder::Build() { 78 void AppsModelBuilder::Build() {
72 DCHECK(model_ && model_->item_count() == 0); 79 DCHECK(model_ && model_->item_count() == 0);
73 80
74 PopulateApps(); 81 PopulateApps();
75 HighlightApp(); 82 HighlightApp();
76 } 83 }
77 84
78 void AppsModelBuilder::OnBeginExtensionInstall(
79 const std::string& extension_id,
80 const std::string& extension_name,
81 const gfx::ImageSkia& installing_icon) {
82 InsertApp(new ExtensionAppItem(profile_,
83 extension_id,
84 controller_,
85 extension_name,
86 installing_icon));
87 highlight_app_id_ = extension_id;
88 HighlightApp();
89 }
90
91 void AppsModelBuilder::OnDownloadProgress(const std::string& extension_id,
92 int percent_downloaded) {
93 int i = FindApp(extension_id);
94 if (i == -1)
95 return;
96 GetAppAt(i)->SetPercentDownloaded(percent_downloaded);
97 }
98
99 void AppsModelBuilder::OnInstallFailure(const std::string& extension_id) {
100 int i = FindApp(extension_id);
101 if (i == -1)
102 return;
103 model_->DeleteAt(i);
104 }
105
106 void AppsModelBuilder::AddApps(const ExtensionSet* extensions, Apps* apps) { 85 void AppsModelBuilder::AddApps(const ExtensionSet* extensions, Apps* apps) {
107 for (ExtensionSet::const_iterator app = extensions->begin(); 86 for (ExtensionSet::const_iterator app = extensions->begin();
108 app != extensions->end(); ++app) { 87 app != extensions->end(); ++app) {
109 if ((*app)->ShouldDisplayInAppLauncher()) 88 if ((*app)->ShouldDisplayInAppLauncher())
110 apps->push_back(new ExtensionAppItem(profile_, 89 apps->push_back(new ExtensionAppItem(profile_,
111 (*app)->id(), 90 (*app)->id(),
112 controller_, 91 controller_,
113 "", 92 "",
114 gfx::ImageSkia())); 93 gfx::ImageSkia()));
115 } 94 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 if (unload_info->reason == extension_misc::UNLOAD_REASON_UNINSTALL) 224 if (unload_info->reason == extension_misc::UNLOAD_REASON_UNINSTALL)
246 model_->DeleteAt(index); 225 model_->DeleteAt(index);
247 else 226 else
248 GetAppAt(index)->UpdateIcon(); 227 GetAppAt(index)->UpdateIcon();
249 break; 228 break;
250 } 229 }
251 case chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED: { 230 case chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED: {
252 ResortApps(); 231 ResortApps();
253 break; 232 break;
254 } 233 }
234 case chrome::NOTIFICATION_EXTENSION_INSTALL_BEGIN: {
235 ExtensionInstallingDetails* d =
236 content::Details<ExtensionInstallingDetails>(details).ptr();
237
238 InsertApp(new ExtensionAppItem(profile_,
239 d->extension_id,
240 controller_,
241 d->extension_name,
242 d->icon));
243 highlight_app_id_ = d->extension_id;
244 HighlightApp();
245 }
246 case chrome::NOTIFICATION_EXTENSION_INSTALL_PROGRESS: {
247 std::pair<std::string, int>* complete_details =
248 content::Details<std::pair<std::string, int> >(details).ptr();
249 std::string& extension_id = complete_details->first;
250 int percent_downloaded = complete_details->second;
251 int i = FindApp(extension_id);
252 if (i == -1)
253 return;
254 GetAppAt(i)->SetPercentDownloaded(percent_downloaded);
255 }
256 case chrome::NOTIFICATION_EXTENSION_INSTALL_FAIL: {
257 const std::string& extension_id =
258 *content::Details<std::string>(details).ptr();
259 int i = FindApp(extension_id);
260 if (i == -1)
261 return;
262 model_->DeleteAt(i);
263 }
255 case chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST: { 264 case chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST: {
256 highlight_app_id_ = *content::Details<const std::string>(details).ptr(); 265 highlight_app_id_ = *content::Details<const std::string>(details).ptr();
257 HighlightApp(); 266 HighlightApp();
258 break; 267 break;
259 } 268 }
260 default: 269 default:
261 NOTREACHED(); 270 NOTREACHED();
262 } 271 }
263 } 272 }
264 273
265 void AppsModelBuilder::ListItemsAdded(size_t start, size_t count) { 274 void AppsModelBuilder::ListItemsAdded(size_t start, size_t count) {
266 } 275 }
267 276
268 void AppsModelBuilder::ListItemsRemoved(size_t start, size_t count) { 277 void AppsModelBuilder::ListItemsRemoved(size_t start, size_t count) {
269 } 278 }
270 279
271 void AppsModelBuilder::ListItemMoved(size_t index, size_t target_index) { 280 void AppsModelBuilder::ListItemMoved(size_t index, size_t target_index) {
272 if (ignore_changes_) 281 if (ignore_changes_)
273 return; 282 return;
274 283
275 ExtensionAppItem* prev = target_index > 0 ? GetAppAt(target_index - 1) : NULL; 284 ExtensionAppItem* prev = target_index > 0 ? GetAppAt(target_index - 1) : NULL;
276 ExtensionAppItem* next = target_index + 1 < model_->item_count() ? 285 ExtensionAppItem* next = target_index + 1 < model_->item_count() ?
277 GetAppAt(target_index + 1) : NULL; 286 GetAppAt(target_index + 1) : NULL;
278 GetAppAt(target_index)->Move(prev, next); 287 GetAppAt(target_index)->Move(prev, next);
279 } 288 }
280 289
281 void AppsModelBuilder::ListItemsChanged(size_t start, size_t count) { 290 void AppsModelBuilder::ListItemsChanged(size_t start, size_t count) {
282 NOTREACHED(); 291 NOTREACHED();
283 } 292 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698