OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_BACKEND_IMPL_H_ | 5 #ifndef WEBKIT_APPCACHE_APPCACHE_BACKEND_IMPL_H_ |
6 #define WEBKIT_APPCACHE_APPCACHE_BACKEND_IMPL_H_ | 6 #define WEBKIT_APPCACHE_APPCACHE_BACKEND_IMPL_H_ |
7 | 7 |
8 #include <map> | |
9 | |
10 #include "base/logging.h" | 8 #include "base/logging.h" |
11 #include "base/task.h" | 9 #include "base/hash_tables.h" |
12 #include "webkit/appcache/appcache_host.h" | 10 #include "webkit/appcache/appcache_host.h" |
13 #include "webkit/appcache/appcache_interfaces.h" | |
14 | 11 |
15 namespace appcache { | 12 namespace appcache { |
16 | 13 |
17 class AppCacheService; | 14 class AppCacheService; |
18 | 15 |
19 typedef Callback2<Status, void*>::Type GetStatusCallback; | 16 class AppCacheBackendImpl { |
20 typedef Callback2<bool, void*>::Type StartUpdateCallback; | |
21 typedef Callback2<bool, void*>::Type SwapCacheCallback; | |
22 | |
23 class AppCacheBackendImpl : public AppCacheBackend { | |
24 public: | 17 public: |
25 AppCacheBackendImpl() : service_(NULL), frontend_(NULL), process_id_(0) {} | 18 AppCacheBackendImpl() : service_(NULL), frontend_(NULL), process_id_(0) {} |
26 ~AppCacheBackendImpl(); | 19 ~AppCacheBackendImpl(); |
27 | 20 |
28 void Initialize(AppCacheService* service, | 21 void Initialize(AppCacheService* service, |
29 AppCacheFrontend* frontend, | 22 AppCacheFrontend* frontend, |
30 int process_id); | 23 int process_id); |
31 | 24 |
32 int process_id() const { return process_id_; } | 25 int process_id() const { return process_id_; } |
33 | 26 |
| 27 // Methods to support the AppCacheBackend interface. A false return |
| 28 // value indicates an invalid host_id and that no action was taken |
| 29 // by the backend impl. |
| 30 bool RegisterHost(int host_id); |
| 31 bool UnregisterHost(int host_id); |
| 32 bool SelectCache(int host_id, |
| 33 const GURL& document_url, |
| 34 const int64 cache_document_was_loaded_from, |
| 35 const GURL& manifest_url); |
| 36 bool MarkAsForeignEntry(int host_id, const GURL& document_url, |
| 37 int64 cache_document_was_loaded_from); |
| 38 bool GetStatusWithCallback(int host_id, GetStatusCallback* callback, |
| 39 void* callback_param); |
| 40 bool StartUpdateWithCallback(int host_id, StartUpdateCallback* callback, |
| 41 void* callback_param); |
| 42 bool SwapCacheWithCallback(int host_id, SwapCacheCallback* callback, |
| 43 void* callback_param); |
| 44 |
34 // Returns a pointer to a registered host. The backend retains ownership. | 45 // Returns a pointer to a registered host. The backend retains ownership. |
35 AppCacheHost* GetHost(int host_id) { | 46 AppCacheHost* GetHost(int host_id) { |
36 HostMap::iterator it = hosts_.find(host_id); | 47 HostMap::iterator it = hosts_.find(host_id); |
37 return (it != hosts_.end()) ? &(it->second) : NULL; | 48 return (it != hosts_.end()) ? (it->second) : NULL; |
38 } | 49 } |
39 | 50 |
40 typedef std::map<int, AppCacheHost> HostMap; | 51 typedef base::hash_map<int, AppCacheHost*> HostMap; |
41 const HostMap& hosts() { return hosts_; } | 52 const HostMap& hosts() { return hosts_; } |
42 | 53 |
43 // AppCacheBackend methods | |
44 virtual void RegisterHost(int host_id); | |
45 virtual void UnregisterHost(int host_id); | |
46 virtual void SelectCache(int host_id, | |
47 const GURL& document_url, | |
48 const int64 cache_document_was_loaded_from, | |
49 const GURL& manifest_url); | |
50 virtual void MarkAsForeignEntry(int host_id, const GURL& document_url, | |
51 int64 cache_document_was_loaded_from); | |
52 | |
53 // We don't use the sync variants in the backend, would block the IO thread. | |
54 virtual Status GetStatus(int host_id) { NOTREACHED(); return UNCACHED; } | |
55 virtual bool StartUpdate(int host_id) { NOTREACHED(); return false; } | |
56 virtual bool SwapCache(int host_id) { NOTREACHED(); return false; } | |
57 | |
58 // Async variants of the sync methods defined in the backend interface. | |
59 void GetStatusWithCallback(int host_id, GetStatusCallback* callback, | |
60 void* callback_param); | |
61 void StartUpdateWithCallback(int host_id, StartUpdateCallback* callback, | |
62 void* callback_param); | |
63 void SwapCacheWithCallback(int host_id, SwapCacheCallback* callback, | |
64 void* callback_param); | |
65 | |
66 private: | 54 private: |
67 AppCacheService* service_; | 55 AppCacheService* service_; |
68 AppCacheFrontend* frontend_; | 56 AppCacheFrontend* frontend_; |
69 int process_id_; | 57 int process_id_; |
70 HostMap hosts_; | 58 HostMap hosts_; |
71 }; | 59 }; |
72 | 60 |
73 } // namespace | 61 } // namespace |
74 | 62 |
75 #endif // WEBKIT_APPCACHE_APPCACHE_BACKEND_IMPL_H_ | 63 #endif // WEBKIT_APPCACHE_APPCACHE_BACKEND_IMPL_H_ |
OLD | NEW |