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

Side by Side Diff: chrome/browser/themes/browser_theme_pack.cc

Issue 10854074: Fixes memory alignment issues due to browser_theme_pack changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/themes/browser_theme_pack.h" 5 #include "chrome/browser/themes/browser_theme_pack.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/memory/ref_counted_memory.h" 9 #include "base/memory/ref_counted_memory.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 int prs_id = kPersistingImages[i].persistent_id; 181 int prs_id = kPersistingImages[i].persistent_id;
182 (*lookup_table)[idr] = prs_id; 182 (*lookup_table)[idr] = prs_id;
183 } 183 }
184 } 184 }
185 std::map<int,int>::iterator it = lookup_table->find(idr); 185 std::map<int,int>::iterator it = lookup_table->find(idr);
186 return (it == lookup_table->end()) ? -1 : it->second; 186 return (it == lookup_table->end()) ? -1 : it->second;
187 } 187 }
188 188
189 // Returns true if the scales in |input| match those in |expected|. 189 // Returns true if the scales in |input| match those in |expected|.
190 // The order must match as the index is used in determining the raw id. 190 // The order must match as the index is used in determining the raw id.
191 bool InputScalesValid(const char* input, 191 bool InputScalesValid(const base::StringPiece& input,
192 const std::vector<ui::ScaleFactor>& expected) { 192 const std::vector<ui::ScaleFactor>& expected) {
193 const float* scales = reinterpret_cast<const float*>(input); 193 size_t scales_size = static_cast<size_t>(
194 input.size() * sizeof(char) / sizeof(float));
benrg 2012/08/09 21:45:10 Either don't multiply by sizeof(char) here or else
195 float* scales = new float[scales_size];
sky 2012/08/09 19:49:17 scoped_array here and 211 (200/202 leak the way yo
benrg 2012/08/09 21:45:10 I think there should be a comment explaining why t
196 memcpy(scales, input.data(), input.size());
194 size_t index = 0; 197 size_t index = 0;
195 for (const float* end = scales; *end != -1.0f; ++end) { 198 for (; index < scales_size; ++index) {
196 if (index >= expected.size()) 199 if (index >= expected.size())
benrg 2012/08/09 21:45:10 It would be slightly simpler to check scales_size
197 return false; 200 return false;
198 if (*end != ui::GetScaleFactorScale(expected[index])) 201 if (scales[index] != ui::GetScaleFactorScale(expected[index]))
199 return false; 202 return false;
200 index++;
201 } 203 }
204 delete[] scales;
202 return (index == expected.size()); 205 return (index == expected.size());
203 } 206 }
204 207
205 // Returns |scale_factors| as a string to be written to disk. 208 // Returns |scale_factors| as a string to be written to disk.
206 std::string GetScaleFactorsAsString( 209 std::string GetScaleFactorsAsString(
207 const std::vector<ui::ScaleFactor>& scale_factors) { 210 const std::vector<ui::ScaleFactor>& scale_factors) {
208 size_t scales_size = scale_factors.size() + 1; 211 float* scales = new float[scale_factors.size()];
209 float* scales = new float[scales_size];
210 for (size_t i = 0; i < scale_factors.size(); ++i) 212 for (size_t i = 0; i < scale_factors.size(); ++i)
211 scales[i] = ui::GetScaleFactorScale(scale_factors[i]); 213 scales[i] = ui::GetScaleFactorScale(scale_factors[i]);
212 scales[scales_size - 1] = -1.0f;
213 std::string out_string = std::string( 214 std::string out_string = std::string(
214 reinterpret_cast<const char*>(scales), 215 reinterpret_cast<const char*>(scales),
215 scales_size * sizeof(float)); 216 scale_factors.size() * sizeof(float));
216 delete[] scales; 217 delete[] scales;
217 return out_string; 218 return out_string;
218 } 219 }
219 220
220 struct StringToIntTable { 221 struct StringToIntTable {
221 const char* key; 222 const char* key;
222 int id; 223 int id;
223 }; 224 };
224 225
225 // Strings used by themes to identify tints in the JSON. 226 // Strings used by themes to identify tints in the JSON.
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 const_cast<char*>(pointer.data())); 502 const_cast<char*>(pointer.data()));
502 503
503 if (!pack->data_pack_->GetStringPiece(kSourceImagesID, &pointer)) 504 if (!pack->data_pack_->GetStringPiece(kSourceImagesID, &pointer))
504 return NULL; 505 return NULL;
505 pack->source_images_ = reinterpret_cast<int*>( 506 pack->source_images_ = reinterpret_cast<int*>(
506 const_cast<char*>(pointer.data())); 507 const_cast<char*>(pointer.data()));
507 508
508 if (!pack->data_pack_->GetStringPiece(kScaleFactorsID, &pointer)) 509 if (!pack->data_pack_->GetStringPiece(kScaleFactorsID, &pointer))
509 return NULL; 510 return NULL;
510 511
511 if (!InputScalesValid(const_cast<char*>(pointer.data()), 512 if (!InputScalesValid(pointer, pack->scale_factors_)) {
512 pack->scale_factors_)) {
513 DLOG(ERROR) << "BuildFromDataPack failure! The pack scale factors differ " 513 DLOG(ERROR) << "BuildFromDataPack failure! The pack scale factors differ "
514 << "from those supported by platform."; 514 << "from those supported by platform.";
515 } 515 }
516
517 return pack; 516 return pack;
518 } 517 }
519 518
520 bool BrowserThemePack::WriteToDisk(const FilePath& path) const { 519 bool BrowserThemePack::WriteToDisk(const FilePath& path) const {
521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
522 // Add resources for each of the property arrays. 521 // Add resources for each of the property arrays.
523 RawDataForWriting resources; 522 RawDataForWriting resources;
524 resources[kHeaderID] = base::StringPiece( 523 resources[kHeaderID] = base::StringPiece(
525 reinterpret_cast<const char*>(header_), sizeof(BrowserThemePackHeader)); 524 reinterpret_cast<const char*>(header_), sizeof(BrowserThemePackHeader));
526 resources[kTintsID] = base::StringPiece( 525 resources[kTintsID] = base::StringPiece(
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 ui::ScaleFactor scale_factor) const { 1231 ui::ScaleFactor scale_factor) const {
1233 if (prs_id < 0) 1232 if (prs_id < 0)
1234 return -1; 1233 return -1;
1235 1234
1236 for (size_t i = 0; i < scale_factors_.size(); ++i) { 1235 for (size_t i = 0; i < scale_factors_.size(); ++i) {
1237 if (scale_factors_[i] == scale_factor) 1236 if (scale_factors_[i] == scale_factor)
1238 return static_cast<int>(kPersistingImagesLength * i) + prs_id; 1237 return static_cast<int>(kPersistingImagesLength * i) + prs_id;
1239 } 1238 }
1240 return -1; 1239 return -1;
1241 } 1240 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698