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

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

Issue 102873002: Move GetFileSize, NormalizeFilePath to base namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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/sandboxed_unpacker.h" 5 #include "chrome/browser/extensions/sandboxed_unpacker.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 const base::FilePath& crx_path, const base::TimeDelta unpack_time) { 65 const base::FilePath& crx_path, const base::TimeDelta unpack_time) {
66 66
67 const int64 kBytesPerKb = 1024; 67 const int64 kBytesPerKb = 1024;
68 const int64 kBytesPerMb = 1024 * 1024; 68 const int64 kBytesPerMb = 1024 * 1024;
69 69
70 UMA_HISTOGRAM_TIMES("Extensions.SandboxUnpackSuccessTime", unpack_time); 70 UMA_HISTOGRAM_TIMES("Extensions.SandboxUnpackSuccessTime", unpack_time);
71 71
72 // To get a sense of how CRX size impacts unpack time, record unpack 72 // To get a sense of how CRX size impacts unpack time, record unpack
73 // time for several increments of CRX size. 73 // time for several increments of CRX size.
74 int64 crx_file_size; 74 int64 crx_file_size;
75 if (!file_util::GetFileSize(crx_path, &crx_file_size)) { 75 if (!base::GetFileSize(crx_path, &crx_file_size)) {
76 UMA_HISTOGRAM_COUNTS("Extensions.SandboxUnpackSuccessCantGetCrxSize", 1); 76 UMA_HISTOGRAM_COUNTS("Extensions.SandboxUnpackSuccessCantGetCrxSize", 1);
77 return; 77 return;
78 } 78 }
79 79
80 // Cast is safe as long as the number of bytes in the CRX is less than 80 // Cast is safe as long as the number of bytes in the CRX is less than
81 // 2^31 * 2^10. 81 // 2^31 * 2^10.
82 int crx_file_size_kb = static_cast<int>(crx_file_size / kBytesPerKb); 82 int crx_file_size_kb = static_cast<int>(crx_file_size / kBytesPerKb);
83 UMA_HISTOGRAM_COUNTS( 83 UMA_HISTOGRAM_COUNTS(
84 "Extensions.SandboxUnpackSuccessCrxSize", crx_file_size_kb); 84 "Extensions.SandboxUnpackSuccessCrxSize", crx_file_size_kb);
85 85
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 LOG(ERROR) << temp_dir->value() << " is not writable"; 128 LOG(ERROR) << temp_dir->value() << " is not writable";
129 return false; 129 return false;
130 } 130 }
131 // NormalizeFilePath requires a non-empty file, so write some data. 131 // NormalizeFilePath requires a non-empty file, so write some data.
132 // If you change the exit points of this function please make sure all 132 // If you change the exit points of this function please make sure all
133 // exit points delete this temp file! 133 // exit points delete this temp file!
134 if (file_util::WriteFile(temp_file, ".", 1) != 1) 134 if (file_util::WriteFile(temp_file, ".", 1) != 1)
135 return false; 135 return false;
136 136
137 base::FilePath normalized_temp_file; 137 base::FilePath normalized_temp_file;
138 bool normalized = 138 bool normalized = base::NormalizeFilePath(temp_file, &normalized_temp_file);
139 file_util::NormalizeFilePath(temp_file, &normalized_temp_file);
140 if (!normalized) { 139 if (!normalized) {
141 // If |temp_file| contains a link, the sandbox will block al file system 140 // If |temp_file| contains a link, the sandbox will block al file system
142 // operations, and the install will fail. 141 // operations, and the install will fail.
143 LOG(ERROR) << temp_dir->value() << " seem to be on remote drive."; 142 LOG(ERROR) << temp_dir->value() << " seem to be on remote drive.";
144 } else { 143 } else {
145 *temp_dir = normalized_temp_file.DirName(); 144 *temp_dir = normalized_temp_file.DirName();
146 } 145 }
147 // Clean up the temp file. 146 // Clean up the temp file.
148 base::DeleteFile(temp_file, false); 147 base::DeleteFile(temp_file, false);
149 148
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 ASCIIToUTF16("FAILED_TO_COPY_EXTENSION_FILE_TO_TEMP_DIRECTORY"))); 285 ASCIIToUTF16("FAILED_TO_COPY_EXTENSION_FILE_TO_TEMP_DIRECTORY")));
287 return; 286 return;
288 } 287 }
289 288
290 // The utility process will have access to the directory passed to 289 // The utility process will have access to the directory passed to
291 // SandboxedUnpacker. That directory should not contain a symlink or NTFS 290 // SandboxedUnpacker. That directory should not contain a symlink or NTFS
292 // reparse point. When the path is used, following the link/reparse point 291 // reparse point. When the path is used, following the link/reparse point
293 // will cause file system access outside the sandbox path, and the sandbox 292 // will cause file system access outside the sandbox path, and the sandbox
294 // will deny the operation. 293 // will deny the operation.
295 base::FilePath link_free_crx_path; 294 base::FilePath link_free_crx_path;
296 if (!file_util::NormalizeFilePath(temp_crx_path, &link_free_crx_path)) { 295 if (!base::NormalizeFilePath(temp_crx_path, &link_free_crx_path)) {
297 LOG(ERROR) << "Could not get the normalized path of " 296 LOG(ERROR) << "Could not get the normalized path of "
298 << temp_crx_path.value(); 297 << temp_crx_path.value();
299 ReportFailure( 298 ReportFailure(
300 COULD_NOT_GET_SANDBOX_FRIENDLY_PATH, 299 COULD_NOT_GET_SANDBOX_FRIENDLY_PATH,
301 l10n_util::GetStringUTF16(IDS_EXTENSION_UNPACK_FAILED)); 300 l10n_util::GetStringUTF16(IDS_EXTENSION_UNPACK_FAILED));
302 return; 301 return;
303 } 302 }
304 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackLinkFreeCrxPathLength", 303 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackLinkFreeCrxPathLength",
305 link_free_crx_path); 304 link_free_crx_path);
306 305
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 822
824 void SandboxedUnpacker::Cleanup() { 823 void SandboxedUnpacker::Cleanup() {
825 DCHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); 824 DCHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread());
826 if (!temp_dir_.Delete()) { 825 if (!temp_dir_.Delete()) {
827 LOG(WARNING) << "Can not delete temp directory at " 826 LOG(WARNING) << "Can not delete temp directory at "
828 << temp_dir_.path().value(); 827 << temp_dir_.path().value();
829 } 828 }
830 } 829 }
831 830
832 } // namespace extensions 831 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/media_galleries/media_galleries_apitest.cc ('k') | chrome/browser/history/history_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698