OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ | 5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ |
6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ | 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/task_runner.h" | 14 #include "base/task_runner.h" |
15 #include "net/base/cache_type.h" | 15 #include "net/base/cache_type.h" |
16 #include "net/disk_cache/disk_cache.h" | 16 #include "net/disk_cache/disk_cache.h" |
17 | 17 |
18 namespace base { | |
19 class MessageLoopProxy; | |
20 } | |
21 | |
18 namespace disk_cache { | 22 namespace disk_cache { |
19 | 23 |
20 // SimpleBackendImpl is a new cache backend that stores entries in individual | 24 // SimpleBackendImpl is a new cache backend that stores entries in individual |
21 // files. | 25 // files. |
22 | 26 |
23 // It is currently a work in progress, missing many features of a real cache, | 27 // It is currently a work in progress, missing many features of a real cache, |
24 // such as eviction. | 28 // such as eviction. |
25 | 29 |
26 // See http://www.chromium.org/developers/design-documents/network-stack/disk-ca che/very-simple-backend | 30 // See http://www.chromium.org/developers/design-documents/network-stack/disk-ca che/very-simple-backend |
27 | 31 |
28 class SimpleIndex; | 32 class SimpleIndex; |
29 | 33 |
30 class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend { | 34 class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend { |
31 public: | 35 public: |
32 SimpleBackendImpl(const base::FilePath& path, int max_bytes, | 36 SimpleBackendImpl(const base::FilePath& path, int max_bytes, |
33 net::CacheType type, | 37 net::CacheType type, |
34 const scoped_refptr<base::TaskRunner>& cache_thread, | 38 const scoped_refptr<base::TaskRunner>& cache_thread, |
35 net::NetLog* net_log); | 39 net::NetLog* net_log); |
36 | 40 |
37 int Init(const CompletionCallback& callback); | 41 int Init(const CompletionCallback& completition_callback); |
gavinp
2013/04/11 09:56:32
Nit: spelling (in the method too).
felipeg
2013/04/11 11:25:45
Done.
| |
38 | 42 |
39 virtual ~SimpleBackendImpl(); | 43 virtual ~SimpleBackendImpl(); |
40 | 44 |
41 // From Backend: | 45 // From Backend: |
42 virtual net::CacheType GetCacheType() const OVERRIDE; | 46 virtual net::CacheType GetCacheType() const OVERRIDE; |
43 virtual int32 GetEntryCount() const OVERRIDE; | 47 virtual int32 GetEntryCount() const OVERRIDE; |
44 virtual int OpenEntry(const std::string& key, Entry** entry, | 48 virtual int OpenEntry(const std::string& key, Entry** entry, |
45 const CompletionCallback& callback) OVERRIDE; | 49 const CompletionCallback& callback) OVERRIDE; |
46 virtual int CreateEntry(const std::string& key, Entry** entry, | 50 virtual int CreateEntry(const std::string& key, Entry** entry, |
47 const CompletionCallback& callback) OVERRIDE; | 51 const CompletionCallback& callback) OVERRIDE; |
48 virtual int DoomEntry(const std::string& key, | 52 virtual int DoomEntry(const std::string& key, |
49 const CompletionCallback& callback) OVERRIDE; | 53 const CompletionCallback& callback) OVERRIDE; |
50 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE; | 54 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE; |
51 virtual int DoomEntriesBetween(base::Time initial_time, | 55 virtual int DoomEntriesBetween(base::Time initial_time, |
52 base::Time end_time, | 56 base::Time end_time, |
53 const CompletionCallback& callback) OVERRIDE; | 57 const CompletionCallback& callback) OVERRIDE; |
54 virtual int DoomEntriesSince(base::Time initial_time, | 58 virtual int DoomEntriesSince(base::Time initial_time, |
55 const CompletionCallback& callback) OVERRIDE; | 59 const CompletionCallback& callback) OVERRIDE; |
56 virtual int OpenNextEntry(void** iter, Entry** next_entry, | 60 virtual int OpenNextEntry(void** iter, Entry** next_entry, |
57 const CompletionCallback& callback) OVERRIDE; | 61 const CompletionCallback& callback) OVERRIDE; |
58 virtual void EndEnumeration(void** iter) OVERRIDE; | 62 virtual void EndEnumeration(void** iter) OVERRIDE; |
59 virtual void GetStats( | 63 virtual void GetStats( |
60 std::vector<std::pair<std::string, std::string> >* stats) OVERRIDE; | 64 std::vector<std::pair<std::string, std::string> >* stats) OVERRIDE; |
61 virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; | 65 virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; |
62 | 66 |
63 private: | 67 private: |
64 // Must run on Cache Thread. | 68 typedef base::Callback<void(int)> InitializeIndexCallback; |
gavinp
2013/04/11 09:56:32
How about naming the int? Call it "result" or io_r
felipeg
2013/04/11 11:25:45
Done.
| |
65 void InitializeIndex(base::MessageLoopProxy* io_thread, | 69 |
66 const CompletionCallback& callback); | 70 void InitializeIndex(const CompletionCallback& callback, int rv); |
pasko-google - do not use
2013/04/10 17:51:01
Should probably comment that this should run on th
felipeg
2013/04/11 09:41:35
Done.
gavinp
2013/04/11 09:56:32
Does every method on this class now run on the IO
gavinp
2013/04/11 09:56:32
rv isn't a good name for an argument; it's more t
felipeg
2013/04/11 11:25:45
Done.
| |
71 | |
72 static void CreateDirectory( | |
pasko-google - do not use
2013/04/10 17:51:01
I would rather call it EnsureDirectoryConsistent()
felipeg
2013/04/11 09:41:35
Done.
| |
73 base::MessageLoopProxy* io_thread, | |
74 const base::FilePath& path, | |
75 const InitializeIndexCallback& initialize_index_callback); | |
67 | 76 |
68 const base::FilePath path_; | 77 const base::FilePath path_; |
69 | |
70 scoped_ptr<SimpleIndex> index_; | 78 scoped_ptr<SimpleIndex> index_; |
71 const scoped_refptr<base::TaskRunner> cache_thread_; | 79 const scoped_refptr<base::TaskRunner> cache_thread_; |
72 }; | 80 }; |
73 | 81 |
74 } // namespace disk_cache | 82 } // namespace disk_cache |
75 | 83 |
76 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ | 84 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ |
OLD | NEW |