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

Side by Side Diff: net/disk_cache/simple/simple_backend_impl.h

Issue 13839011: Asynchronous initialization in Simple Index. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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
« no previous file with comments | « no previous file | net/disk_cache/simple/simple_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) 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 virtual ~SimpleBackendImpl();
38 42
39 virtual ~SimpleBackendImpl(); 43 // Must run on IO Thread.
44 int Init(const CompletionCallback& completion_callback);
40 45
41 // From Backend: 46 // From Backend:
42 virtual net::CacheType GetCacheType() const OVERRIDE; 47 virtual net::CacheType GetCacheType() const OVERRIDE;
43 virtual int32 GetEntryCount() const OVERRIDE; 48 virtual int32 GetEntryCount() const OVERRIDE;
44 virtual int OpenEntry(const std::string& key, Entry** entry, 49 virtual int OpenEntry(const std::string& key, Entry** entry,
45 const CompletionCallback& callback) OVERRIDE; 50 const CompletionCallback& callback) OVERRIDE;
46 virtual int CreateEntry(const std::string& key, Entry** entry, 51 virtual int CreateEntry(const std::string& key, Entry** entry,
47 const CompletionCallback& callback) OVERRIDE; 52 const CompletionCallback& callback) OVERRIDE;
48 virtual int DoomEntry(const std::string& key, 53 virtual int DoomEntry(const std::string& key,
49 const CompletionCallback& callback) OVERRIDE; 54 const CompletionCallback& callback) OVERRIDE;
50 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE; 55 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE;
51 virtual int DoomEntriesBetween(base::Time initial_time, 56 virtual int DoomEntriesBetween(base::Time initial_time,
52 base::Time end_time, 57 base::Time end_time,
53 const CompletionCallback& callback) OVERRIDE; 58 const CompletionCallback& callback) OVERRIDE;
54 virtual int DoomEntriesSince(base::Time initial_time, 59 virtual int DoomEntriesSince(base::Time initial_time,
55 const CompletionCallback& callback) OVERRIDE; 60 const CompletionCallback& callback) OVERRIDE;
56 virtual int OpenNextEntry(void** iter, Entry** next_entry, 61 virtual int OpenNextEntry(void** iter, Entry** next_entry,
57 const CompletionCallback& callback) OVERRIDE; 62 const CompletionCallback& callback) OVERRIDE;
58 virtual void EndEnumeration(void** iter) OVERRIDE; 63 virtual void EndEnumeration(void** iter) OVERRIDE;
59 virtual void GetStats( 64 virtual void GetStats(
60 std::vector<std::pair<std::string, std::string> >* stats) OVERRIDE; 65 std::vector<std::pair<std::string, std::string> >* stats) OVERRIDE;
61 virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; 66 virtual void OnExternalCacheHit(const std::string& key) OVERRIDE;
62 67
63 private: 68 private:
69 typedef base::Callback<void(int result)> InitializeIndexCallback;
70
71 // Must run on IO Thread.
72 void InitializeIndex(const CompletionCallback& callback, int result);
73
74 // Try to create the directory if it doesn't exist.
64 // Must run on Cache Thread. 75 // Must run on Cache Thread.
65 void InitializeIndex(base::MessageLoopProxy* io_thread, 76 static void CreateDirectory(
66 const CompletionCallback& callback); 77 base::MessageLoopProxy* io_thread,
78 const base::FilePath& path,
79 const InitializeIndexCallback& initialize_index_callback);
67 80
68 const base::FilePath path_; 81 const base::FilePath path_;
69
70 scoped_ptr<SimpleIndex> index_; 82 scoped_ptr<SimpleIndex> index_;
71 const scoped_refptr<base::TaskRunner> cache_thread_; 83 const scoped_refptr<base::TaskRunner> cache_thread_;
72 }; 84 };
73 85
74 } // namespace disk_cache 86 } // namespace disk_cache
75 87
76 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ 88 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/simple/simple_backend_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698