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

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

Issue 148403007: Protect AppListItemList Add/Remove and fix sync bugs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 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/extension_app_model_builder.h" 5 #include "chrome/browser/ui/app_list/extension_app_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"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 tracker_(NULL) { 52 tracker_(NULL) {
53 } 53 }
54 54
55 ExtensionAppModelBuilder::~ExtensionAppModelBuilder() { 55 ExtensionAppModelBuilder::~ExtensionAppModelBuilder() {
56 OnShutdown(); 56 OnShutdown();
57 model_->item_list()->RemoveObserver(this); 57 model_->item_list()->RemoveObserver(this);
58 } 58 }
59 59
60 void ExtensionAppModelBuilder::InitializeWithService( 60 void ExtensionAppModelBuilder::InitializeWithService(
61 app_list::AppListSyncableService* service) { 61 app_list::AppListSyncableService* service) {
62 DCHECK(!service_ && !profile_);
62 model_ = service->model(); 63 model_ = service->model();
63 model_->item_list()->AddObserver(this); 64 model_->item_list()->AddObserver(this);
64 service_ = service; 65 service_ = service;
65 profile_ = service->profile(); 66 profile_ = service->profile();
66 BuildModel(); 67 BuildModel();
67 } 68 }
68 69
69 void ExtensionAppModelBuilder::InitializeWithProfile( 70 void ExtensionAppModelBuilder::InitializeWithProfile(
70 Profile* profile, 71 Profile* profile,
71 app_list::AppListModel* model) { 72 app_list::AppListModel* model) {
73 DCHECK(!service_ && !profile_);
72 model_ = model; 74 model_ = model;
73 model_->item_list()->AddObserver(this); 75 model_->item_list()->AddObserver(this);
74 profile_ = profile; 76 profile_ = profile;
75 BuildModel(); 77 BuildModel();
76 } 78 }
77 79
78 void ExtensionAppModelBuilder::OnBeginExtensionInstall( 80 void ExtensionAppModelBuilder::OnBeginExtensionInstall(
79 const ExtensionInstallParams& params) { 81 const ExtensionInstallParams& params) {
80 if (!params.is_app || params.is_ephemeral) 82 if (!params.is_app || params.is_ephemeral)
81 return; 83 return;
(...skipping 16 matching lines...) Expand all
98 const std::string& extension_id, 100 const std::string& extension_id,
99 int percent_downloaded) { 101 int percent_downloaded) {
100 ExtensionAppItem* item = GetExtensionAppItem(extension_id); 102 ExtensionAppItem* item = GetExtensionAppItem(extension_id);
101 if (!item) 103 if (!item)
102 return; 104 return;
103 item->SetPercentDownloaded(percent_downloaded); 105 item->SetPercentDownloaded(percent_downloaded);
104 } 106 }
105 107
106 void ExtensionAppModelBuilder::OnInstallFailure( 108 void ExtensionAppModelBuilder::OnInstallFailure(
107 const std::string& extension_id) { 109 const std::string& extension_id) {
108 model_->item_list()->DeleteItem(extension_id); 110 model_->DeleteItem(extension_id);
109 } 111 }
110 112
111 void ExtensionAppModelBuilder::OnExtensionLoaded(const Extension* extension) { 113 void ExtensionAppModelBuilder::OnExtensionLoaded(const Extension* extension) {
112 if (!extension->ShouldDisplayInAppLauncher()) 114 if (!extension->ShouldDisplayInAppLauncher())
113 return; 115 return;
114 116
115 DVLOG(2) << service_ << ": OnExtensionLoaded: " 117 DVLOG(2) << service_ << ": OnExtensionLoaded: "
116 << extension->id().substr(0, 8); 118 << extension->id().substr(0, 8);
117 ExtensionAppItem* existing_item = GetExtensionAppItem(extension->id()); 119 ExtensionAppItem* existing_item = GetExtensionAppItem(extension->id());
118 if (existing_item) { 120 if (existing_item) {
(...skipping 16 matching lines...) Expand all
135 } 137 }
136 138
137 void ExtensionAppModelBuilder::OnExtensionUninstalled( 139 void ExtensionAppModelBuilder::OnExtensionUninstalled(
138 const Extension* extension) { 140 const Extension* extension) {
139 if (service_) { 141 if (service_) {
140 DVLOG(2) << service_ << ": OnExtensionUninstalled: " 142 DVLOG(2) << service_ << ": OnExtensionUninstalled: "
141 << extension->id().substr(0, 8); 143 << extension->id().substr(0, 8);
142 service_->RemoveItem(extension->id()); 144 service_->RemoveItem(extension->id());
143 return; 145 return;
144 } 146 }
145 model_->item_list()->DeleteItem(extension->id()); 147 model_->DeleteItem(extension->id());
146 } 148 }
147 149
148 void ExtensionAppModelBuilder::OnAppsReordered() { 150 void ExtensionAppModelBuilder::OnAppsReordered() {
149 // Do nothing; App List order does not track extensions order. 151 // Do nothing; App List order does not track extensions order.
150 } 152 }
151 153
152 void ExtensionAppModelBuilder::OnAppInstalledToAppList( 154 void ExtensionAppModelBuilder::OnAppInstalledToAppList(
153 const std::string& extension_id) { 155 const std::string& extension_id) {
154 SetHighlightedApp(extension_id); 156 SetHighlightedApp(extension_id);
155 } 157 }
(...skipping 28 matching lines...) Expand all
184 if (ShouldDisplayInAppLauncher(profile_, *app)) { 186 if (ShouldDisplayInAppLauncher(profile_, *app)) {
185 apps->push_back(CreateAppItem((*app)->id(), 187 apps->push_back(CreateAppItem((*app)->id(),
186 "", 188 "",
187 gfx::ImageSkia(), 189 gfx::ImageSkia(),
188 (*app)->is_platform_app())); 190 (*app)->is_platform_app()));
189 } 191 }
190 } 192 }
191 } 193 }
192 194
193 void ExtensionAppModelBuilder::BuildModel() { 195 void ExtensionAppModelBuilder::BuildModel() {
194 // Delete any extension apps. 196 DCHECK(!tracker_);
195 model_->item_list()->DeleteItemsByType(ExtensionAppItem::kItemType);
196
197 if (tracker_)
198 tracker_->RemoveObserver(this);
199
200 tracker_ = controller_->GetInstallTrackerFor(profile_); 197 tracker_ = controller_->GetInstallTrackerFor(profile_);
201 198
202 PopulateApps(); 199 PopulateApps();
203 UpdateHighlight(); 200 UpdateHighlight();
204 201
205 // Start observing after model is built. 202 // Start observing after model is built.
206 if (tracker_) 203 if (tracker_)
207 tracker_->AddObserver(this); 204 tracker_->AddObserver(this);
208 } 205 }
209 206
210 void ExtensionAppModelBuilder::PopulateApps() { 207 void ExtensionAppModelBuilder::PopulateApps() {
211 extensions::ExtensionSet extensions; 208 extensions::ExtensionSet extensions;
212 controller_->GetApps(profile_, &extensions); 209 controller_->GetApps(profile_, &extensions);
213 ExtensionAppList apps; 210 ExtensionAppList apps;
214 AddApps(&extensions, &apps); 211 AddApps(&extensions, &apps);
215 212
216 if (apps.empty()) 213 if (apps.empty())
217 return; 214 return;
218 215
219 for (size_t i = 0; i < apps.size(); ++i) 216 for (size_t i = 0; i < apps.size(); ++i)
220 InsertApp(apps[i]); 217 InsertApp(apps[i]);
221 } 218 }
222 219
223 void ExtensionAppModelBuilder::InsertApp(ExtensionAppItem* app) { 220 void ExtensionAppModelBuilder::InsertApp(ExtensionAppItem* app) {
224 if (service_) { 221 if (service_) {
225 service_->AddItem(app); 222 service_->AddItem(app);
226 return; 223 return;
227 } 224 }
228 model_->item_list()->AddItem(app); 225 model_->AddItem(app);
229 } 226 }
230 227
231 void ExtensionAppModelBuilder::SetHighlightedApp( 228 void ExtensionAppModelBuilder::SetHighlightedApp(
232 const std::string& extension_id) { 229 const std::string& extension_id) {
233 if (extension_id == highlight_app_id_) 230 if (extension_id == highlight_app_id_)
234 return; 231 return;
235 ExtensionAppItem* old_app = GetExtensionAppItem(highlight_app_id_); 232 ExtensionAppItem* old_app = GetExtensionAppItem(highlight_app_id_);
236 if (old_app) 233 if (old_app)
237 old_app->SetHighlighted(false); 234 old_app->SetHighlighted(false);
238 highlight_app_id_ = extension_id; 235 highlight_app_id_ = extension_id;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 app_list::AppListItem* item = item_list->item_at(idx + 1); 286 app_list::AppListItem* item = item_list->item_at(idx + 1);
290 if (item->GetItemType() == ExtensionAppItem::kItemType) { 287 if (item->GetItemType() == ExtensionAppItem::kItemType) {
291 next = static_cast<ExtensionAppItem*>(item); 288 next = static_cast<ExtensionAppItem*>(item);
292 break; 289 break;
293 } 290 }
294 } 291 }
295 // item->Move will call set_position, overriding the item's position. 292 // item->Move will call set_position, overriding the item's position.
296 if (prev || next) 293 if (prev || next)
297 static_cast<ExtensionAppItem*>(item)->Move(prev, next); 294 static_cast<ExtensionAppItem*>(item)->Move(prev, next);
298 } 295 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698