| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 WEBKIT_APPCACHE_APPCACHE_DISK_CACHE_H_ | 5 #ifndef WEBKIT_APPCACHE_APPCACHE_DISK_CACHE_H_ |
| 6 #define WEBKIT_APPCACHE_APPCACHE_DISK_CACHE_H_ | 6 #define WEBKIT_APPCACHE_APPCACHE_DISK_CACHE_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "net/disk_cache/disk_cache.h" | 12 #include "net/disk_cache/disk_cache.h" |
| 13 #include "webkit/appcache/appcache_export.h" | 13 #include "webkit/appcache/appcache_export.h" |
| 14 #include "webkit/appcache/appcache_response.h" | 14 #include "webkit/appcache/appcache_response.h" |
| 15 | 15 |
| 16 namespace appcache { | 16 namespace appcache { |
| 17 | 17 |
| 18 // An implementation of AppCacheDiskCacheInterface that | 18 // An implementation of AppCacheDiskCacheInterface that |
| 19 // uses net::DiskCache as the backing store. | 19 // uses net::DiskCache as the backing store. |
| 20 class APPCACHE_EXPORT AppCacheDiskCache | 20 class APPCACHE_EXPORT AppCacheDiskCache |
| 21 : public AppCacheDiskCacheInterface { | 21 : public AppCacheDiskCacheInterface { |
| 22 public: | 22 public: |
| 23 AppCacheDiskCache(); | 23 AppCacheDiskCache(); |
| 24 virtual ~AppCacheDiskCache(); | 24 virtual ~AppCacheDiskCache(); |
| 25 | 25 |
| 26 // Initializes the object to use disk backed storage. | 26 // Initializes the object to use disk backed storage. |
| 27 int InitWithDiskBackend(const FilePath& disk_cache_directory, | 27 int InitWithDiskBackend(const FilePath& disk_cache_directory, |
| 28 int disk_cache_size, bool force, | 28 int disk_cache_size, bool force, |
| 29 base::MessageLoopProxy* cache_thread, | 29 base::MessageLoopProxy* cache_thread, |
| 30 net::OldCompletionCallback* callback); | 30 const net::CompletionCallback& callback); |
| 31 | 31 |
| 32 // Initializes the object to use memory only storage. | 32 // Initializes the object to use memory only storage. |
| 33 // This is used for Chrome's incognito browsing. | 33 // This is used for Chrome's incognito browsing. |
| 34 int InitWithMemBackend(int disk_cache_size, | 34 int InitWithMemBackend(int disk_cache_size, |
| 35 net::OldCompletionCallback* callback); | 35 const net::CompletionCallback& callback); |
| 36 | 36 |
| 37 void Disable(); | 37 void Disable(); |
| 38 bool is_disabled() const { return is_disabled_; } | 38 bool is_disabled() const { return is_disabled_; } |
| 39 | 39 |
| 40 virtual int CreateEntry(int64 key, Entry** entry, | 40 virtual int CreateEntry(int64 key, Entry** entry, |
| 41 net::OldCompletionCallback* callback) OVERRIDE; | 41 const net::CompletionCallback& callback) OVERRIDE; |
| 42 virtual int OpenEntry(int64 key, Entry** entry, | 42 virtual int OpenEntry(int64 key, Entry** entry, |
| 43 net::OldCompletionCallback* callback) OVERRIDE; | 43 const net::CompletionCallback& callback) OVERRIDE; |
| 44 virtual int DoomEntry(int64 key, | 44 virtual int DoomEntry(int64 key, |
| 45 net::OldCompletionCallback* callback) OVERRIDE; | 45 const net::CompletionCallback& callback) OVERRIDE; |
| 46 | 46 |
| 47 private: | 47 private: |
| 48 class EntryImpl; | 48 class EntryImpl; |
| 49 | 49 |
| 50 class CreateBackendCallback | 50 class CreateBackendCallback |
| 51 : public net::CancelableOldCompletionCallback<AppCacheDiskCache> { | 51 : public net::CancelableOldCompletionCallback<AppCacheDiskCache> { |
| 52 public: | 52 public: |
| 53 typedef net::CancelableOldCompletionCallback<AppCacheDiskCache> BaseClass; | 53 typedef net::CancelableOldCompletionCallback<AppCacheDiskCache> BaseClass; |
| 54 CreateBackendCallback(AppCacheDiskCache* object, | 54 CreateBackendCallback(AppCacheDiskCache* object, |
| 55 void (AppCacheDiskCache::* method)(int)) | 55 void (AppCacheDiskCache::* method)(int)) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 69 // really ready to go. | 69 // really ready to go. |
| 70 enum PendingCallType { | 70 enum PendingCallType { |
| 71 CREATE, | 71 CREATE, |
| 72 OPEN, | 72 OPEN, |
| 73 DOOM | 73 DOOM |
| 74 }; | 74 }; |
| 75 struct PendingCall { | 75 struct PendingCall { |
| 76 PendingCallType call_type; | 76 PendingCallType call_type; |
| 77 int64 key; | 77 int64 key; |
| 78 Entry** entry; | 78 Entry** entry; |
| 79 net::OldCompletionCallback* callback; | 79 net::CompletionCallback callback; |
| 80 | 80 |
| 81 PendingCall() | 81 PendingCall() |
| 82 : call_type(CREATE), key(0), entry(NULL), callback(NULL) {} | 82 : call_type(CREATE), |
| 83 key(0), |
| 84 entry(NULL) { |
| 85 } |
| 86 |
| 83 PendingCall(PendingCallType call_type, int64 key, | 87 PendingCall(PendingCallType call_type, int64 key, |
| 84 Entry** entry, net::OldCompletionCallback* callback) | 88 Entry** entry, const net::CompletionCallback& callback) |
| 85 : call_type(call_type), key(key), entry(entry), callback(callback) {} | 89 : call_type(call_type), |
| 90 key(key), |
| 91 entry(entry), |
| 92 callback(callback) { |
| 93 } |
| 94 |
| 95 ~PendingCall(); |
| 86 }; | 96 }; |
| 87 typedef std::vector<PendingCall> PendingCalls; | 97 typedef std::vector<PendingCall> PendingCalls; |
| 88 | 98 |
| 89 class ActiveCall; | 99 class ActiveCall; |
| 90 typedef std::set<ActiveCall*> ActiveCalls; | 100 typedef std::set<ActiveCall*> ActiveCalls; |
| 91 | 101 |
| 92 bool is_initializing() const { | 102 bool is_initializing() const { |
| 93 return create_backend_callback_.get() != NULL; | 103 return create_backend_callback_.get() != NULL; |
| 94 } | 104 } |
| 95 disk_cache::Backend* disk_cache() { return disk_cache_.get(); } | 105 disk_cache::Backend* disk_cache() { return disk_cache_.get(); } |
| 96 int Init(net::CacheType cache_type, const FilePath& directory, | 106 int Init(net::CacheType cache_type, const FilePath& directory, |
| 97 int cache_size, bool force, base::MessageLoopProxy* cache_thread, | 107 int cache_size, bool force, base::MessageLoopProxy* cache_thread, |
| 98 net::OldCompletionCallback* callback); | 108 const net::CompletionCallback& callback); |
| 99 void OnCreateBackendComplete(int rv); | 109 void OnCreateBackendComplete(int rv); |
| 100 void AddActiveCall(ActiveCall* call) { active_calls_.insert(call); } | 110 void AddActiveCall(ActiveCall* call) { active_calls_.insert(call); } |
| 101 void RemoveActiveCall(ActiveCall* call) { active_calls_.erase(call); } | 111 void RemoveActiveCall(ActiveCall* call) { active_calls_.erase(call); } |
| 102 | 112 |
| 103 bool is_disabled_; | 113 bool is_disabled_; |
| 104 net::OldCompletionCallback* init_callback_; | 114 net::CompletionCallback init_callback_; |
| 105 scoped_refptr<CreateBackendCallback> create_backend_callback_; | 115 scoped_refptr<CreateBackendCallback> create_backend_callback_; |
| 106 PendingCalls pending_calls_; | 116 PendingCalls pending_calls_; |
| 107 ActiveCalls active_calls_; | 117 ActiveCalls active_calls_; |
| 108 scoped_ptr<disk_cache::Backend> disk_cache_; | 118 scoped_ptr<disk_cache::Backend> disk_cache_; |
| 109 }; | 119 }; |
| 110 | 120 |
| 111 } // namespace appcache | 121 } // namespace appcache |
| 112 | 122 |
| 113 #endif // WEBKIT_APPCACHE_APPCACHE_DISK_CACHE_H_ | 123 #endif // WEBKIT_APPCACHE_APPCACHE_DISK_CACHE_H_ |
| 114 | 124 |
| OLD | NEW |