| OLD | NEW |
| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 if (!it->ReadString(&id)) | 152 if (!it->ReadString(&id)) |
| 153 return scoped_ptr<AppListItem>(); | 153 return scoped_ptr<AppListItem>(); |
| 154 scoped_ptr<AppListItem> result(new AppListItem(id)); | 154 scoped_ptr<AppListItem> result(new AppListItem(id)); |
| 155 std::string name; | 155 std::string name; |
| 156 if (!it->ReadString(&name)) | 156 if (!it->ReadString(&name)) |
| 157 return scoped_ptr<AppListItem>(); | 157 return scoped_ptr<AppListItem>(); |
| 158 std::string short_name; | 158 std::string short_name; |
| 159 if (!it->ReadString(&short_name)) | 159 if (!it->ReadString(&short_name)) |
| 160 return scoped_ptr<AppListItem>(); | 160 return scoped_ptr<AppListItem>(); |
| 161 result->SetNameAndShortName(name, short_name); | 161 result->SetNameAndShortName(name, short_name); |
| 162 bool has_shadow = false; | |
| 163 if (!it->ReadBool(&has_shadow)) | |
| 164 return scoped_ptr<AppListItem>(); | |
| 165 gfx::ImageSkia icon; | 162 gfx::ImageSkia icon; |
| 166 if (!UnpickleImage(it, &icon)) | 163 if (!UnpickleImage(it, &icon)) |
| 167 return scoped_ptr<AppListItem>(); | 164 return scoped_ptr<AppListItem>(); |
| 168 result->SetIcon(icon, has_shadow); | 165 result->SetIcon(icon); |
| 169 return result.Pass(); | 166 return result.Pass(); |
| 170 } | 167 } |
| 171 | 168 |
| 172 bool FastShowPickler::PickleAppListItem(Pickle* pickle, AppListItem* item) { | 169 bool FastShowPickler::PickleAppListItem(Pickle* pickle, AppListItem* item) { |
| 173 if (!pickle->WriteString(item->id())) | 170 if (!pickle->WriteString(item->id())) |
| 174 return false; | 171 return false; |
| 175 if (!pickle->WriteString(item->name())) | 172 if (!pickle->WriteString(item->name())) |
| 176 return false; | 173 return false; |
| 177 if (!pickle->WriteString(item->short_name())) | 174 if (!pickle->WriteString(item->short_name())) |
| 178 return false; | 175 return false; |
| 179 if (!pickle->WriteBool(item->has_shadow())) | |
| 180 return false; | |
| 181 if (!PickleImage(pickle, item->icon())) | 176 if (!PickleImage(pickle, item->icon())) |
| 182 return false; | 177 return false; |
| 183 return true; | 178 return true; |
| 184 } | 179 } |
| 185 | 180 |
| 186 void FastShowPickler::CopyOverItem(AppListItem* src_item, | 181 void FastShowPickler::CopyOverItem(AppListItem* src_item, |
| 187 AppListItem* dest_item) { | 182 AppListItem* dest_item) { |
| 188 dest_item->SetNameAndShortName(src_item->name(), src_item->short_name()); | 183 dest_item->SetNameAndShortName(src_item->name(), src_item->short_name()); |
| 189 dest_item->SetIcon(src_item->icon(), src_item->has_shadow()); | 184 dest_item->SetIcon(src_item->icon()); |
| 190 // Do not set folder_id, pass that to AppListModel::AddItemToFolder() instead. | 185 // Do not set folder_id, pass that to AppListModel::AddItemToFolder() instead. |
| 191 } | 186 } |
| 192 | 187 |
| 193 // The version of the pickle format defined here. This needs to be incremented | 188 // The version of the pickle format defined here. This needs to be incremented |
| 194 // whenever this format is changed so new clients can invalidate old versions. | 189 // whenever this format is changed so new clients can invalidate old versions. |
| 195 const int FastShowPickler::kVersion = 3; | 190 const int FastShowPickler::kVersion = 4; |
| 196 | 191 |
| 197 scoped_ptr<Pickle> FastShowPickler::PickleAppListModelForFastShow( | 192 scoped_ptr<Pickle> FastShowPickler::PickleAppListModelForFastShow( |
| 198 AppListModel* model) { | 193 AppListModel* model) { |
| 199 scoped_ptr<Pickle> result(new Pickle); | 194 scoped_ptr<Pickle> result(new Pickle); |
| 200 if (!result->WriteInt(kVersion)) | 195 if (!result->WriteInt(kVersion)) |
| 201 return scoped_ptr<Pickle>(); | 196 return scoped_ptr<Pickle>(); |
| 202 if (!result->WriteInt((int)model->top_level_item_list()->item_count())) | 197 if (!result->WriteInt((int)model->top_level_item_list()->item_count())) |
| 203 return scoped_ptr<Pickle>(); | 198 return scoped_ptr<Pickle>(); |
| 204 for (size_t i = 0; i < model->top_level_item_list()->item_count(); ++i) { | 199 for (size_t i = 0; i < model->top_level_item_list()->item_count(); ++i) { |
| 205 if (!PickleAppListItem(result.get(), | 200 if (!PickleAppListItem(result.get(), |
| (...skipping 30 matching lines...) Expand all Loading... |
| 236 for (int i = 0; i < app_count; ++i) { | 231 for (int i = 0; i < app_count; ++i) { |
| 237 scoped_ptr<AppListItem> item(UnpickleAppListItem(&it).Pass()); | 232 scoped_ptr<AppListItem> item(UnpickleAppListItem(&it).Pass()); |
| 238 if (!item) | 233 if (!item) |
| 239 return scoped_ptr<AppListModel>(); | 234 return scoped_ptr<AppListModel>(); |
| 240 std::string folder_id = item->folder_id(); | 235 std::string folder_id = item->folder_id(); |
| 241 model->AddItemToFolder(item.Pass(), folder_id); | 236 model->AddItemToFolder(item.Pass(), folder_id); |
| 242 } | 237 } |
| 243 | 238 |
| 244 return model.Pass(); | 239 return model.Pass(); |
| 245 } | 240 } |
| OLD | NEW |