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

Side by Side Diff: base/file_util.cc

Issue 397014: Revert 31875 to see whether it fixes reliability bot. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 1 month 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 | « base/file_util.h ('k') | base/file_util_posix.cc » ('j') | 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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 "base/file_util.h" 5 #include "base/file_util.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <io.h> 8 #include <io.h>
9 #endif 9 #endif
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 return true; 260 return true;
261 } 261 }
262 262
263 /////////////////////////////////////////////// 263 ///////////////////////////////////////////////
264 // MemoryMappedFile 264 // MemoryMappedFile
265 265
266 MemoryMappedFile::~MemoryMappedFile() { 266 MemoryMappedFile::~MemoryMappedFile() {
267 CloseHandles(); 267 CloseHandles();
268 } 268 }
269 269
270 bool MemoryMappedFile::Initialize(base::PlatformFile file) {
271 if (IsValid())
272 return false;
273
274 file_ = file;
275
276 if (!MapFileToMemoryInternal()) {
277 CloseHandles();
278 return false;
279 }
280
281 return true;
282 }
283
284 bool MemoryMappedFile::Initialize(const FilePath& file_name) { 270 bool MemoryMappedFile::Initialize(const FilePath& file_name) {
285 if (IsValid()) 271 if (IsValid())
286 return false; 272 return false;
287 273
288 if (!MapFileToMemory(file_name)) { 274 if (!MapFileToMemory(file_name)) {
289 CloseHandles(); 275 CloseHandles();
290 return false; 276 return false;
291 } 277 }
292 278
293 return true; 279 return true;
294 } 280 }
295 281
296 bool MemoryMappedFile::MapFileToMemory(const FilePath& file_name) {
297 file_ = base::CreatePlatformFile(file_name,
298 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ,
299 NULL);
300
301 if (file_ == base::kInvalidPlatformFileValue) {
302 LOG(ERROR) << "Couldn't open " << file_name.value();
303 return false;
304 }
305
306 return MapFileToMemoryInternal();
307 }
308
309 bool MemoryMappedFile::IsValid() { 282 bool MemoryMappedFile::IsValid() {
310 return data_ != NULL; 283 return data_ != NULL;
311 } 284 }
312 285
313 // Deprecated functions ---------------------------------------------------- 286 // Deprecated functions ----------------------------------------------------
314 287
315 bool ReadFileToString(const std::wstring& path, std::string* contents) { 288 bool ReadFileToString(const std::wstring& path, std::string* contents) {
316 return ReadFileToString(FilePath::FromWStringHack(path), contents); 289 return ReadFileToString(FilePath::FromWStringHack(path), contents);
317 } 290 }
318 291
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 420
448 bool FileEnumerator::IsDot(const FilePath& path) { 421 bool FileEnumerator::IsDot(const FilePath& path) {
449 return FILE_PATH_LITERAL(".") == path.BaseName().value(); 422 return FILE_PATH_LITERAL(".") == path.BaseName().value();
450 } 423 }
451 424
452 bool FileEnumerator::IsDotDot(const FilePath& path) { 425 bool FileEnumerator::IsDotDot(const FilePath& path) {
453 return FILE_PATH_LITERAL("..") == path.BaseName().value(); 426 return FILE_PATH_LITERAL("..") == path.BaseName().value();
454 } 427 }
455 428
456 } // namespace 429 } // namespace
OLDNEW
« no previous file with comments | « base/file_util.h ('k') | base/file_util_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698