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

Side by Side Diff: components/drive/file_cache.h

Issue 1546143002: Switch to standard integer types in components/, part 1 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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
« no previous file with comments | « components/drive/fake_free_disk_space_getter.cc ('k') | components/drive/file_cache.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) 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 COMPONENTS_DRIVE_FILE_CACHE_H_ 5 #ifndef COMPONENTS_DRIVE_FILE_CACHE_H_
6 #define COMPONENTS_DRIVE_FILE_CACHE_H_ 6 #define COMPONENTS_DRIVE_FILE_CACHE_H_
7 7
8 #include <stddef.h>
9 #include <stdint.h>
10
8 #include <set> 11 #include <set>
9 #include <string> 12 #include <string>
10 13
11 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
14 #include "base/synchronization/cancellation_flag.h" 18 #include "base/synchronization/cancellation_flag.h"
15 #include "base/threading/thread_checker.h" 19 #include "base/threading/thread_checker.h"
20 #include "build/build_config.h"
16 #include "components/drive/file_errors.h" 21 #include "components/drive/file_errors.h"
17 #include "components/drive/resource_metadata_storage.h" 22 #include "components/drive/resource_metadata_storage.h"
18 #if defined(OS_CHROMEOS) 23 #if defined(OS_CHROMEOS)
19 #include "third_party/cros_system_api/constants/cryptohome.h" 24 #include "third_party/cros_system_api/constants/cryptohome.h"
20 #endif 25 #endif
21 26
22 namespace base { 27 namespace base {
23 class ScopedClosureRunner; 28 class ScopedClosureRunner;
24 class SequencedTaskRunner; 29 class SequencedTaskRunner;
25 } // namespace base 30 } // namespace base
26 31
27 namespace drive { 32 namespace drive {
28 33
29 namespace internal { 34 namespace internal {
30 35
31 #if defined(OS_CHROMEOS) 36 #if defined(OS_CHROMEOS)
32 const int64 kMinFreeSpaceInBytes = cryptohome::kMinFreeSpaceInBytes; 37 const int64_t kMinFreeSpaceInBytes = cryptohome::kMinFreeSpaceInBytes;
33 #else 38 #else
34 const int64 kMinFreeSpaceInBytes = 512ull * 1024ull * 1024ull; // 512MB 39 const int64_t kMinFreeSpaceInBytes = 512ull * 1024ull * 1024ull; // 512MB
35 #endif 40 #endif
36 41
37 // Interface class used for getting the free disk space. Tests can inject an 42 // Interface class used for getting the free disk space. Tests can inject an
38 // implementation that reports fake free disk space. 43 // implementation that reports fake free disk space.
39 class FreeDiskSpaceGetterInterface { 44 class FreeDiskSpaceGetterInterface {
40 public: 45 public:
41 virtual ~FreeDiskSpaceGetterInterface() {} 46 virtual ~FreeDiskSpaceGetterInterface() {}
42 virtual int64 AmountOfFreeDiskSpace() = 0; 47 virtual int64_t AmountOfFreeDiskSpace() = 0;
43 }; 48 };
44 49
45 // FileCache is used to maintain cache states of FileSystem. 50 // FileCache is used to maintain cache states of FileSystem.
46 // 51 //
47 // All non-static public member functions, unless mentioned otherwise (see 52 // All non-static public member functions, unless mentioned otherwise (see
48 // GetCacheFilePath() for example), should be run with |blocking_task_runner|. 53 // GetCacheFilePath() for example), should be run with |blocking_task_runner|.
49 class FileCache { 54 class FileCache {
50 public: 55 public:
51 // Enum defining type of file operation e.g. copy or move, etc. 56 // Enum defining type of file operation e.g. copy or move, etc.
52 enum FileOperationType { 57 enum FileOperationType {
(...skipping 23 matching lines...) Expand all
76 // Returns true if the given path is under drive cache directory, i.e. 81 // Returns true if the given path is under drive cache directory, i.e.
77 // <user_profile_dir>/GCache/v1 82 // <user_profile_dir>/GCache/v1
78 // 83 //
79 // Can be called on any thread. 84 // Can be called on any thread.
80 bool IsUnderFileCacheDirectory(const base::FilePath& path) const; 85 bool IsUnderFileCacheDirectory(const base::FilePath& path) const;
81 86
82 // Frees up disk space to store a file with |num_bytes| size content, while 87 // Frees up disk space to store a file with |num_bytes| size content, while
83 // keeping drive::internal::kMinFreeSpaceInBytes bytes on the disk, if needed. 88 // keeping drive::internal::kMinFreeSpaceInBytes bytes on the disk, if needed.
84 // Returns true if we successfully manage to have enough space, otherwise 89 // Returns true if we successfully manage to have enough space, otherwise
85 // false. 90 // false.
86 bool FreeDiskSpaceIfNeededFor(int64 num_bytes); 91 bool FreeDiskSpaceIfNeededFor(int64_t num_bytes);
87 92
88 // Calculates and returns evictable cache size. In error case, this returns 0. 93 // Calculates and returns evictable cache size. In error case, this returns 0.
89 uint64_t CalculateEvictableCacheSize(); 94 uint64_t CalculateEvictableCacheSize();
90 95
91 // Checks if file corresponding to |id| exists in cache, and returns 96 // Checks if file corresponding to |id| exists in cache, and returns
92 // FILE_ERROR_OK with |cache_file_path| storing the path to the file. 97 // FILE_ERROR_OK with |cache_file_path| storing the path to the file.
93 // |cache_file_path| must not be null. 98 // |cache_file_path| must not be null.
94 FileError GetFile(const std::string& id, base::FilePath* cache_file_path); 99 FileError GetFile(const std::string& id, base::FilePath* cache_file_path);
95 100
96 // Stores |source_path| as a cache of the remote content of the file 101 // Stores |source_path| as a cache of the remote content of the file
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 169
165 // Checks whether the current thread is on the right sequenced worker pool 170 // Checks whether the current thread is on the right sequenced worker pool
166 // with the right sequence ID. If not, DCHECK will fail. 171 // with the right sequence ID. If not, DCHECK will fail.
167 void AssertOnSequencedWorkerPool(); 172 void AssertOnSequencedWorkerPool();
168 173
169 // Destroys the cache on the blocking pool. 174 // Destroys the cache on the blocking pool.
170 void DestroyOnBlockingPool(); 175 void DestroyOnBlockingPool();
171 176
172 // Returns available space, while keeping 177 // Returns available space, while keeping
173 // drive::internal::kMinFreeSpaceInBytes bytes on the disk. 178 // drive::internal::kMinFreeSpaceInBytes bytes on the disk.
174 int64 GetAvailableSpace(); 179 int64_t GetAvailableSpace();
175 180
176 // Renames cache files from old "prefix:id.md5" format to the new format. 181 // Renames cache files from old "prefix:id.md5" format to the new format.
177 // TODO(hashimoto): Remove this method at some point. 182 // TODO(hashimoto): Remove this method at some point.
178 bool RenameCacheFilesToNewFormat(); 183 bool RenameCacheFilesToNewFormat();
179 184
180 // This method must be called after writing to a cache file. 185 // This method must be called after writing to a cache file.
181 // Used to implement OpenForWrite(). 186 // Used to implement OpenForWrite().
182 void CloseForWrite(const std::string& id); 187 void CloseForWrite(const std::string& id);
183 188
184 // Returns true if the cache entry can be evicted. 189 // Returns true if the cache entry can be evicted.
(...skipping 26 matching lines...) Expand all
211 // invalidate its weak pointers before any other members are destroyed. 216 // invalidate its weak pointers before any other members are destroyed.
212 // This object should be accessed only on |blocking_task_runner_|. 217 // This object should be accessed only on |blocking_task_runner_|.
213 base::WeakPtrFactory<FileCache> weak_ptr_factory_; 218 base::WeakPtrFactory<FileCache> weak_ptr_factory_;
214 DISALLOW_COPY_AND_ASSIGN(FileCache); 219 DISALLOW_COPY_AND_ASSIGN(FileCache);
215 }; 220 };
216 221
217 } // namespace internal 222 } // namespace internal
218 } // namespace drive 223 } // namespace drive
219 224
220 #endif // COMPONENTS_DRIVE_FILE_CACHE_H_ 225 #endif // COMPONENTS_DRIVE_FILE_CACHE_H_
OLDNEW
« no previous file with comments | « components/drive/fake_free_disk_space_getter.cc ('k') | components/drive/file_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698