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

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

Issue 27438002: Store AppItems as pages in AppListModel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 2 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_model.h" 8 #include "ui/app_list/app_list_item_model.h"
9 #include "ui/gfx/image/image_skia_rep.h" 9 #include "ui/gfx/image/image_skia_rep.h"
10 10
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 return false; 182 return false;
183 if (!pickle->WriteString(item->full_name())) 183 if (!pickle->WriteString(item->full_name()))
184 return false; 184 return false;
185 if (!pickle->WriteBool(item->has_shadow())) 185 if (!pickle->WriteBool(item->has_shadow()))
186 return false; 186 return false;
187 if (!PickleImage(pickle, item->icon())) 187 if (!PickleImage(pickle, item->icon()))
188 return false; 188 return false;
189 return true; 189 return true;
190 } 190 }
191 191
192 void CopyOverItem(AppListItemModel* src_item, AppListItemModel* dest_item) {
193 dest_item->SetTitleAndFullName(src_item->title(), src_item->full_name());
194 dest_item->SetIcon(src_item->icon(), src_item->has_shadow());
195 }
196
197 } // namespace 192 } // namespace
198 193
199 // The version of the pickle format defined here. This needs to be incremented 194 // The version of the pickle format defined here. This needs to be incremented
200 // whenever this format is changed so new clients can invalidate old versions. 195 // whenever this format is changed so new clients can invalidate old versions.
201 const int FastShowPickler::kVersion = 1; 196 const int FastShowPickler::kVersion = 2;
202 197
203 scoped_ptr<Pickle> FastShowPickler::PickleAppListModelForFastShow( 198 scoped_ptr<Pickle> FastShowPickler::PickleAppListModelForFastShow(
204 AppListModel* model) { 199 AppListModel* model) {
205 scoped_ptr<Pickle> result(new Pickle); 200 scoped_ptr<Pickle> result(new Pickle);
206 if (!result->WriteInt(kVersion)) 201 if (!result->WriteInt(kVersion))
207 return scoped_ptr<Pickle>(); 202 return scoped_ptr<Pickle>();
208 if (!result->WriteBool(model->signed_in())) 203 if (!result->WriteBool(model->signed_in()))
209 return scoped_ptr<Pickle>(); 204 return scoped_ptr<Pickle>();
210 if (!result->WriteInt((int) model->apps()->item_count())) 205 // Write the number of pages.
206 size_t page_count = model->GetNumAppPages();
207 if (!result->WriteInt(static_cast<int>(page_count)))
211 return scoped_ptr<Pickle>(); 208 return scoped_ptr<Pickle>();
212 for (size_t i = 0; i < model->apps()->item_count(); ++i) { 209 for (size_t p = 0; p < page_count; ++p) {
213 if (!PickleAppListItemModel(result.get(), model->apps()->GetItemAt(i))) 210 // Write the number of items in the page.
211 size_t item_count = model->GetAppItems(p).item_count();
212 if (!result->WriteInt(static_cast<int>(item_count)))
214 return scoped_ptr<Pickle>(); 213 return scoped_ptr<Pickle>();
214 // Write the items in the page.
215 for (size_t i = 0; i < item_count; ++i) {
216 if (!PickleAppListItemModel(result.get(), model->GetItemAt(p, i)))
217 return scoped_ptr<Pickle>();
218 }
215 } 219 }
216 return result.Pass(); 220 return result.Pass();
217 } 221 }
218 222
219 void FastShowPickler::CopyOver(AppListModel* src, AppListModel* dest) {
220 dest->apps()->DeleteAll();
221 dest->SetSignedIn(src->signed_in());
222 for (size_t i = 0; i < src->apps()->item_count(); i++) {
223 AppListItemModel* src_item = src->apps()->GetItemAt(i);
224 AppListItemModel* dest_item = new AppListItemModel(src_item->id());
225 CopyOverItem(src_item, dest_item);
226 dest->apps()->Add(dest_item);
227 }
228 }
229
230 scoped_ptr<AppListModel> 223 scoped_ptr<AppListModel>
231 FastShowPickler::UnpickleAppListModelForFastShow(Pickle* pickle) { 224 FastShowPickler::UnpickleAppListModelForFastShow(Pickle* pickle) {
232 PickleIterator it(*pickle); 225 PickleIterator it(*pickle);
233 int read_version = 0; 226 int read_version = 0;
234 if (!it.ReadInt(&read_version)) 227 if (!it.ReadInt(&read_version))
235 return scoped_ptr<AppListModel>(); 228 return scoped_ptr<AppListModel>();
236 if (read_version != kVersion) 229 if (read_version != kVersion)
237 return scoped_ptr<AppListModel>(); 230 return scoped_ptr<AppListModel>();
238 int app_count = 0;
239 bool signed_in = false; 231 bool signed_in = false;
240 if (!it.ReadBool(&signed_in)) 232 if (!it.ReadBool(&signed_in))
241 return scoped_ptr<AppListModel>(); 233 return scoped_ptr<AppListModel>();
242 if (!it.ReadInt(&app_count)) 234 // Read the number of pages.
235 int page_count = 0;
236 if (!it.ReadInt(&page_count))
243 return scoped_ptr<AppListModel>(); 237 return scoped_ptr<AppListModel>();
244
245 scoped_ptr<AppListModel> model(new AppListModel); 238 scoped_ptr<AppListModel> model(new AppListModel);
246 model->SetSignedIn(signed_in); 239 model->SetSignedIn(signed_in);
247 for (int i = 0; i < app_count; ++i) { 240 for (size_t p = 0; p < static_cast<size_t>(page_count); ++p) {
248 scoped_ptr<AppListItemModel> item(UnpickleAppListItemModel(&it).Pass()); 241 // Read the number of items in the page.
249 if (!item) 242 int item_count = 0;
243 if (!it.ReadInt(&item_count))
250 return scoped_ptr<AppListModel>(); 244 return scoped_ptr<AppListModel>();
251 model->apps()->Add(item.release()); 245 // Read each item in the page.
246 for (int i = 0; i < item_count; ++i) {
247 scoped_ptr<AppListItemModel> item(UnpickleAppListItemModel(&it).Pass());
248 if (!item)
249 return scoped_ptr<AppListModel>();
250 model->AddItemToPage(item.release(), p);
251 }
252 } 252 }
253 253
254 return model.Pass(); 254 return model.Pass();
255 } 255 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698