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 #include <utility> |
9 | 9 |
10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 memcpy(bitmap.getPixels(), pixels, bitmap.getSize()); | 142 memcpy(bitmap.getPixels(), pixels, bitmap.getSize()); |
143 result.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale)); | 143 result.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale)); |
144 } | 144 } |
145 | 145 |
146 *out = result; | 146 *out = result; |
147 return true; | 147 return true; |
148 } | 148 } |
149 | 149 |
150 } // namespace | 150 } // namespace |
151 | 151 |
152 scoped_ptr<AppListItem> FastShowPickler::UnpickleAppListItem( | 152 std::unique_ptr<AppListItem> FastShowPickler::UnpickleAppListItem( |
153 base::PickleIterator* it) { | 153 base::PickleIterator* it) { |
154 std::string id; | 154 std::string id; |
155 if (!it->ReadString(&id)) | 155 if (!it->ReadString(&id)) |
156 return scoped_ptr<AppListItem>(); | 156 return std::unique_ptr<AppListItem>(); |
157 scoped_ptr<AppListItem> result(new AppListItem(id)); | 157 std::unique_ptr<AppListItem> result(new AppListItem(id)); |
158 std::string name; | 158 std::string name; |
159 if (!it->ReadString(&name)) | 159 if (!it->ReadString(&name)) |
160 return scoped_ptr<AppListItem>(); | 160 return std::unique_ptr<AppListItem>(); |
161 std::string short_name; | 161 std::string short_name; |
162 if (!it->ReadString(&short_name)) | 162 if (!it->ReadString(&short_name)) |
163 return scoped_ptr<AppListItem>(); | 163 return std::unique_ptr<AppListItem>(); |
164 result->SetNameAndShortName(name, short_name); | 164 result->SetNameAndShortName(name, short_name); |
165 gfx::ImageSkia icon; | 165 gfx::ImageSkia icon; |
166 if (!UnpickleImage(it, &icon)) | 166 if (!UnpickleImage(it, &icon)) |
167 return scoped_ptr<AppListItem>(); | 167 return std::unique_ptr<AppListItem>(); |
168 result->SetIcon(icon); | 168 result->SetIcon(icon); |
169 return result; | 169 return result; |
170 } | 170 } |
171 | 171 |
172 bool FastShowPickler::PickleAppListItem(base::Pickle* pickle, | 172 bool FastShowPickler::PickleAppListItem(base::Pickle* pickle, |
173 AppListItem* item) { | 173 AppListItem* item) { |
174 if (!pickle->WriteString(item->id())) | 174 if (!pickle->WriteString(item->id())) |
175 return false; | 175 return false; |
176 if (!pickle->WriteString(item->name())) | 176 if (!pickle->WriteString(item->name())) |
177 return false; | 177 return false; |
178 if (!pickle->WriteString(item->short_name())) | 178 if (!pickle->WriteString(item->short_name())) |
179 return false; | 179 return false; |
180 if (!PickleImage(pickle, item->icon())) | 180 if (!PickleImage(pickle, item->icon())) |
181 return false; | 181 return false; |
182 return true; | 182 return true; |
183 } | 183 } |
184 | 184 |
185 void FastShowPickler::CopyOverItem(AppListItem* src_item, | 185 void FastShowPickler::CopyOverItem(AppListItem* src_item, |
186 AppListItem* dest_item) { | 186 AppListItem* dest_item) { |
187 dest_item->SetNameAndShortName(src_item->name(), src_item->short_name()); | 187 dest_item->SetNameAndShortName(src_item->name(), src_item->short_name()); |
188 dest_item->SetIcon(src_item->icon()); | 188 dest_item->SetIcon(src_item->icon()); |
189 // Do not set folder_id, pass that to AppListModel::AddItemToFolder() instead. | 189 // Do not set folder_id, pass that to AppListModel::AddItemToFolder() instead. |
190 } | 190 } |
191 | 191 |
192 // The version of the pickle format defined here. This needs to be incremented | 192 // The version of the pickle format defined here. This needs to be incremented |
193 // whenever this format is changed so new clients can invalidate old versions. | 193 // whenever this format is changed so new clients can invalidate old versions. |
194 const int FastShowPickler::kVersion = 4; | 194 const int FastShowPickler::kVersion = 4; |
195 | 195 |
196 scoped_ptr<base::Pickle> FastShowPickler::PickleAppListModelForFastShow( | 196 std::unique_ptr<base::Pickle> FastShowPickler::PickleAppListModelForFastShow( |
197 AppListModel* model) { | 197 AppListModel* model) { |
198 scoped_ptr<base::Pickle> result(new base::Pickle); | 198 std::unique_ptr<base::Pickle> result(new base::Pickle); |
199 if (!result->WriteInt(kVersion)) | 199 if (!result->WriteInt(kVersion)) |
200 return scoped_ptr<base::Pickle>(); | 200 return std::unique_ptr<base::Pickle>(); |
201 if (!result->WriteInt((int)model->top_level_item_list()->item_count())) | 201 if (!result->WriteInt((int)model->top_level_item_list()->item_count())) |
202 return scoped_ptr<base::Pickle>(); | 202 return std::unique_ptr<base::Pickle>(); |
203 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) { |
204 if (!PickleAppListItem(result.get(), | 204 if (!PickleAppListItem(result.get(), |
205 model->top_level_item_list()->item_at(i))) { | 205 model->top_level_item_list()->item_at(i))) { |
206 return scoped_ptr<base::Pickle>(); | 206 return std::unique_ptr<base::Pickle>(); |
207 } | 207 } |
208 } | 208 } |
209 return result; | 209 return result; |
210 } | 210 } |
211 | 211 |
212 void FastShowPickler::CopyOver(AppListModel* src, AppListModel* dest) { | 212 void FastShowPickler::CopyOver(AppListModel* src, AppListModel* dest) { |
213 DCHECK_EQ(0u, dest->top_level_item_list()->item_count()); | 213 DCHECK_EQ(0u, dest->top_level_item_list()->item_count()); |
214 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++) { |
215 AppListItem* src_item = src->top_level_item_list()->item_at(i); | 215 AppListItem* src_item = src->top_level_item_list()->item_at(i); |
216 scoped_ptr<AppListItem> dest_item(new AppListItem(src_item->id())); | 216 std::unique_ptr<AppListItem> dest_item(new AppListItem(src_item->id())); |
217 CopyOverItem(src_item, dest_item.get()); | 217 CopyOverItem(src_item, dest_item.get()); |
218 dest->AddItemToFolder(std::move(dest_item), src_item->folder_id()); | 218 dest->AddItemToFolder(std::move(dest_item), src_item->folder_id()); |
219 } | 219 } |
220 } | 220 } |
221 | 221 |
222 scoped_ptr<AppListModel> FastShowPickler::UnpickleAppListModelForFastShow( | 222 std::unique_ptr<AppListModel> FastShowPickler::UnpickleAppListModelForFastShow( |
223 base::Pickle* pickle) { | 223 base::Pickle* pickle) { |
224 base::PickleIterator it(*pickle); | 224 base::PickleIterator it(*pickle); |
225 int read_version = 0; | 225 int read_version = 0; |
226 if (!it.ReadInt(&read_version)) | 226 if (!it.ReadInt(&read_version)) |
227 return scoped_ptr<AppListModel>(); | 227 return std::unique_ptr<AppListModel>(); |
228 if (read_version != kVersion) | 228 if (read_version != kVersion) |
229 return scoped_ptr<AppListModel>(); | 229 return std::unique_ptr<AppListModel>(); |
230 int app_count = 0; | 230 int app_count = 0; |
231 if (!it.ReadInt(&app_count)) | 231 if (!it.ReadInt(&app_count)) |
232 return scoped_ptr<AppListModel>(); | 232 return std::unique_ptr<AppListModel>(); |
233 | 233 |
234 scoped_ptr<AppListModel> model(new AppListModel); | 234 std::unique_ptr<AppListModel> model(new AppListModel); |
235 for (int i = 0; i < app_count; ++i) { | 235 for (int i = 0; i < app_count; ++i) { |
236 scoped_ptr<AppListItem> item(UnpickleAppListItem(&it)); | 236 std::unique_ptr<AppListItem> item(UnpickleAppListItem(&it)); |
237 if (!item) | 237 if (!item) |
238 return scoped_ptr<AppListModel>(); | 238 return std::unique_ptr<AppListModel>(); |
239 std::string folder_id = item->folder_id(); | 239 std::string folder_id = item->folder_id(); |
240 model->AddItemToFolder(std::move(item), folder_id); | 240 model->AddItemToFolder(std::move(item), folder_id); |
241 } | 241 } |
242 | 242 |
243 return model; | 243 return model; |
244 } | 244 } |
OLD | NEW |