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

Side by Side Diff: net/disk_cache/file.h

Issue 8843: Add write and read/write support to FileStream (renamed from FileInputStream)... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 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 | « net/disk_cache/disk_cache_test_util.cc ('k') | net/disk_cache/file_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-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 // See net/disk_cache/disk_cache.h for the public interface of the cache. 5 // See net/disk_cache/disk_cache.h for the public interface of the cache.
6 6
7 #ifndef NET_DISK_CACHE_FILE_H_ 7 #ifndef NET_DISK_CACHE_FILE_H_
8 #define NET_DISK_CACHE_FILE_H_ 8 #define NET_DISK_CACHE_FILE_H_
9 9
10 #include <string> 10 #include <string>
11 11
12 #include "base/platform_file.h"
12 #include "base/ref_counted.h" 13 #include "base/ref_counted.h"
13 #include "net/disk_cache/os_file.h"
14 14
15 namespace disk_cache { 15 namespace disk_cache {
16 16
17 // This interface is used to support asynchronous ReadData and WriteData calls. 17 // This interface is used to support asynchronous ReadData and WriteData calls.
18 class FileIOCallback { 18 class FileIOCallback {
19 public: 19 public:
20 // Notified of the actual number of bytes read or written. This value is 20 // Notified of the actual number of bytes read or written. This value is
21 // negative if an error occurred. 21 // negative if an error occurred.
22 virtual void OnFileIOComplete(int bytes_copied) = 0; 22 virtual void OnFileIOComplete(int bytes_copied) = 0;
23 23
24 virtual ~FileIOCallback() {} 24 virtual ~FileIOCallback() {}
25 }; 25 };
26 26
27 // Simple wrapper around a file that allows asynchronous operations. 27 // Simple wrapper around a file that allows asynchronous operations.
28 class File : public base::RefCounted<File> { 28 class File : public base::RefCounted<File> {
29 friend class base::RefCounted<File>; 29 friend class base::RefCounted<File>;
30 public: 30 public:
31 File() : init_(false), mixed_(false) {} 31 File() : init_(false), mixed_(false) {}
32 // mixed_mode set to true enables regular synchronous operations for the file. 32 // mixed_mode set to true enables regular synchronous operations for the file.
33 explicit File(bool mixed_mode) : init_(false), mixed_(mixed_mode) {} 33 explicit File(bool mixed_mode) : init_(false), mixed_(mixed_mode) {}
34 34
35 // Initializes the object to use the passed in file instead of opening it with 35 // Initializes the object to use the passed in file instead of opening it with
36 // the Init() call. No asynchronous operations can be performed with this 36 // the Init() call. No asynchronous operations can be performed with this
37 // object. 37 // object.
38 explicit File(OSFile file); 38 explicit File(base::PlatformFile file);
39 39
40 // Initializes the object to point to a given file. The file must aready exist 40 // Initializes the object to point to a given file. The file must aready exist
41 // on disk, and allow shared read and write. 41 // on disk, and allow shared read and write.
42 bool Init(const std::wstring& name); 42 bool Init(const std::wstring& name);
43 43
44 // Returns the handle or file descriptor. 44 // Returns the handle or file descriptor.
45 OSFile os_file() const; 45 base::PlatformFile platform_file() const;
46 46
47 // Returns true if the file was opened properly. 47 // Returns true if the file was opened properly.
48 bool IsValid() const; 48 bool IsValid() const;
49 49
50 // Performs synchronous IO. 50 // Performs synchronous IO.
51 bool Read(void* buffer, size_t buffer_len, size_t offset); 51 bool Read(void* buffer, size_t buffer_len, size_t offset);
52 bool Write(const void* buffer, size_t buffer_len, size_t offset); 52 bool Write(const void* buffer, size_t buffer_len, size_t offset);
53 53
54 // Performs asynchronous IO. callback will be called when the IO completes, 54 // Performs asynchronous IO. callback will be called when the IO completes,
55 // as an APC on the thread that queued the operation. 55 // as an APC on the thread that queued the operation.
(...skipping 15 matching lines...) Expand all
71 virtual ~File(); 71 virtual ~File();
72 72
73 // Performs the actual asynchronous write. If notify is set and there is no 73 // Performs the actual asynchronous write. If notify is set and there is no
74 // callback, the call will be re-synchronized. 74 // callback, the call will be re-synchronized.
75 bool AsyncWrite(const void* buffer, size_t buffer_len, size_t offset, 75 bool AsyncWrite(const void* buffer, size_t buffer_len, size_t offset,
76 bool notify, FileIOCallback* callback, bool* completed); 76 bool notify, FileIOCallback* callback, bool* completed);
77 77
78 private: 78 private:
79 bool init_; 79 bool init_;
80 bool mixed_; 80 bool mixed_;
81 OSFile os_file_; // Regular, asynchronous IO handle. 81 base::PlatformFile platform_file_; // Regular, asynchronous IO handle.
82 OSFile sync_os_file_; // Synchronous IO hanlde. 82 base::PlatformFile sync_platform_file_; // Synchronous IO handle.
83 83
84 DISALLOW_COPY_AND_ASSIGN(File); 84 DISALLOW_COPY_AND_ASSIGN(File);
85 }; 85 };
86 86
87 } // namespace disk_cache 87 } // namespace disk_cache
88 88
89 #endif // NET_DISK_CACHE_FILE_H_ 89 #endif // NET_DISK_CACHE_FILE_H_
90 90
OLDNEW
« no previous file with comments | « net/disk_cache/disk_cache_test_util.cc ('k') | net/disk_cache/file_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698