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

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: Address comments 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) { 192 void CopyAppListItemModel(const AppListItemModel* src_item,
193 AppListItemModel* dest_item) {
193 dest_item->SetTitleAndFullName(src_item->title(), src_item->full_name()); 194 dest_item->SetTitleAndFullName(src_item->title(), src_item->full_name());
194 dest_item->SetIcon(src_item->icon(), src_item->has_shadow()); 195 dest_item->SetIcon(src_item->icon(), src_item->has_shadow());
195 } 196 }
196 197
197 } // namespace 198 } // namespace
198 199
199 // The version of the pickle format defined here. This needs to be incremented 200 // 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. 201 // whenever this format is changed so new clients can invalidate old versions.
201 const int FastShowPickler::kVersion = 1; 202 const int FastShowPickler::kVersion = 2;
202 203
204 // static
203 scoped_ptr<Pickle> FastShowPickler::PickleAppListModelForFastShow( 205 scoped_ptr<Pickle> FastShowPickler::PickleAppListModelForFastShow(
204 AppListModel* model) { 206 AppListModel* model) {
205 scoped_ptr<Pickle> result(new Pickle); 207 scoped_ptr<Pickle> result(new Pickle);
206 if (!result->WriteInt(kVersion)) 208 if (!result->WriteInt(kVersion))
207 return scoped_ptr<Pickle>(); 209 return scoped_ptr<Pickle>();
208 if (!result->WriteBool(model->signed_in())) 210 if (!result->WriteBool(model->signed_in()))
209 return scoped_ptr<Pickle>(); 211 return scoped_ptr<Pickle>();
210 if (!result->WriteInt((int) model->apps()->item_count())) 212 // Write the number of pages.
213 size_t page_count = model->GetNumAppPages();
214 if (!result->WriteInt(static_cast<int>(page_count)))
211 return scoped_ptr<Pickle>(); 215 return scoped_ptr<Pickle>();
212 for (size_t i = 0; i < model->apps()->item_count(); ++i) { 216 for (size_t p = 0; p < page_count; ++p) {
213 if (!PickleAppListItemModel(result.get(), model->apps()->GetItemAt(i))) 217 // Write the number of items in the page.
218 size_t item_count = model->GetAppItemsForPage(p).item_count();
219 if (!result->WriteInt(static_cast<int>(item_count)))
214 return scoped_ptr<Pickle>(); 220 return scoped_ptr<Pickle>();
221 // Write the items in the page.
222 for (size_t i = 0; i < item_count; ++i) {
223 if (!PickleAppListItemModel(result.get(), model->GetItemAt(p, i)))
224 return scoped_ptr<Pickle>();
225 }
215 } 226 }
216 return result.Pass(); 227 return result.Pass();
217 } 228 }
218 229
219 void FastShowPickler::CopyOver(AppListModel* src, AppListModel* dest) { 230 // static
220 dest->apps()->DeleteAll(); 231 void FastShowPickler::CopyAppListModel(const AppListModel* src,
232 AppListModel* dest) {
233 CHECK_EQ(0u, dest->GetNumAppPages());
221 dest->SetSignedIn(src->signed_in()); 234 dest->SetSignedIn(src->signed_in());
222 for (size_t i = 0; i < src->apps()->item_count(); i++) { 235 for (size_t p = 0; p < src->GetNumAppPages(); ++p) {
223 AppListItemModel* src_item = src->apps()->GetItemAt(i); 236 const AppListModel::AppItems& apps = src->GetAppItemsForPage(p);
224 AppListItemModel* dest_item = new AppListItemModel(src_item->id()); 237 for (size_t i = 0; i < apps.item_count(); ++i) {
225 CopyOverItem(src_item, dest_item); 238 const AppListItemModel* src_item = apps.GetItemAt(i);
226 dest->apps()->Add(dest_item); 239 AppListItemModel* dest_item = new AppListItemModel(src_item->id());
240 CopyAppListItemModel(src_item, dest_item);
241 dest->AddItem(dest_item);
242 }
227 } 243 }
228 } 244 }
229 245
246 // static
230 scoped_ptr<AppListModel> 247 scoped_ptr<AppListModel>
231 FastShowPickler::UnpickleAppListModelForFastShow(Pickle* pickle) { 248 FastShowPickler::UnpickleAppListModelForFastShow(Pickle* pickle) {
232 PickleIterator it(*pickle); 249 PickleIterator it(*pickle);
233 int read_version = 0; 250 int read_version = 0;
234 if (!it.ReadInt(&read_version)) 251 if (!it.ReadInt(&read_version))
235 return scoped_ptr<AppListModel>(); 252 return scoped_ptr<AppListModel>();
236 if (read_version != kVersion) 253 if (read_version != kVersion)
237 return scoped_ptr<AppListModel>(); 254 return scoped_ptr<AppListModel>();
238 int app_count = 0;
239 bool signed_in = false; 255 bool signed_in = false;
240 if (!it.ReadBool(&signed_in)) 256 if (!it.ReadBool(&signed_in))
241 return scoped_ptr<AppListModel>(); 257 return scoped_ptr<AppListModel>();
242 if (!it.ReadInt(&app_count)) 258 // Read the number of pages.
259 int page_count = 0;
260 if (!it.ReadInt(&page_count))
243 return scoped_ptr<AppListModel>(); 261 return scoped_ptr<AppListModel>();
244
245 scoped_ptr<AppListModel> model(new AppListModel); 262 scoped_ptr<AppListModel> model(new AppListModel);
246 model->SetSignedIn(signed_in); 263 model->SetSignedIn(signed_in);
247 for (int i = 0; i < app_count; ++i) { 264 for (size_t p = 0; p < static_cast<size_t>(page_count); ++p) {
248 scoped_ptr<AppListItemModel> item(UnpickleAppListItemModel(&it).Pass()); 265 // Read the number of items in the page.
249 if (!item) 266 int item_count = 0;
267 if (!it.ReadInt(&item_count))
250 return scoped_ptr<AppListModel>(); 268 return scoped_ptr<AppListModel>();
251 model->apps()->Add(item.release()); 269 // Read each item in the page.
270 for (int i = 0; i < item_count; ++i) {
271 scoped_ptr<AppListItemModel> item(UnpickleAppListItemModel(&it).Pass());
272 if (!item)
273 return scoped_ptr<AppListModel>();
274 model->AddItemToPage(item.release(), p);
275 }
252 } 276 }
253 277
254 return model.Pass(); 278 return model.Pass();
255 } 279 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698