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

Side by Side Diff: chrome/browser/extensions/convert_web_app.cc

Issue 141113003: Refactor base/safe_numerics.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 11 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 (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/extensions/convert_web_app.h" 5 #include "chrome/browser/extensions/convert_web_app.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/base64.h" 12 #include "base/base64.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/files/scoped_temp_dir.h" 15 #include "base/files/scoped_temp_dir.h"
16 #include "base/json/json_file_value_serializer.h" 16 #include "base/json/json_file_value_serializer.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/numerics/safe_conversions.h"
18 #include "base/path_service.h" 19 #include "base/path_service.h"
19 #include "base/safe_numerics.h"
20 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
22 #include "base/time/time.h" 22 #include "base/time/time.h"
23 #include "chrome/common/chrome_paths.h" 23 #include "chrome/common/chrome_paths.h"
24 #include "chrome/common/extensions/extension_file_util.h" 24 #include "chrome/common/extensions/extension_file_util.h"
25 #include "chrome/common/web_application_info.h" 25 #include "chrome/common/web_application_info.h"
26 #include "crypto/sha2.h" 26 #include "crypto/sha2.h"
27 #include "extensions/common/constants.h" 27 #include "extensions/common/constants.h"
28 #include "extensions/common/extension.h" 28 #include "extensions/common/extension.h"
29 #include "extensions/common/manifest_constants.h" 29 #include "extensions/common/manifest_constants.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 base::StringPrintf("%i.png", web_app.icons[i].width)); 166 base::StringPrintf("%i.png", web_app.icons[i].width));
167 std::vector<unsigned char> image_data; 167 std::vector<unsigned char> image_data;
168 if (!gfx::PNGCodec::EncodeBGRASkBitmap(web_app.icons[i].data, 168 if (!gfx::PNGCodec::EncodeBGRASkBitmap(web_app.icons[i].data,
169 false, 169 false,
170 &image_data)) { 170 &image_data)) {
171 LOG(ERROR) << "Could not create icon file."; 171 LOG(ERROR) << "Could not create icon file.";
172 return NULL; 172 return NULL;
173 } 173 }
174 174
175 const char* image_data_ptr = reinterpret_cast<const char*>(&image_data[0]); 175 const char* image_data_ptr = reinterpret_cast<const char*>(&image_data[0]);
176 int size = base::checked_numeric_cast<int>(image_data.size()); 176 int size = base::checked_cast<int>(image_data.size());
177 if (file_util::WriteFile(icon_file, image_data_ptr, size) != size) { 177 if (file_util::WriteFile(icon_file, image_data_ptr, size) != size) {
178 LOG(ERROR) << "Could not write icon file."; 178 LOG(ERROR) << "Could not write icon file.";
179 return NULL; 179 return NULL;
180 } 180 }
181 } 181 }
182 182
183 // Finally, create the extension object to represent the unpacked directory. 183 // Finally, create the extension object to represent the unpacked directory.
184 std::string error; 184 std::string error;
185 int extension_flags = Extension::NO_FLAGS; 185 int extension_flags = Extension::NO_FLAGS;
186 if (web_app.is_bookmark_app) 186 if (web_app.is_bookmark_app)
187 extension_flags |= Extension::FROM_BOOKMARK; 187 extension_flags |= Extension::FROM_BOOKMARK;
188 scoped_refptr<Extension> extension = Extension::Create( 188 scoped_refptr<Extension> extension = Extension::Create(
189 temp_dir.path(), 189 temp_dir.path(),
190 Manifest::INTERNAL, 190 Manifest::INTERNAL,
191 *root, 191 *root,
192 extension_flags, 192 extension_flags,
193 &error); 193 &error);
194 if (!extension.get()) { 194 if (!extension.get()) {
195 LOG(ERROR) << error; 195 LOG(ERROR) << error;
196 return NULL; 196 return NULL;
197 } 197 }
198 198
199 temp_dir.Take(); // The caller takes ownership of the directory. 199 temp_dir.Take(); // The caller takes ownership of the directory.
200 return extension; 200 return extension;
201 } 201 }
202 202
203 } // namespace extensions 203 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698