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 #ifndef STORAGE_BROWSER_FILEAPI_FILE_SYSTEM_USAGE_CACHE_H_ | 5 #ifndef STORAGE_BROWSER_FILEAPI_FILE_SYSTEM_USAGE_CACHE_H_ |
6 #define STORAGE_BROWSER_FILEAPI_FILE_SYSTEM_USAGE_CACHE_H_ | 6 #define STORAGE_BROWSER_FILEAPI_FILE_SYSTEM_USAGE_CACHE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 bool Delete(const base::FilePath& usage_file_path); | 56 bool Delete(const base::FilePath& usage_file_path); |
57 | 57 |
58 void CloseCacheFiles(); | 58 void CloseCacheFiles(); |
59 | 59 |
60 static const base::FilePath::CharType kUsageFileName[]; | 60 static const base::FilePath::CharType kUsageFileName[]; |
61 static const char kUsageFileHeader[]; | 61 static const char kUsageFileHeader[]; |
62 static const int kUsageFileSize; | 62 static const int kUsageFileSize; |
63 static const int kUsageFileHeaderSize; | 63 static const int kUsageFileHeaderSize; |
64 | 64 |
65 private: | 65 private: |
66 typedef std::map<base::FilePath, base::File*> CacheFiles; | |
67 | |
68 // Read the size, validity and the "dirty" entry described in the .usage file. | 66 // Read the size, validity and the "dirty" entry described in the .usage file. |
69 // Returns less than zero if no .usage file is available. | 67 // Returns less than zero if no .usage file is available. |
70 bool Read(const base::FilePath& usage_file_path, | 68 bool Read(const base::FilePath& usage_file_path, |
71 bool* is_valid, | 69 bool* is_valid, |
72 uint32_t* dirty, | 70 uint32_t* dirty, |
73 int64_t* usage); | 71 int64_t* usage); |
74 | 72 |
75 bool Write(const base::FilePath& usage_file_path, | 73 bool Write(const base::FilePath& usage_file_path, |
76 bool is_valid, | 74 bool is_valid, |
77 int32_t dirty, | 75 int32_t dirty, |
78 int64_t fs_usage); | 76 int64_t fs_usage); |
79 | 77 |
80 base::File* GetFile(const base::FilePath& file_path); | 78 base::File* GetFile(const base::FilePath& file_path); |
81 | 79 |
82 bool ReadBytes(const base::FilePath& file_path, | 80 bool ReadBytes(const base::FilePath& file_path, |
83 char* buffer, | 81 char* buffer, |
84 int64_t buffer_size); | 82 int64_t buffer_size); |
85 bool WriteBytes(const base::FilePath& file_path, | 83 bool WriteBytes(const base::FilePath& file_path, |
86 const char* buffer, | 84 const char* buffer, |
87 int64_t buffer_size); | 85 int64_t buffer_size); |
88 bool FlushFile(const base::FilePath& file_path); | 86 bool FlushFile(const base::FilePath& file_path); |
89 void ScheduleCloseTimer(); | 87 void ScheduleCloseTimer(); |
90 | 88 |
91 bool HasCacheFileHandle(const base::FilePath& file_path); | 89 bool HasCacheFileHandle(const base::FilePath& file_path); |
92 | 90 |
93 bool CalledOnValidThread(); | 91 bool CalledOnValidThread(); |
94 | 92 |
95 std::unique_ptr<TimedTaskHelper> timer_; | 93 std::unique_ptr<TimedTaskHelper> timer_; |
96 CacheFiles cache_files_; | 94 std::map<base::FilePath, std::unique_ptr<base::File>> cache_files_; |
97 | 95 |
98 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 96 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
99 | 97 |
100 base::WeakPtrFactory<FileSystemUsageCache> weak_factory_; | 98 base::WeakPtrFactory<FileSystemUsageCache> weak_factory_; |
101 | 99 |
102 DISALLOW_COPY_AND_ASSIGN(FileSystemUsageCache); | 100 DISALLOW_COPY_AND_ASSIGN(FileSystemUsageCache); |
103 }; | 101 }; |
104 | 102 |
105 } // namespace storage | 103 } // namespace storage |
106 | 104 |
107 #endif // STORAGE_BROWSER_FILEAPI_FILE_SYSTEM_USAGE_CACHE_H_ | 105 #endif // STORAGE_BROWSER_FILEAPI_FILE_SYSTEM_USAGE_CACHE_H_ |
OLD | NEW |