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

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

Issue 121643003: Reorganize net/disk_cache into backend specific directories. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix ios breakage Created 6 years, 9 months 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/experiments.h ('k') | net/disk_cache/file.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 // See net/disk_cache/disk_cache.h for the public interface of the cache.
6
7 #ifndef NET_DISK_CACHE_FILE_H_
8 #define NET_DISK_CACHE_FILE_H_
9
10 #include "base/memory/ref_counted.h"
11 #include "base/platform_file.h"
12 #include "net/base/net_export.h"
13
14 namespace base {
15 class FilePath;
16 }
17
18 namespace disk_cache {
19
20 // This interface is used to support asynchronous ReadData and WriteData calls.
21 class FileIOCallback {
22 public:
23 // Notified of the actual number of bytes read or written. This value is
24 // negative if an error occurred.
25 virtual void OnFileIOComplete(int bytes_copied) = 0;
26
27 protected:
28 virtual ~FileIOCallback() {}
29 };
30
31 // Simple wrapper around a file that allows asynchronous operations.
32 class NET_EXPORT_PRIVATE File : public base::RefCounted<File> {
33 friend class base::RefCounted<File>;
34 public:
35 File();
36 // mixed_mode set to true enables regular synchronous operations for the file.
37 explicit File(bool mixed_mode);
38
39 // Initializes the object to use the passed in file instead of opening it with
40 // the Init() call. No asynchronous operations can be performed with this
41 // object.
42 explicit File(base::PlatformFile file);
43
44 // Initializes the object to point to a given file. The file must aready exist
45 // on disk, and allow shared read and write.
46 bool Init(const base::FilePath& name);
47
48 // Returns the handle or file descriptor.
49 base::PlatformFile platform_file() const;
50
51 // Returns true if the file was opened properly.
52 bool IsValid() const;
53
54 // Performs synchronous IO.
55 bool Read(void* buffer, size_t buffer_len, size_t offset);
56 bool Write(const void* buffer, size_t buffer_len, size_t offset);
57
58 // Performs asynchronous IO. callback will be called when the IO completes,
59 // as an APC on the thread that queued the operation.
60 bool Read(void* buffer, size_t buffer_len, size_t offset,
61 FileIOCallback* callback, bool* completed);
62 bool Write(const void* buffer, size_t buffer_len, size_t offset,
63 FileIOCallback* callback, bool* completed);
64
65 // Sets the file's length. The file is truncated or extended with zeros to
66 // the new length.
67 bool SetLength(size_t length);
68 size_t GetLength();
69
70 // Blocks until |num_pending_io| IO operations complete.
71 static void WaitForPendingIO(int* num_pending_io);
72
73 // Drops current pending operations without waiting for them to complete.
74 static void DropPendingIO();
75
76 protected:
77 virtual ~File();
78
79 private:
80 // Performs the actual asynchronous write. If notify is set and there is no
81 // callback, the call will be re-synchronized.
82 bool AsyncWrite(const void* buffer, size_t buffer_len, size_t offset,
83 FileIOCallback* callback, bool* completed);
84
85 // Infrastructure for async IO.
86 int DoRead(void* buffer, size_t buffer_len, size_t offset);
87 int DoWrite(const void* buffer, size_t buffer_len, size_t offset);
88 void OnOperationComplete(FileIOCallback* callback, int result);
89
90 bool init_;
91 bool mixed_;
92 base::PlatformFile platform_file_; // Regular, asynchronous IO handle.
93 base::PlatformFile sync_platform_file_; // Synchronous IO handle.
94
95 DISALLOW_COPY_AND_ASSIGN(File);
96 };
97
98 } // namespace disk_cache
99
100 #endif // NET_DISK_CACHE_FILE_H_
OLDNEW
« no previous file with comments | « net/disk_cache/experiments.h ('k') | net/disk_cache/file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698