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

Side by Side Diff: chrome/browser/ui/app_list/fast_show_pickler.cc

Issue 24707002: Add unit tests for AppListServiceImpl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: un-const an iterator 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/base/layout.h"
10 #include "ui/gfx/image/image_skia_rep.h" 9 #include "ui/gfx/image/image_skia_rep.h"
11 10
12 namespace { 11 namespace {
13 12
14 using app_list::AppListItemModel; 13 using app_list::AppListItemModel;
15 using app_list::AppListModel; 14 using app_list::AppListModel;
16 15
17 // These have the same meaning as SkBitmap::Config. Reproduced here to insure 16 // These have the same meaning as SkBitmap::Config. Reproduced here to insure
18 // against their value changing in Skia. If the order of these changes kVersion 17 // against their value changing in Skia. If the order of these changes kVersion
19 // should be incremented. 18 // should be incremented.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 default: return false; 80 default: return false;
82 } 81 }
83 return true; 82 return true;
84 } 83 }
85 84
86 bool PickleImage(Pickle* pickle, const gfx::ImageSkia& image) { 85 bool PickleImage(Pickle* pickle, const gfx::ImageSkia& image) {
87 std::vector<gfx::ImageSkiaRep> reps(image.image_reps()); 86 std::vector<gfx::ImageSkiaRep> reps(image.image_reps());
88 pickle->WriteInt(static_cast<int>(reps.size())); 87 pickle->WriteInt(static_cast<int>(reps.size()));
89 for (std::vector<gfx::ImageSkiaRep>::const_iterator it = reps.begin(); 88 for (std::vector<gfx::ImageSkiaRep>::const_iterator it = reps.begin();
90 it != reps.end(); ++it) { 89 it != reps.end(); ++it) {
91 pickle->WriteInt(static_cast<int>(ui::GetSupportedScaleFactor(it->scale()))) ; 90 pickle->WriteFloat(it->scale());
92 pickle->WriteInt(it->pixel_width()); 91 pickle->WriteInt(it->pixel_width());
93 pickle->WriteInt(it->pixel_height()); 92 pickle->WriteInt(it->pixel_height());
94 ImageFormat format = NONE; 93 ImageFormat format = NONE;
95 if (!ConfigToFormat(it->sk_bitmap().getConfig(), &format)) 94 if (!ConfigToFormat(it->sk_bitmap().getConfig(), &format))
96 return false; 95 return false;
97 pickle->WriteInt(static_cast<int>(format)); 96 pickle->WriteInt(static_cast<int>(format));
98 int size = static_cast<int>(it->sk_bitmap().getSafeSize()); 97 int size = static_cast<int>(it->sk_bitmap().getSafeSize());
99 pickle->WriteInt(size); 98 pickle->WriteInt(size);
100 SkBitmap bitmap = it->sk_bitmap(); 99 SkBitmap bitmap = it->sk_bitmap();
101 SkAutoLockPixels lock(bitmap); 100 SkAutoLockPixels lock(bitmap);
102 pickle->WriteBytes(bitmap.getPixels(), size); 101 pickle->WriteBytes(bitmap.getPixels(), size);
103 } 102 }
104 return true; 103 return true;
105 } 104 }
106 105
107 bool UnpickleImage(PickleIterator* it, gfx::ImageSkia* out) { 106 bool UnpickleImage(PickleIterator* it, gfx::ImageSkia* out) {
108 int rep_count = 0; 107 int rep_count = 0;
109 if (!it->ReadInt(&rep_count)) 108 if (!it->ReadInt(&rep_count))
110 return false; 109 return false;
111 110
112 gfx::ImageSkia result; 111 gfx::ImageSkia result;
113 for (int i = 0; i < rep_count; ++i) { 112 for (int i = 0; i < rep_count; ++i) {
114 int scale_factor = 0; 113 float scale = 0.0f;
115 if (!it->ReadInt(&scale_factor)) 114 if (!it->ReadFloat(&scale))
116 return false; 115 return false;
117 116
118 int width = 0; 117 int width = 0;
119 if (!it->ReadInt(&width)) 118 if (!it->ReadInt(&width))
120 return false; 119 return false;
121 120
122 int height = 0; 121 int height = 0;
123 if (!it->ReadInt(&height)) 122 if (!it->ReadInt(&height))
124 return false; 123 return false;
125 124
(...skipping 14 matching lines...) Expand all
140 return false; 139 return false;
141 140
142 SkBitmap bitmap; 141 SkBitmap bitmap;
143 bitmap.setConfig(static_cast<SkBitmap::Config>(config), width, height); 142 bitmap.setConfig(static_cast<SkBitmap::Config>(config), width, height);
144 if (!bitmap.allocPixels()) 143 if (!bitmap.allocPixels())
145 return false; 144 return false;
146 { 145 {
147 SkAutoLockPixels lock(bitmap); 146 SkAutoLockPixels lock(bitmap);
148 memcpy(bitmap.getPixels(), pixels, bitmap.getSize()); 147 memcpy(bitmap.getPixels(), pixels, bitmap.getSize());
149 } 148 }
150 float scale = ui::GetImageScale(static_cast<ui::ScaleFactor>(scale_factor));
151 result.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale)); 149 result.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale));
152 } 150 }
153 151
154 *out = result; 152 *out = result;
155 return true; 153 return true;
156 } 154 }
157 155
158 scoped_ptr<AppListItemModel> UnpickleAppListItemModel(PickleIterator* it) { 156 scoped_ptr<AppListItemModel> UnpickleAppListItemModel(PickleIterator* it) {
159 scoped_ptr<AppListItemModel> result(new AppListItemModel); 157 scoped_ptr<AppListItemModel> result(new AppListItemModel);
160 std::string id; 158 std::string id;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 model->SetSignedIn(signed_in); 248 model->SetSignedIn(signed_in);
251 for (int i = 0; i < app_count; ++i) { 249 for (int i = 0; i < app_count; ++i) {
252 scoped_ptr<AppListItemModel> item(UnpickleAppListItemModel(&it).Pass()); 250 scoped_ptr<AppListItemModel> item(UnpickleAppListItemModel(&it).Pass());
253 if (!item) 251 if (!item)
254 return scoped_ptr<AppListModel>(); 252 return scoped_ptr<AppListModel>();
255 model->apps()->Add(item.release()); 253 model->apps()->Add(item.release());
256 } 254 }
257 255
258 return model.Pass(); 256 return model.Pass();
259 } 257 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/app_list_service_unittest.cc ('k') | chrome/browser/ui/app_list/keep_alive_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698