| 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> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 // It is currently a work in progress, missing many features of a real cache, | 23 // It is currently a work in progress, missing many features of a real cache, |
| 24 // such as eviction. | 24 // such as eviction. |
| 25 | 25 |
| 26 // See http://www.chromium.org/developers/design-documents/network-stack/disk-ca
che/very-simple-backend | 26 // See http://www.chromium.org/developers/design-documents/network-stack/disk-ca
che/very-simple-backend |
| 27 | 27 |
| 28 class SimpleIndex; | 28 class SimpleIndex; |
| 29 | 29 |
| 30 class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend { | 30 class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend { |
| 31 public: | 31 public: |
| 32 SimpleBackendImpl(const base::FilePath& path, int max_bytes, |
| 33 net::CacheType type, |
| 34 const scoped_refptr<base::TaskRunner>& cache_thread, |
| 35 net::NetLog* net_log); |
| 36 |
| 37 int Init(const CompletionCallback& callback); |
| 38 |
| 32 virtual ~SimpleBackendImpl(); | 39 virtual ~SimpleBackendImpl(); |
| 33 | 40 |
| 34 static int CreateBackend(const base::FilePath& full_path, | |
| 35 int max_bytes, | |
| 36 net::CacheType type, | |
| 37 uint32 flags, | |
| 38 scoped_refptr<base::TaskRunner> cache_thread, | |
| 39 net::NetLog* net_log, | |
| 40 Backend** backend, | |
| 41 const CompletionCallback& callback); | |
| 42 | |
| 43 // From Backend: | 41 // From Backend: |
| 44 virtual net::CacheType GetCacheType() const OVERRIDE; | 42 virtual net::CacheType GetCacheType() const OVERRIDE; |
| 45 virtual int32 GetEntryCount() const OVERRIDE; | 43 virtual int32 GetEntryCount() const OVERRIDE; |
| 46 virtual int OpenEntry(const std::string& key, Entry** entry, | 44 virtual int OpenEntry(const std::string& key, Entry** entry, |
| 47 const CompletionCallback& callback) OVERRIDE; | 45 const CompletionCallback& callback) OVERRIDE; |
| 48 virtual int CreateEntry(const std::string& key, Entry** entry, | 46 virtual int CreateEntry(const std::string& key, Entry** entry, |
| 49 const CompletionCallback& callback) OVERRIDE; | 47 const CompletionCallback& callback) OVERRIDE; |
| 50 virtual int DoomEntry(const std::string& key, | 48 virtual int DoomEntry(const std::string& key, |
| 51 const CompletionCallback& callback) OVERRIDE; | 49 const CompletionCallback& callback) OVERRIDE; |
| 52 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE; | 50 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE; |
| 53 virtual int DoomEntriesBetween(base::Time initial_time, | 51 virtual int DoomEntriesBetween(base::Time initial_time, |
| 54 base::Time end_time, | 52 base::Time end_time, |
| 55 const CompletionCallback& callback) OVERRIDE; | 53 const CompletionCallback& callback) OVERRIDE; |
| 56 virtual int DoomEntriesSince(base::Time initial_time, | 54 virtual int DoomEntriesSince(base::Time initial_time, |
| 57 const CompletionCallback& callback) OVERRIDE; | 55 const CompletionCallback& callback) OVERRIDE; |
| 58 virtual int OpenNextEntry(void** iter, Entry** next_entry, | 56 virtual int OpenNextEntry(void** iter, Entry** next_entry, |
| 59 const CompletionCallback& callback) OVERRIDE; | 57 const CompletionCallback& callback) OVERRIDE; |
| 60 virtual void EndEnumeration(void** iter) OVERRIDE; | 58 virtual void EndEnumeration(void** iter) OVERRIDE; |
| 61 virtual void GetStats( | 59 virtual void GetStats( |
| 62 std::vector<std::pair<std::string, std::string> >* stats) OVERRIDE; | 60 std::vector<std::pair<std::string, std::string> >* stats) OVERRIDE; |
| 63 virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; | 61 virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; |
| 64 | 62 |
| 65 private: | 63 private: |
| 66 SimpleBackendImpl( | |
| 67 const scoped_refptr<base::TaskRunner>& cache_thread, | |
| 68 const base::FilePath& path); | |
| 69 | |
| 70 // Creates the Cache directory if needed. Performs blocking IO, so it cannot | |
| 71 // be called on IO thread. | |
| 72 static void EnsureCachePathExists( | |
| 73 const base::FilePath& path, | |
| 74 const scoped_refptr<base::TaskRunner>& cache_thread, | |
| 75 const scoped_refptr<base::TaskRunner>& io_thread, | |
| 76 const CompletionCallback& callback, | |
| 77 Backend** backend); | |
| 78 | |
| 79 // Must run on Cache Thread. | 64 // Must run on Cache Thread. |
| 80 void Initialize(); | 65 void InitializeIndex(base::MessageLoopProxy* io_thread, |
| 66 const CompletionCallback& callback); |
| 81 | 67 |
| 82 const base::FilePath path_; | 68 const base::FilePath path_; |
| 83 | 69 |
| 84 scoped_ptr<SimpleIndex> index_; | 70 scoped_ptr<SimpleIndex> index_; |
| 71 const scoped_refptr<base::TaskRunner> cache_thread_; |
| 85 }; | 72 }; |
| 86 | 73 |
| 87 } // namespace disk_cache | 74 } // namespace disk_cache |
| 88 | 75 |
| 89 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ | 76 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ |
| OLD | NEW |