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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/app_list/fast_show_pickler.cc
diff --git a/chrome/browser/ui/app_list/fast_show_pickler.cc b/chrome/browser/ui/app_list/fast_show_pickler.cc
index 80b2c0f58674719e07792bf8fcd3bba5c78f81c1..d5b31f10d7811a0df7e7060163737c59418cf8bc 100644
--- a/chrome/browser/ui/app_list/fast_show_pickler.cc
+++ b/chrome/browser/ui/app_list/fast_show_pickler.cc
@@ -189,7 +189,8 @@ bool PickleAppListItemModel(Pickle* pickle, AppListItemModel* item) {
return true;
}
-void CopyOverItem(AppListItemModel* src_item, AppListItemModel* dest_item) {
+void CopyAppListItemModel(const AppListItemModel* src_item,
+ AppListItemModel* dest_item) {
dest_item->SetTitleAndFullName(src_item->title(), src_item->full_name());
dest_item->SetIcon(src_item->icon(), src_item->has_shadow());
}
@@ -198,8 +199,9 @@ void CopyOverItem(AppListItemModel* src_item, AppListItemModel* dest_item) {
// The version of the pickle format defined here. This needs to be incremented
// whenever this format is changed so new clients can invalidate old versions.
-const int FastShowPickler::kVersion = 1;
+const int FastShowPickler::kVersion = 2;
+// static
scoped_ptr<Pickle> FastShowPickler::PickleAppListModelForFastShow(
AppListModel* model) {
scoped_ptr<Pickle> result(new Pickle);
@@ -207,26 +209,41 @@ scoped_ptr<Pickle> FastShowPickler::PickleAppListModelForFastShow(
return scoped_ptr<Pickle>();
if (!result->WriteBool(model->signed_in()))
return scoped_ptr<Pickle>();
- if (!result->WriteInt((int) model->apps()->item_count()))
+ // Write the number of pages.
+ size_t page_count = model->GetNumAppPages();
+ if (!result->WriteInt(static_cast<int>(page_count)))
return scoped_ptr<Pickle>();
- for (size_t i = 0; i < model->apps()->item_count(); ++i) {
- if (!PickleAppListItemModel(result.get(), model->apps()->GetItemAt(i)))
+ for (size_t p = 0; p < page_count; ++p) {
+ // Write the number of items in the page.
+ size_t item_count = model->GetAppItemsForPage(p).item_count();
+ if (!result->WriteInt(static_cast<int>(item_count)))
return scoped_ptr<Pickle>();
+ // Write the items in the page.
+ for (size_t i = 0; i < item_count; ++i) {
+ if (!PickleAppListItemModel(result.get(), model->GetItemAt(p, i)))
+ return scoped_ptr<Pickle>();
+ }
}
return result.Pass();
}
-void FastShowPickler::CopyOver(AppListModel* src, AppListModel* dest) {
- dest->apps()->DeleteAll();
+// static
+void FastShowPickler::CopyAppListModel(const AppListModel* src,
+ AppListModel* dest) {
+ CHECK_EQ(0u, dest->GetNumAppPages());
dest->SetSignedIn(src->signed_in());
- for (size_t i = 0; i < src->apps()->item_count(); i++) {
- AppListItemModel* src_item = src->apps()->GetItemAt(i);
- AppListItemModel* dest_item = new AppListItemModel(src_item->id());
- CopyOverItem(src_item, dest_item);
- dest->apps()->Add(dest_item);
+ for (size_t p = 0; p < src->GetNumAppPages(); ++p) {
+ const AppListModel::AppItems& apps = src->GetAppItemsForPage(p);
+ for (size_t i = 0; i < apps.item_count(); ++i) {
+ const AppListItemModel* src_item = apps.GetItemAt(i);
+ AppListItemModel* dest_item = new AppListItemModel(src_item->id());
+ CopyAppListItemModel(src_item, dest_item);
+ dest->AddItem(dest_item);
+ }
}
}
+// static
scoped_ptr<AppListModel>
FastShowPickler::UnpickleAppListModelForFastShow(Pickle* pickle) {
PickleIterator it(*pickle);
@@ -235,20 +252,27 @@ FastShowPickler::UnpickleAppListModelForFastShow(Pickle* pickle) {
return scoped_ptr<AppListModel>();
if (read_version != kVersion)
return scoped_ptr<AppListModel>();
- int app_count = 0;
bool signed_in = false;
if (!it.ReadBool(&signed_in))
return scoped_ptr<AppListModel>();
- if (!it.ReadInt(&app_count))
+ // Read the number of pages.
+ int page_count = 0;
+ if (!it.ReadInt(&page_count))
return scoped_ptr<AppListModel>();
-
scoped_ptr<AppListModel> model(new AppListModel);
model->SetSignedIn(signed_in);
- for (int i = 0; i < app_count; ++i) {
- scoped_ptr<AppListItemModel> item(UnpickleAppListItemModel(&it).Pass());
- if (!item)
+ for (size_t p = 0; p < static_cast<size_t>(page_count); ++p) {
+ // Read the number of items in the page.
+ int item_count = 0;
+ if (!it.ReadInt(&item_count))
return scoped_ptr<AppListModel>();
- model->apps()->Add(item.release());
+ // Read each item in the page.
+ for (int i = 0; i < item_count; ++i) {
+ scoped_ptr<AppListItemModel> item(UnpickleAppListItemModel(&it).Pass());
+ if (!item)
+ return scoped_ptr<AppListModel>();
+ model->AddItemToPage(item.release(), p);
+ }
}
return model.Pass();

Powered by Google App Engine
This is Rietveld 408576698