OLD | NEW |
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 Loading... |
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 |
270 bool MemoryMappedFile::Initialize(const FilePath& file_name) { | 284 bool MemoryMappedFile::Initialize(const FilePath& file_name) { |
271 if (IsValid()) | 285 if (IsValid()) |
272 return false; | 286 return false; |
273 | 287 |
274 if (!MapFileToMemory(file_name)) { | 288 if (!MapFileToMemory(file_name)) { |
275 CloseHandles(); | 289 CloseHandles(); |
276 return false; | 290 return false; |
277 } | 291 } |
278 | 292 |
279 return true; | 293 return true; |
280 } | 294 } |
281 | 295 |
| 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 |
282 bool MemoryMappedFile::IsValid() { | 309 bool MemoryMappedFile::IsValid() { |
283 return data_ != NULL; | 310 return data_ != NULL; |
284 } | 311 } |
285 | 312 |
286 // Deprecated functions ---------------------------------------------------- | 313 // Deprecated functions ---------------------------------------------------- |
287 | 314 |
288 bool ReadFileToString(const std::wstring& path, std::string* contents) { | 315 bool ReadFileToString(const std::wstring& path, std::string* contents) { |
289 return ReadFileToString(FilePath::FromWStringHack(path), contents); | 316 return ReadFileToString(FilePath::FromWStringHack(path), contents); |
290 } | 317 } |
291 | 318 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 447 |
421 bool FileEnumerator::IsDot(const FilePath& path) { | 448 bool FileEnumerator::IsDot(const FilePath& path) { |
422 return FILE_PATH_LITERAL(".") == path.BaseName().value(); | 449 return FILE_PATH_LITERAL(".") == path.BaseName().value(); |
423 } | 450 } |
424 | 451 |
425 bool FileEnumerator::IsDotDot(const FilePath& path) { | 452 bool FileEnumerator::IsDotDot(const FilePath& path) { |
426 return FILE_PATH_LITERAL("..") == path.BaseName().value(); | 453 return FILE_PATH_LITERAL("..") == path.BaseName().value(); |
427 } | 454 } |
428 | 455 |
429 } // namespace | 456 } // namespace |
OLD | NEW |