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

Side by Side Diff: chrome/browser/ui/app_list/fast_show_pickler.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 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/fast_show_pickler.h" 5 #include "chrome/browser/ui/app_list/fast_show_pickler.h"
6 6
7 #include "third_party/skia/include/core/SkBitmap.h" 7 #include "third_party/skia/include/core/SkBitmap.h"
8 #include "ui/app_list/app_list_item.h" 8 #include "ui/app_list/app_list_item.h"
9 #include "ui/gfx/image/image_skia_rep.h" 9 #include "ui/gfx/image/image_skia_rep.h"
10 10
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 if (!result->WriteInt((int) model->item_list()->item_count())) 201 if (!result->WriteInt((int) model->item_list()->item_count()))
202 return scoped_ptr<Pickle>(); 202 return scoped_ptr<Pickle>();
203 for (size_t i = 0; i < model->item_list()->item_count(); ++i) { 203 for (size_t i = 0; i < model->item_list()->item_count(); ++i) {
204 if (!PickleAppListItem(result.get(), model->item_list()->item_at(i))) 204 if (!PickleAppListItem(result.get(), model->item_list()->item_at(i)))
205 return scoped_ptr<Pickle>(); 205 return scoped_ptr<Pickle>();
206 } 206 }
207 return result.Pass(); 207 return result.Pass();
208 } 208 }
209 209
210 void FastShowPickler::CopyOver(AppListModel* src, AppListModel* dest) { 210 void FastShowPickler::CopyOver(AppListModel* src, AppListModel* dest) {
211 dest->item_list()->DeleteItemsByType(NULL /* all items */); 211 DCHECK_EQ(0u, dest->item_list()->item_count());
212 for (size_t i = 0; i < src->item_list()->item_count(); i++) { 212 for (size_t i = 0; i < src->item_list()->item_count(); i++) {
213 AppListItem* src_item = src->item_list()->item_at(i); 213 AppListItem* src_item = src->item_list()->item_at(i);
214 AppListItem* dest_item = new AppListItem(src_item->id()); 214 AppListItem* dest_item = new AppListItem(src_item->id());
215 CopyOverItem(src_item, dest_item); 215 CopyOverItem(src_item, dest_item);
216 dest->item_list()->AddItem(dest_item); 216 dest->AddItem(dest_item);
217 } 217 }
218 } 218 }
219 219
220 scoped_ptr<AppListModel> 220 scoped_ptr<AppListModel>
221 FastShowPickler::UnpickleAppListModelForFastShow(Pickle* pickle) { 221 FastShowPickler::UnpickleAppListModelForFastShow(Pickle* pickle) {
222 PickleIterator it(*pickle); 222 PickleIterator it(*pickle);
223 int read_version = 0; 223 int read_version = 0;
224 if (!it.ReadInt(&read_version)) 224 if (!it.ReadInt(&read_version))
225 return scoped_ptr<AppListModel>(); 225 return scoped_ptr<AppListModel>();
226 if (read_version != kVersion) 226 if (read_version != kVersion)
227 return scoped_ptr<AppListModel>(); 227 return scoped_ptr<AppListModel>();
228 int app_count = 0; 228 int app_count = 0;
229 if (!it.ReadInt(&app_count)) 229 if (!it.ReadInt(&app_count))
230 return scoped_ptr<AppListModel>(); 230 return scoped_ptr<AppListModel>();
231 231
232 scoped_ptr<AppListModel> model(new AppListModel); 232 scoped_ptr<AppListModel> model(new AppListModel);
233 for (int i = 0; i < app_count; ++i) { 233 for (int i = 0; i < app_count; ++i) {
234 scoped_ptr<AppListItem> item(UnpickleAppListItem(&it).Pass()); 234 scoped_ptr<AppListItem> item(UnpickleAppListItem(&it).Pass());
235 if (!item) 235 if (!item)
236 return scoped_ptr<AppListModel>(); 236 return scoped_ptr<AppListModel>();
237 model->item_list()->AddItem(item.release()); 237 model->AddItem(item.release());
238 } 238 }
239 239
240 return model.Pass(); 240 return model.Pass();
241 } 241 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698