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

Side by Side Diff: base/file_util.h

Issue 372075: Use renderer spellchecker for windows. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: inline 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 | « no previous file | base/file_util.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-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 // This file contains utility functions for dealing with the local 5 // This file contains utility functions for dealing with the local
6 // filesystem. 6 // filesystem.
7 7
8 #ifndef BASE_FILE_UTIL_H_ 8 #ifndef BASE_FILE_UTIL_H_
9 #define BASE_FILE_UTIL_H_ 9 #define BASE_FILE_UTIL_H_
10 10
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 12
13 #if defined(OS_WIN) 13 #if defined(OS_WIN)
14 #include <windows.h> 14 #include <windows.h>
15 #elif defined(OS_POSIX) 15 #elif defined(OS_POSIX)
16 #include <sys/stat.h> 16 #include <sys/stat.h>
17 #endif 17 #endif
18 18
19 #include <stdio.h> 19 #include <stdio.h>
20 20
21 #include <stack> 21 #include <stack>
22 #include <string> 22 #include <string>
23 #include <vector> 23 #include <vector>
24 24
25 #include "base/basictypes.h" 25 #include "base/basictypes.h"
26 #include "base/file_path.h" 26 #include "base/file_path.h"
27 #include "base/platform_file.h"
27 #include "base/scoped_ptr.h" 28 #include "base/scoped_ptr.h"
28 #include "base/string16.h" 29 #include "base/string16.h"
29 #include "base/time.h" 30 #include "base/time.h"
30 31
31 #if defined(OS_POSIX) 32 #if defined(OS_POSIX)
32 #include "base/file_descriptor_posix.h" 33 #include "base/file_descriptor_posix.h"
33 #endif 34 #endif
34 35
35 namespace base { 36 namespace base {
36 class Time; 37 class Time;
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 // The default constructor sets all members to invalid/null values. 484 // The default constructor sets all members to invalid/null values.
484 MemoryMappedFile(); 485 MemoryMappedFile();
485 ~MemoryMappedFile(); 486 ~MemoryMappedFile();
486 487
487 // Opens an existing file and maps it into memory. Access is restricted to 488 // Opens an existing file and maps it into memory. Access is restricted to
488 // read only. If this object already points to a valid memory mapped file 489 // read only. If this object already points to a valid memory mapped file
489 // then this method will fail and return false. If it cannot open the file, 490 // then this method will fail and return false. If it cannot open the file,
490 // the file does not exist, or the memory mapping fails, it will return false. 491 // the file does not exist, or the memory mapping fails, it will return false.
491 // Later we may want to allow the user to specify access. 492 // Later we may want to allow the user to specify access.
492 bool Initialize(const FilePath& file_name); 493 bool Initialize(const FilePath& file_name);
493 #if defined(OS_POSIX) 494 // As above, but works with an already-opened file. MemoryMappedFile will take
494 // As above, but works with an alreay-opened file. 495 // ownership of |file| and close it when done.
495 bool Initialize(const base::FileDescriptor& fd); 496 bool Initialize(base::PlatformFile file);
496 #endif
497 497
498 const uint8* data() const { return data_; } 498 const uint8* data() const { return data_; }
499 size_t length() const { return length_; } 499 size_t length() const { return length_; }
500 500
501 // Is file_ a valid file handle that points to an open, memory mapped file? 501 // Is file_ a valid file handle that points to an open, memory mapped file?
502 bool IsValid(); 502 bool IsValid();
503 503
504 private: 504 private:
505 // Open the given file and pass it to MapFileToMemoryInternal().
506 bool MapFileToMemory(const FilePath& file_name);
507
505 // Map the file to memory, set data_ to that memory address. Return true on 508 // Map the file to memory, set data_ to that memory address. Return true on
506 // success, false on any kind of failure. This is a helper for Initialize(). 509 // success, false on any kind of failure. This is a helper for Initialize().
507 bool MapFileToMemory(const FilePath& file_name);
508
509 #if defined(OS_POSIX)
510 bool MapFileToMemoryInternal(); 510 bool MapFileToMemoryInternal();
511 #endif
512 511
513 // Closes all open handles. Later we may want to make this public. 512 // Closes all open handles. Later we may want to make this public.
514 void CloseHandles(); 513 void CloseHandles();
515 514
515 base::PlatformFile file_;
516 #if defined(OS_WIN) 516 #if defined(OS_WIN)
517 HANDLE file_;
518 HANDLE file_mapping_; 517 HANDLE file_mapping_;
519 #elif defined(OS_POSIX)
520 // The file descriptor.
521 base::FileDescriptor file_;
522 #endif 518 #endif
523 uint8* data_; 519 uint8* data_;
524 size_t length_; 520 size_t length_;
525 521
526 DISALLOW_COPY_AND_ASSIGN(MemoryMappedFile); 522 DISALLOW_COPY_AND_ASSIGN(MemoryMappedFile);
527 }; 523 };
528 524
529 // Renames a file using the SHFileOperation API to ensure that the target file 525 // Renames a file using the SHFileOperation API to ensure that the target file
530 // gets the correct default security descriptor in the new path. 526 // gets the correct default security descriptor in the new path.
531 bool RenameFileAndResetSecurityDescriptor( 527 bool RenameFileAndResetSecurityDescriptor(
532 const FilePath& source_file_path, 528 const FilePath& source_file_path,
533 const FilePath& target_file_path); 529 const FilePath& target_file_path);
534 530
535 } // namespace file_util 531 } // namespace file_util
536 532
537 #endif // BASE_FILE_UTIL_H_ 533 #endif // BASE_FILE_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | base/file_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698