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

Side by Side Diff: net/disk_cache/blockfile/backend_impl.h

Issue 1492403002: Remove kuint32max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: http security header file Created 5 years 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 | « media/audio/audio_output_controller.cc ('k') | net/disk_cache/blockfile/backend_impl.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 // 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_BLOCKFILE_BACKEND_IMPL_H_ 7 #ifndef NET_DISK_CACHE_BLOCKFILE_BACKEND_IMPL_H_
8 #define NET_DISK_CACHE_BLOCKFILE_BACKEND_IMPL_H_ 8 #define NET_DISK_CACHE_BLOCKFILE_BACKEND_IMPL_H_
9 9
10 #include <stdint.h>
11
10 #include "base/containers/hash_tables.h" 12 #include "base/containers/hash_tables.h"
11 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
12 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
13 #include "base/timer/timer.h" 15 #include "base/timer/timer.h"
14 #include "net/disk_cache/blockfile/block_files.h" 16 #include "net/disk_cache/blockfile/block_files.h"
15 #include "net/disk_cache/blockfile/eviction.h" 17 #include "net/disk_cache/blockfile/eviction.h"
16 #include "net/disk_cache/blockfile/in_flight_backend_io.h" 18 #include "net/disk_cache/blockfile/in_flight_backend_io.h"
17 #include "net/disk_cache/blockfile/rankings.h" 19 #include "net/disk_cache/blockfile/rankings.h"
18 #include "net/disk_cache/blockfile/stats.h" 20 #include "net/disk_cache/blockfile/stats.h"
19 #include "net/disk_cache/blockfile/stress_support.h" 21 #include "net/disk_cache/blockfile/stress_support.h"
(...skipping 27 matching lines...) Expand all
47 // This class implements the Backend interface. An object of this 49 // This class implements the Backend interface. An object of this
48 // class handles the operations of the cache for a particular profile. 50 // class handles the operations of the cache for a particular profile.
49 class NET_EXPORT_PRIVATE BackendImpl : public Backend { 51 class NET_EXPORT_PRIVATE BackendImpl : public Backend {
50 friend class Eviction; 52 friend class Eviction;
51 public: 53 public:
52 BackendImpl(const base::FilePath& path, 54 BackendImpl(const base::FilePath& path,
53 const scoped_refptr<base::SingleThreadTaskRunner>& cache_thread, 55 const scoped_refptr<base::SingleThreadTaskRunner>& cache_thread,
54 net::NetLog* net_log); 56 net::NetLog* net_log);
55 // mask can be used to limit the usable size of the hash table, for testing. 57 // mask can be used to limit the usable size of the hash table, for testing.
56 BackendImpl(const base::FilePath& path, 58 BackendImpl(const base::FilePath& path,
57 uint32 mask, 59 uint32_t mask,
58 const scoped_refptr<base::SingleThreadTaskRunner>& cache_thread, 60 const scoped_refptr<base::SingleThreadTaskRunner>& cache_thread,
59 net::NetLog* net_log); 61 net::NetLog* net_log);
60 ~BackendImpl() override; 62 ~BackendImpl() override;
61 63
62 // Performs general initialization for this current instance of the cache. 64 // Performs general initialization for this current instance of the cache.
63 int Init(const CompletionCallback& callback); 65 int Init(const CompletionCallback& callback);
64 66
65 // Performs the actual initialization and final cleanup on destruction. 67 // Performs the actual initialization and final cleanup on destruction.
66 int SyncInit(); 68 int SyncInit();
67 void CleanupCache(); 69 void CleanupCache();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // This method must be called after all resources for an entry have been 144 // This method must be called after all resources for an entry have been
143 // released. 145 // released.
144 void OnEntryDestroyEnd(); 146 void OnEntryDestroyEnd();
145 147
146 // If the data stored by the provided |rankings| points to an open entry, 148 // If the data stored by the provided |rankings| points to an open entry,
147 // returns a pointer to that entry, otherwise returns NULL. Note that this 149 // returns a pointer to that entry, otherwise returns NULL. Note that this
148 // method does NOT increase the ref counter for the entry. 150 // method does NOT increase the ref counter for the entry.
149 EntryImpl* GetOpenEntry(CacheRankingsBlock* rankings) const; 151 EntryImpl* GetOpenEntry(CacheRankingsBlock* rankings) const;
150 152
151 // Returns the id being used on this run of the cache. 153 // Returns the id being used on this run of the cache.
152 int32 GetCurrentEntryId() const; 154 int32_t GetCurrentEntryId() const;
153 155
154 // Returns the maximum size for a file to reside on the cache. 156 // Returns the maximum size for a file to reside on the cache.
155 int MaxFileSize() const; 157 int MaxFileSize() const;
156 158
157 // A user data block is being created, extended or truncated. 159 // A user data block is being created, extended or truncated.
158 void ModifyStorageSize(int32 old_size, int32 new_size); 160 void ModifyStorageSize(int32_t old_size, int32_t new_size);
159 161
160 // Logs requests that are denied due to being too big. 162 // Logs requests that are denied due to being too big.
161 void TooMuchStorageRequested(int32 size); 163 void TooMuchStorageRequested(int32_t size);
162 164
163 // Returns true if a temporary buffer is allowed to be extended. 165 // Returns true if a temporary buffer is allowed to be extended.
164 bool IsAllocAllowed(int current_size, int new_size); 166 bool IsAllocAllowed(int current_size, int new_size);
165 167
166 // Tracks the release of |size| bytes by an entry buffer. 168 // Tracks the release of |size| bytes by an entry buffer.
167 void BufferDeleted(int size); 169 void BufferDeleted(int size);
168 170
169 // Only intended for testing the two previous methods. 171 // Only intended for testing the two previous methods.
170 int GetTotalBuffersSize() const { 172 int GetTotalBuffersSize() const {
171 return buffer_bytes_; 173 return buffer_bytes_;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 // Sets internal parameters to enable unit testing mode. 223 // Sets internal parameters to enable unit testing mode.
222 void SetUnitTestMode(); 224 void SetUnitTestMode();
223 225
224 // Sets internal parameters to enable upgrade mode (for internal tools). 226 // Sets internal parameters to enable upgrade mode (for internal tools).
225 void SetUpgradeMode(); 227 void SetUpgradeMode();
226 228
227 // Sets the eviction algorithm to version 2. 229 // Sets the eviction algorithm to version 2.
228 void SetNewEviction(); 230 void SetNewEviction();
229 231
230 // Sets an explicit set of BackendFlags. 232 // Sets an explicit set of BackendFlags.
231 void SetFlags(uint32 flags); 233 void SetFlags(uint32_t flags);
232 234
233 // Clears the counter of references to test handling of corruptions. 235 // Clears the counter of references to test handling of corruptions.
234 void ClearRefCountForTest(); 236 void ClearRefCountForTest();
235 237
236 // Sends a dummy operation through the operation queue, for unit tests. 238 // Sends a dummy operation through the operation queue, for unit tests.
237 int FlushQueueForTest(const CompletionCallback& callback); 239 int FlushQueueForTest(const CompletionCallback& callback);
238 240
239 // Runs the provided task on the cache thread. The task will be automatically 241 // Runs the provided task on the cache thread. The task will be automatically
240 // deleted after it runs. 242 // deleted after it runs.
241 int RunTaskForTest(const base::Closure& task, 243 int RunTaskForTest(const base::Closure& task,
(...skipping 12 matching lines...) Expand all
254 256
255 // Performs a simple self-check, and returns the number of dirty items 257 // Performs a simple self-check, and returns the number of dirty items
256 // or an error code (negative value). 258 // or an error code (negative value).
257 int SelfCheck(); 259 int SelfCheck();
258 260
259 // Ensures the index is flushed to disk (a no-op on platforms with mmap). 261 // Ensures the index is flushed to disk (a no-op on platforms with mmap).
260 void FlushIndex(); 262 void FlushIndex();
261 263
262 // Backend implementation. 264 // Backend implementation.
263 net::CacheType GetCacheType() const override; 265 net::CacheType GetCacheType() const override;
264 int32 GetEntryCount() const override; 266 int32_t GetEntryCount() const override;
265 int OpenEntry(const std::string& key, 267 int OpenEntry(const std::string& key,
266 Entry** entry, 268 Entry** entry,
267 const CompletionCallback& callback) override; 269 const CompletionCallback& callback) override;
268 int CreateEntry(const std::string& key, 270 int CreateEntry(const std::string& key,
269 Entry** entry, 271 Entry** entry,
270 const CompletionCallback& callback) override; 272 const CompletionCallback& callback) override;
271 int DoomEntry(const std::string& key, 273 int DoomEntry(const std::string& key,
272 const CompletionCallback& callback) override; 274 const CompletionCallback& callback) override;
273 int DoomAllEntries(const CompletionCallback& callback) override; 275 int DoomAllEntries(const CompletionCallback& callback) override;
274 int DoomEntriesBetween(base::Time initial_time, 276 int DoomEntriesBetween(base::Time initial_time,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // on failure. 311 // on failure.
310 int NewEntry(Addr address, EntryImpl** entry); 312 int NewEntry(Addr address, EntryImpl** entry);
311 313
312 // Returns a given entry from the cache. The entry to match is determined by 314 // Returns a given entry from the cache. The entry to match is determined by
313 // key and hash, and the returned entry may be the matched one or it's parent 315 // key and hash, and the returned entry may be the matched one or it's parent
314 // on the list of entries with the same hash (or bucket). To look for a parent 316 // on the list of entries with the same hash (or bucket). To look for a parent
315 // of a given entry, |entry_addr| should be grabbed from that entry, so that 317 // of a given entry, |entry_addr| should be grabbed from that entry, so that
316 // if it doesn't match the entry on the index, we know that it was replaced 318 // if it doesn't match the entry on the index, we know that it was replaced
317 // with a new entry; in this case |*match_error| will be set to true and the 319 // with a new entry; in this case |*match_error| will be set to true and the
318 // return value will be NULL. 320 // return value will be NULL.
319 EntryImpl* MatchEntry(const std::string& key, uint32 hash, bool find_parent, 321 EntryImpl* MatchEntry(const std::string& key,
320 Addr entry_addr, bool* match_error); 322 uint32_t hash,
323 bool find_parent,
324 Addr entry_addr,
325 bool* match_error);
321 326
322 // Opens the next or previous entry on a single list. If successful, 327 // Opens the next or previous entry on a single list. If successful,
323 // |from_entry| will be updated to point to the new entry, otherwise it will 328 // |from_entry| will be updated to point to the new entry, otherwise it will
324 // be set to NULL; in other words, it is used as an explicit iterator. 329 // be set to NULL; in other words, it is used as an explicit iterator.
325 bool OpenFollowingEntryFromList(Rankings::List list, 330 bool OpenFollowingEntryFromList(Rankings::List list,
326 CacheRankingsBlock** from_entry, 331 CacheRankingsBlock** from_entry,
327 EntryImpl** next_entry); 332 EntryImpl** next_entry);
328 333
329 // Returns the entry that is pointed by |next|, from the given |list|. 334 // Returns the entry that is pointed by |next|, from the given |list|.
330 EntryImpl* GetEnumeratedEntry(CacheRankingsBlock* next, Rankings::List list); 335 EntryImpl* GetEnumeratedEntry(CacheRankingsBlock* next, Rankings::List list);
331 336
332 // Re-opens an entry that was previously deleted. 337 // Re-opens an entry that was previously deleted.
333 EntryImpl* ResurrectEntry(EntryImpl* deleted_entry); 338 EntryImpl* ResurrectEntry(EntryImpl* deleted_entry);
334 339
335 void DestroyInvalidEntry(EntryImpl* entry); 340 void DestroyInvalidEntry(EntryImpl* entry);
336 341
337 // Handles the used storage count. 342 // Handles the used storage count.
338 void AddStorageSize(int32 bytes); 343 void AddStorageSize(int32_t bytes);
339 void SubstractStorageSize(int32 bytes); 344 void SubstractStorageSize(int32_t bytes);
340 345
341 // Update the number of referenced cache entries. 346 // Update the number of referenced cache entries.
342 void IncreaseNumRefs(); 347 void IncreaseNumRefs();
343 void DecreaseNumRefs(); 348 void DecreaseNumRefs();
344 void IncreaseNumEntries(); 349 void IncreaseNumEntries();
345 void DecreaseNumEntries(); 350 void DecreaseNumEntries();
346 351
347 // Dumps current cache statistics to the log. 352 // Dumps current cache statistics to the log.
348 void LogStats(); 353 void LogStats();
349 354
(...skipping 14 matching lines...) Expand all
364 369
365 // Returns the maximum total memory for the memory buffers. 370 // Returns the maximum total memory for the memory buffers.
366 int MaxBuffersSize(); 371 int MaxBuffersSize();
367 372
368 InFlightBackendIO background_queue_; // The controller of pending operations. 373 InFlightBackendIO background_queue_; // The controller of pending operations.
369 scoped_refptr<MappedFile> index_; // The main cache index. 374 scoped_refptr<MappedFile> index_; // The main cache index.
370 base::FilePath path_; // Path to the folder used as backing storage. 375 base::FilePath path_; // Path to the folder used as backing storage.
371 Index* data_; // Pointer to the index data. 376 Index* data_; // Pointer to the index data.
372 BlockFiles block_files_; // Set of files used to store all data. 377 BlockFiles block_files_; // Set of files used to store all data.
373 Rankings rankings_; // Rankings to be able to trim the cache. 378 Rankings rankings_; // Rankings to be able to trim the cache.
374 uint32 mask_; // Binary mask to map a hash to the hash table. 379 uint32_t mask_; // Binary mask to map a hash to the hash table.
375 int32 max_size_; // Maximum data size for this instance. 380 int32_t max_size_; // Maximum data size for this instance.
376 Eviction eviction_; // Handler of the eviction algorithm. 381 Eviction eviction_; // Handler of the eviction algorithm.
377 EntriesMap open_entries_; // Map of open entries. 382 EntriesMap open_entries_; // Map of open entries.
378 int num_refs_; // Number of referenced cache entries. 383 int num_refs_; // Number of referenced cache entries.
379 int max_refs_; // Max number of referenced cache entries. 384 int max_refs_; // Max number of referenced cache entries.
380 int num_pending_io_; // Number of pending IO operations. 385 int num_pending_io_; // Number of pending IO operations.
381 int entry_count_; // Number of entries accessed lately. 386 int entry_count_; // Number of entries accessed lately.
382 int byte_count_; // Number of bytes read/written lately. 387 int byte_count_; // Number of bytes read/written lately.
383 int buffer_bytes_; // Total size of the temporary entries' buffers. 388 int buffer_bytes_; // Total size of the temporary entries' buffers.
384 int up_ticks_; // The number of timer ticks received (OnStatsTimer). 389 int up_ticks_; // The number of timer ticks received (OnStatsTimer).
385 net::CacheType cache_type_; 390 net::CacheType cache_type_;
386 int uma_report_; // Controls transmission of UMA data. 391 int uma_report_; // Controls transmission of UMA data.
387 uint32 user_flags_; // Flags set by the user. 392 uint32_t user_flags_; // Flags set by the user.
388 bool init_; // controls the initialization of the system. 393 bool init_; // controls the initialization of the system.
389 bool restarted_; 394 bool restarted_;
390 bool unit_test_; 395 bool unit_test_;
391 bool read_only_; // Prevents updates of the rankings data (used by tools). 396 bool read_only_; // Prevents updates of the rankings data (used by tools).
392 bool disabled_; 397 bool disabled_;
393 bool new_eviction_; // What eviction algorithm should be used. 398 bool new_eviction_; // What eviction algorithm should be used.
394 bool first_timer_; // True if the timer has not been called. 399 bool first_timer_; // True if the timer has not been called.
395 bool user_load_; // True if we see a high load coming from the caller. 400 bool user_load_; // True if we see a high load coming from the caller.
396 401
397 net::NetLog* net_log_; 402 net::NetLog* net_log_;
398 403
399 Stats stats_; // Usage statistics. 404 Stats stats_; // Usage statistics.
400 scoped_ptr<base::RepeatingTimer> timer_; // Usage timer. 405 scoped_ptr<base::RepeatingTimer> timer_; // Usage timer.
401 base::WaitableEvent done_; // Signals the end of background work. 406 base::WaitableEvent done_; // Signals the end of background work.
402 scoped_refptr<TraceObject> trace_object_; // Initializes internal tracing. 407 scoped_refptr<TraceObject> trace_object_; // Initializes internal tracing.
403 base::WeakPtrFactory<BackendImpl> ptr_factory_; 408 base::WeakPtrFactory<BackendImpl> ptr_factory_;
404 409
405 DISALLOW_COPY_AND_ASSIGN(BackendImpl); 410 DISALLOW_COPY_AND_ASSIGN(BackendImpl);
406 }; 411 };
407 412
408 } // namespace disk_cache 413 } // namespace disk_cache
409 414
410 #endif // NET_DISK_CACHE_BLOCKFILE_BACKEND_IMPL_H_ 415 #endif // NET_DISK_CACHE_BLOCKFILE_BACKEND_IMPL_H_
OLDNEW
« no previous file with comments | « media/audio/audio_output_controller.cc ('k') | net/disk_cache/blockfile/backend_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698