| OLD | NEW |
| 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 "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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 LARGE_INTEGER li = { info.nFileSizeLow, info.nFileSizeHigh }; | 344 LARGE_INTEGER li = { info.nFileSizeLow, info.nFileSizeHigh }; |
| 345 running_size += li.QuadPart; | 345 running_size += li.QuadPart; |
| 346 #else | 346 #else |
| 347 running_size += info.stat.st_size; | 347 running_size += info.stat.st_size; |
| 348 #endif | 348 #endif |
| 349 } | 349 } |
| 350 return running_size; | 350 return running_size; |
| 351 } | 351 } |
| 352 | 352 |
| 353 /////////////////////////////////////////////// | 353 /////////////////////////////////////////////// |
| 354 // MemoryMappedFile | |
| 355 | |
| 356 MemoryMappedFile::~MemoryMappedFile() { | |
| 357 CloseHandles(); | |
| 358 } | |
| 359 | |
| 360 bool MemoryMappedFile::Initialize(const FilePath& file_name) { | |
| 361 if (IsValid()) | |
| 362 return false; | |
| 363 | |
| 364 if (!MapFileToMemory(file_name)) { | |
| 365 CloseHandles(); | |
| 366 return false; | |
| 367 } | |
| 368 | |
| 369 return true; | |
| 370 } | |
| 371 | |
| 372 bool MemoryMappedFile::Initialize(base::PlatformFile file) { | |
| 373 if (IsValid()) | |
| 374 return false; | |
| 375 | |
| 376 file_ = file; | |
| 377 | |
| 378 if (!MapFileToMemoryInternal()) { | |
| 379 CloseHandles(); | |
| 380 return false; | |
| 381 } | |
| 382 | |
| 383 return true; | |
| 384 } | |
| 385 | |
| 386 bool MemoryMappedFile::IsValid() const { | |
| 387 return data_ != NULL; | |
| 388 } | |
| 389 | |
| 390 bool MemoryMappedFile::MapFileToMemory(const FilePath& file_name) { | |
| 391 file_ = base::CreatePlatformFile( | |
| 392 file_name, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, | |
| 393 NULL, NULL); | |
| 394 | |
| 395 if (file_ == base::kInvalidPlatformFileValue) { | |
| 396 DLOG(ERROR) << "Couldn't open " << file_name.value(); | |
| 397 return false; | |
| 398 } | |
| 399 | |
| 400 return MapFileToMemoryInternal(); | |
| 401 } | |
| 402 | |
| 403 /////////////////////////////////////////////// | |
| 404 // FileEnumerator | 354 // FileEnumerator |
| 405 // | 355 // |
| 406 // Note: the main logic is in file_util_<platform>.cc | 356 // Note: the main logic is in file_util_<platform>.cc |
| 407 | 357 |
| 408 bool FileEnumerator::ShouldSkip(const FilePath& path) { | 358 bool FileEnumerator::ShouldSkip(const FilePath& path) { |
| 409 FilePath::StringType basename = path.BaseName().value(); | 359 FilePath::StringType basename = path.BaseName().value(); |
| 410 return IsDot(path) || (IsDotDot(path) && !(INCLUDE_DOT_DOT & file_type_)); | 360 return IsDot(path) || (IsDotDot(path) && !(INCLUDE_DOT_DOT & file_type_)); |
| 411 } | 361 } |
| 412 | 362 |
| 413 } // namespace | 363 } // namespace |
| OLD | NEW |