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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> |
8 | 9 |
9 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
10 #include "ui/app_list/app_list_item.h" | 11 #include "ui/app_list/app_list_item.h" |
11 #include "ui/gfx/image/image_skia_rep.h" | 12 #include "ui/gfx/image/image_skia_rep.h" |
12 | 13 |
13 namespace { | 14 namespace { |
14 | 15 |
15 using app_list::AppListItem; | 16 using app_list::AppListItem; |
16 using app_list::AppListModel; | 17 using app_list::AppListModel; |
17 | 18 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 if (!it->ReadString(&name)) | 159 if (!it->ReadString(&name)) |
159 return scoped_ptr<AppListItem>(); | 160 return scoped_ptr<AppListItem>(); |
160 std::string short_name; | 161 std::string short_name; |
161 if (!it->ReadString(&short_name)) | 162 if (!it->ReadString(&short_name)) |
162 return scoped_ptr<AppListItem>(); | 163 return scoped_ptr<AppListItem>(); |
163 result->SetNameAndShortName(name, short_name); | 164 result->SetNameAndShortName(name, short_name); |
164 gfx::ImageSkia icon; | 165 gfx::ImageSkia icon; |
165 if (!UnpickleImage(it, &icon)) | 166 if (!UnpickleImage(it, &icon)) |
166 return scoped_ptr<AppListItem>(); | 167 return scoped_ptr<AppListItem>(); |
167 result->SetIcon(icon); | 168 result->SetIcon(icon); |
168 return result.Pass(); | 169 return result; |
169 } | 170 } |
170 | 171 |
171 bool FastShowPickler::PickleAppListItem(base::Pickle* pickle, | 172 bool FastShowPickler::PickleAppListItem(base::Pickle* pickle, |
172 AppListItem* item) { | 173 AppListItem* item) { |
173 if (!pickle->WriteString(item->id())) | 174 if (!pickle->WriteString(item->id())) |
174 return false; | 175 return false; |
175 if (!pickle->WriteString(item->name())) | 176 if (!pickle->WriteString(item->name())) |
176 return false; | 177 return false; |
177 if (!pickle->WriteString(item->short_name())) | 178 if (!pickle->WriteString(item->short_name())) |
178 return false; | 179 return false; |
(...skipping 19 matching lines...) Expand all Loading... |
198 if (!result->WriteInt(kVersion)) | 199 if (!result->WriteInt(kVersion)) |
199 return scoped_ptr<base::Pickle>(); | 200 return scoped_ptr<base::Pickle>(); |
200 if (!result->WriteInt((int)model->top_level_item_list()->item_count())) | 201 if (!result->WriteInt((int)model->top_level_item_list()->item_count())) |
201 return scoped_ptr<base::Pickle>(); | 202 return scoped_ptr<base::Pickle>(); |
202 for (size_t i = 0; i < model->top_level_item_list()->item_count(); ++i) { | 203 for (size_t i = 0; i < model->top_level_item_list()->item_count(); ++i) { |
203 if (!PickleAppListItem(result.get(), | 204 if (!PickleAppListItem(result.get(), |
204 model->top_level_item_list()->item_at(i))) { | 205 model->top_level_item_list()->item_at(i))) { |
205 return scoped_ptr<base::Pickle>(); | 206 return scoped_ptr<base::Pickle>(); |
206 } | 207 } |
207 } | 208 } |
208 return result.Pass(); | 209 return result; |
209 } | 210 } |
210 | 211 |
211 void FastShowPickler::CopyOver(AppListModel* src, AppListModel* dest) { | 212 void FastShowPickler::CopyOver(AppListModel* src, AppListModel* dest) { |
212 DCHECK_EQ(0u, dest->top_level_item_list()->item_count()); | 213 DCHECK_EQ(0u, dest->top_level_item_list()->item_count()); |
213 for (size_t i = 0; i < src->top_level_item_list()->item_count(); i++) { | 214 for (size_t i = 0; i < src->top_level_item_list()->item_count(); i++) { |
214 AppListItem* src_item = src->top_level_item_list()->item_at(i); | 215 AppListItem* src_item = src->top_level_item_list()->item_at(i); |
215 scoped_ptr<AppListItem> dest_item(new AppListItem(src_item->id())); | 216 scoped_ptr<AppListItem> dest_item(new AppListItem(src_item->id())); |
216 CopyOverItem(src_item, dest_item.get()); | 217 CopyOverItem(src_item, dest_item.get()); |
217 dest->AddItemToFolder(dest_item.Pass(), src_item->folder_id()); | 218 dest->AddItemToFolder(std::move(dest_item), src_item->folder_id()); |
218 } | 219 } |
219 } | 220 } |
220 | 221 |
221 scoped_ptr<AppListModel> FastShowPickler::UnpickleAppListModelForFastShow( | 222 scoped_ptr<AppListModel> FastShowPickler::UnpickleAppListModelForFastShow( |
222 base::Pickle* pickle) { | 223 base::Pickle* pickle) { |
223 base::PickleIterator it(*pickle); | 224 base::PickleIterator it(*pickle); |
224 int read_version = 0; | 225 int read_version = 0; |
225 if (!it.ReadInt(&read_version)) | 226 if (!it.ReadInt(&read_version)) |
226 return scoped_ptr<AppListModel>(); | 227 return scoped_ptr<AppListModel>(); |
227 if (read_version != kVersion) | 228 if (read_version != kVersion) |
228 return scoped_ptr<AppListModel>(); | 229 return scoped_ptr<AppListModel>(); |
229 int app_count = 0; | 230 int app_count = 0; |
230 if (!it.ReadInt(&app_count)) | 231 if (!it.ReadInt(&app_count)) |
231 return scoped_ptr<AppListModel>(); | 232 return scoped_ptr<AppListModel>(); |
232 | 233 |
233 scoped_ptr<AppListModel> model(new AppListModel); | 234 scoped_ptr<AppListModel> model(new AppListModel); |
234 for (int i = 0; i < app_count; ++i) { | 235 for (int i = 0; i < app_count; ++i) { |
235 scoped_ptr<AppListItem> item(UnpickleAppListItem(&it).Pass()); | 236 scoped_ptr<AppListItem> item(UnpickleAppListItem(&it)); |
236 if (!item) | 237 if (!item) |
237 return scoped_ptr<AppListModel>(); | 238 return scoped_ptr<AppListModel>(); |
238 std::string folder_id = item->folder_id(); | 239 std::string folder_id = item->folder_id(); |
239 model->AddItemToFolder(item.Pass(), folder_id); | 240 model->AddItemToFolder(std::move(item), folder_id); |
240 } | 241 } |
241 | 242 |
242 return model.Pass(); | 243 return model; |
243 } | 244 } |
OLD | NEW |