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

Side by Side Diff: chrome/browser/chromeos/drive/file_cache_metadata.h

Issue 16338005: drive: Remove FakeCacheMetadata (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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
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 CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_METADATA_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_METADATA_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_METADATA_H_ 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_METADATA_H_
7 7
8 #include <map>
9 #include <string> 8 #include <string>
10 #include <vector> 9 #include <vector>
11 10
12 #include "base/callback_forward.h" 11 #include "base/callback_forward.h"
13 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
14 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
16 15
17 namespace base { 16 namespace base {
17 class SequencedTaskRunner;
18 } // namespace base
18 19
19 class SequencedTaskRunner; 20 namespace leveldb {
20 21 class DB;
21 } // namespace base 22 } // namespace leveldb
22 23
23 namespace drive { 24 namespace drive {
24 25
25 class FileCacheEntry; 26 class FileCacheEntry;
26 27
27 // Callback for Iterate(). 28 // Callback for Iterate().
28 typedef base::Callback<void(const std::string& resource_id, 29 typedef base::Callback<void(const std::string& resource_id,
29 const FileCacheEntry& cache_entry)> 30 const FileCacheEntry& cache_entry)>
30 CacheIterateCallback; 31 CacheIterateCallback;
31 32
32 namespace internal { 33 namespace internal {
33 34
34 // FileCacheMetadata is interface to maintain metadata of FileCache's cached 35 // FileCacheMetadata maintains metadata of FileCache's cached files.
35 // files. This class only manages metadata. File operations are done by 36 // This class only manages metadata. File operations are done by FileCache.
36 // FileCache.
37 // All member access including ctor and dtor must be made on the blocking pool. 37 // All member access including ctor and dtor must be made on the blocking pool.
38 class FileCacheMetadata { 38 class FileCacheMetadata {
39 public: 39 public:
40 // A map table of cache file's resource id to its FileCacheEntry* entry.
41 typedef std::map<std::string, FileCacheEntry> CacheMap;
42
43 // Database path. 40 // Database path.
44 static const base::FilePath::CharType* kCacheMetadataDBPath; 41 static const base::FilePath::CharType* kCacheMetadataDBPath;
45 42
43 explicit FileCacheMetadata(base::SequencedTaskRunner* blocking_task_runner);
kinaba 2013/06/04 06:24:46 Could you add a comment that NULL is allowed durin
hashimoto 2013/06/04 06:30:38 Done.
44
46 virtual ~FileCacheMetadata(); 45 virtual ~FileCacheMetadata();
kinaba 2013/06/04 06:24:46 You can drop virtual here, too.
hashimoto 2013/06/04 06:30:38 Done.
47 46
48 // Creates FileCacheMetadata instance.
49 static scoped_ptr<FileCacheMetadata> CreateCacheMetadata(
50 base::SequencedTaskRunner* blocking_task_runner);
51
52 // Creates FileCacheMetadata instance. This uses FakeCacheMetadata,
53 // which is an in-memory implementation and faster than FileCacheMetadataDB.
54 static scoped_ptr<FileCacheMetadata> CreateCacheMetadataForTesting(
55 base::SequencedTaskRunner* blocking_task_runner);
56
57 // Initialize the cache metadata store. Returns true on success. 47 // Initialize the cache metadata store. Returns true on success.
58 virtual bool Initialize(const std::vector<base::FilePath>& cache_paths) = 0; 48 bool Initialize(const std::vector<base::FilePath>& cache_paths);
59 // Adds a new cache entry corresponding to |resource_id| if it doesn't 49 // Adds a new cache entry corresponding to |resource_id| if it doesn't
60 // exist, otherwise update the existing entry. 50 // exist, otherwise update the existing entry.
61 virtual void AddOrUpdateCacheEntry(const std::string& resource_id, 51 void AddOrUpdateCacheEntry(const std::string& resource_id,
62 const FileCacheEntry& cache_entry) = 0; 52 const FileCacheEntry& cache_entry);
63 53
64 // Removes entry corresponding to |resource_id| from cache map. 54 // Removes entry corresponding to |resource_id| from cache map.
65 virtual void RemoveCacheEntry(const std::string& resource_id) = 0; 55 void RemoveCacheEntry(const std::string& resource_id);
66 56
67 // Gets the cache entry for file corresponding to |resource_id| and |md5| 57 // Gets the cache entry for file corresponding to |resource_id| and |md5|
68 // and returns true if entry exists in cache map. Otherwise, returns false. 58 // and returns true if entry exists in cache map. Otherwise, returns false.
69 // |md5| can be empty if only matching |resource_id| is desired. 59 // |md5| can be empty if only matching |resource_id| is desired.
70 virtual bool GetCacheEntry(const std::string& resource_id, 60 bool GetCacheEntry(const std::string& resource_id,
71 const std::string& md5, 61 const std::string& md5,
72 FileCacheEntry* entry) = 0; 62 FileCacheEntry* entry);
73 63
74 // Removes temporary files (files in CACHE_TYPE_TMP) from the cache map. 64 // Removes temporary files (files in CACHE_TYPE_TMP) from the cache map.
75 virtual void RemoveTemporaryFiles() = 0; 65 void RemoveTemporaryFiles();
76 66
77 // Iterates over all the cache entries synchronously. |callback| is called 67 // Iterates over all the cache entries synchronously. |callback| is called
78 // on each cache entry. 68 // on each cache entry.
79 virtual void Iterate(const CacheIterateCallback& callback) = 0; 69 void Iterate(const CacheIterateCallback& callback);
80 70
81 protected: 71 private:
82 explicit FileCacheMetadata(base::SequencedTaskRunner* blocking_task_runner);
83
84 // Checks whether the current thread is on the right sequenced worker pool 72 // Checks whether the current thread is on the right sequenced worker pool
85 // with the right sequence ID. If not, DCHECK will fail. 73 // with the right sequence ID. If not, DCHECK will fail.
86 void AssertOnSequencedWorkerPool(); 74 void AssertOnSequencedWorkerPool();
87 75
88 private:
89 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 76 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
77 scoped_ptr<leveldb::DB> level_db_;
90 78
91 DISALLOW_COPY_AND_ASSIGN(FileCacheMetadata); 79 DISALLOW_COPY_AND_ASSIGN(FileCacheMetadata);
92 }; 80 };
93 81
94 } // namespace internal 82 } // namespace internal
95 } // namespace drive 83 } // namespace drive
96 84
97 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_METADATA_H_ 85 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_METADATA_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_cache.cc ('k') | chrome/browser/chromeos/drive/file_cache_metadata.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698