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

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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 const std::string& extension_id, 98 const std::string& extension_id,
99 int percent_downloaded) { 99 int percent_downloaded) {
100 ExtensionAppItem* item = GetExtensionAppItem(extension_id); 100 ExtensionAppItem* item = GetExtensionAppItem(extension_id);
101 if (!item) 101 if (!item)
102 return; 102 return;
103 item->SetPercentDownloaded(percent_downloaded); 103 item->SetPercentDownloaded(percent_downloaded);
104 } 104 }
105 105
106 void ExtensionAppModelBuilder::OnInstallFailure( 106 void ExtensionAppModelBuilder::OnInstallFailure(
107 const std::string& extension_id) { 107 const std::string& extension_id) {
108 model_->item_list()->DeleteItem(extension_id); 108 model_->DeleteItem(extension_id);
109 } 109 }
110 110
111 void ExtensionAppModelBuilder::OnExtensionLoaded(const Extension* extension) { 111 void ExtensionAppModelBuilder::OnExtensionLoaded(const Extension* extension) {
112 if (!extension->ShouldDisplayInAppLauncher()) 112 if (!extension->ShouldDisplayInAppLauncher())
113 return; 113 return;
114 114
115 DVLOG(2) << service_ << ": OnExtensionLoaded: " 115 DVLOG(2) << service_ << ": OnExtensionLoaded: "
116 << extension->id().substr(0, 8); 116 << extension->id().substr(0, 8);
117 ExtensionAppItem* existing_item = GetExtensionAppItem(extension->id()); 117 ExtensionAppItem* existing_item = GetExtensionAppItem(extension->id());
118 if (existing_item) { 118 if (existing_item) {
(...skipping 16 matching lines...) Expand all
135 } 135 }
136 136
137 void ExtensionAppModelBuilder::OnExtensionUninstalled( 137 void ExtensionAppModelBuilder::OnExtensionUninstalled(
138 const Extension* extension) { 138 const Extension* extension) {
139 if (service_) { 139 if (service_) {
140 DVLOG(2) << service_ << ": OnExtensionUninstalled: " 140 DVLOG(2) << service_ << ": OnExtensionUninstalled: "
141 << extension->id().substr(0, 8); 141 << extension->id().substr(0, 8);
142 service_->RemoveItem(extension->id()); 142 service_->RemoveItem(extension->id());
143 return; 143 return;
144 } 144 }
145 model_->item_list()->DeleteItem(extension->id()); 145 model_->DeleteItem(extension->id());
146 } 146 }
147 147
148 void ExtensionAppModelBuilder::OnAppsReordered() { 148 void ExtensionAppModelBuilder::OnAppsReordered() {
149 // Do nothing; App List order does not track extensions order. 149 // Do nothing; App List order does not track extensions order.
150 } 150 }
151 151
152 void ExtensionAppModelBuilder::OnAppInstalledToAppList( 152 void ExtensionAppModelBuilder::OnAppInstalledToAppList(
153 const std::string& extension_id) { 153 const std::string& extension_id) {
154 SetHighlightedApp(extension_id); 154 SetHighlightedApp(extension_id);
155 } 155 }
(...skipping 28 matching lines...) Expand all
184 if (ShouldDisplayInAppLauncher(profile_, *app)) { 184 if (ShouldDisplayInAppLauncher(profile_, *app)) {
185 apps->push_back(CreateAppItem((*app)->id(), 185 apps->push_back(CreateAppItem((*app)->id(),
186 "", 186 "",
187 gfx::ImageSkia(), 187 gfx::ImageSkia(),
188 (*app)->is_platform_app())); 188 (*app)->is_platform_app()));
189 } 189 }
190 } 190 }
191 } 191 }
192 192
193 void ExtensionAppModelBuilder::BuildModel() { 193 void ExtensionAppModelBuilder::BuildModel() {
194 // Delete any extension apps.
195 model_->item_list()->DeleteItemsByType(ExtensionAppItem::kItemType);
196
jennyz 2014/01/28 18:02:48 Is the model_ empty, or we just don't need to clea
stevenjb 2014/01/28 18:28:08 This only gets called once now. We used to call th
197 if (tracker_) 194 if (tracker_)
198 tracker_->RemoveObserver(this); 195 tracker_->RemoveObserver(this);
199 196
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_)
(...skipping 11 matching lines...) Expand all
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