OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "webkit/appcache/appcache_service.h" | 5 #include "webkit/appcache/appcache_service.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
10 #include "webkit/appcache/appcache_backend_impl.h" | 10 #include "webkit/appcache/appcache_backend_impl.h" |
11 #include "webkit/appcache/appcache_storage_impl.h" | 11 #include "webkit/appcache/appcache_storage_impl.h" |
12 #include "webkit/appcache/appcache_entry.h" | |
oshima
2011/01/23 15:24:18
sort includes
michaeln
2011/01/24 20:38:34
Done.
| |
12 | 13 |
13 namespace appcache { | 14 namespace appcache { |
14 | 15 |
15 AppCacheInfoCollection::AppCacheInfoCollection() {} | 16 AppCacheInfoCollection::AppCacheInfoCollection() {} |
16 | 17 |
17 AppCacheInfoCollection::~AppCacheInfoCollection() {} | 18 AppCacheInfoCollection::~AppCacheInfoCollection() {} |
18 | 19 |
19 // AsyncHelper ------- | 20 // AsyncHelper ------- |
20 | 21 |
21 class AppCacheService::AsyncHelper | 22 class AppCacheService::AsyncHelper |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 AppCacheService* service_; | 54 AppCacheService* service_; |
54 net::CompletionCallback* callback_; | 55 net::CompletionCallback* callback_; |
55 }; | 56 }; |
56 | 57 |
57 void AppCacheService::AsyncHelper::Cancel() { | 58 void AppCacheService::AsyncHelper::Cancel() { |
58 CallCallback(net::ERR_ABORTED); | 59 CallCallback(net::ERR_ABORTED); |
59 service_->storage()->CancelDelegateCallbacks(this); | 60 service_->storage()->CancelDelegateCallbacks(this); |
60 service_ = NULL; | 61 service_ = NULL; |
61 } | 62 } |
62 | 63 |
64 // CanHandleOfflineHelper ------- | |
65 | |
66 class AppCacheService::CanHandleOfflineHelper : AsyncHelper { | |
67 public: | |
68 CanHandleOfflineHelper( | |
69 AppCacheService* service, const GURL& url, | |
oshima
2011/01/23 15:24:18
looks like arguments can move to above?
michaeln
2011/01/24 20:38:34
The 'callback' param won't fit. In keeping with ho
| |
70 net::CompletionCallback* callback) | |
71 : AsyncHelper(service, callback), url_(url) { | |
72 } | |
73 | |
74 virtual void Start() { | |
75 service_->storage()->FindResponseForMainRequest(url_, this); | |
76 } | |
77 | |
78 private: | |
79 // AppCacheStorage::Delegate override | |
80 virtual void OnMainResponseFound( | |
81 const GURL& url, const AppCacheEntry& entry, | |
82 const GURL& fallback_url, const AppCacheEntry& fallback_entry, | |
83 int64 cache_id, const GURL& mainfest_url, | |
84 bool was_blocked_by_policy); | |
85 | |
86 GURL url_; | |
oshima
2011/01/23 15:24:18
DISALLOW_COPY_AND_ASSIGN
michaeln
2011/01/24 20:38:34
Done (here and in other helpers)
| |
87 }; | |
88 | |
89 void AppCacheService::CanHandleOfflineHelper::OnMainResponseFound( | |
90 const GURL& url, const AppCacheEntry& entry, | |
91 const GURL& fallback_url, const AppCacheEntry& fallback_entry, | |
92 int64 cache_id, const GURL& mainfest_url, | |
93 bool was_blocked_by_policy) { | |
94 bool can = !was_blocked_by_policy && | |
95 (entry.has_response_id() || fallback_entry.has_response_id()); | |
96 CallCallback(can ? net::OK : net::ERR_FAILED); | |
97 delete this; | |
98 } | |
99 | |
63 // DeleteHelper ------- | 100 // DeleteHelper ------- |
64 | 101 |
65 class AppCacheService::DeleteHelper : public AsyncHelper { | 102 class AppCacheService::DeleteHelper : public AsyncHelper { |
66 public: | 103 public: |
67 DeleteHelper( | 104 DeleteHelper( |
68 AppCacheService* service, const GURL& manifest_url, | 105 AppCacheService* service, const GURL& manifest_url, |
69 net::CompletionCallback* callback) | 106 net::CompletionCallback* callback) |
70 : AsyncHelper(service, callback), manifest_url_(manifest_url) { | 107 : AsyncHelper(service, callback), manifest_url_(manifest_url) { |
71 } | 108 } |
72 | 109 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 } | 185 } |
149 | 186 |
150 void AppCacheService::Initialize(const FilePath& cache_directory, | 187 void AppCacheService::Initialize(const FilePath& cache_directory, |
151 base::MessageLoopProxy* cache_thread) { | 188 base::MessageLoopProxy* cache_thread) { |
152 DCHECK(!storage_.get()); | 189 DCHECK(!storage_.get()); |
153 AppCacheStorageImpl* storage = new AppCacheStorageImpl(this); | 190 AppCacheStorageImpl* storage = new AppCacheStorageImpl(this); |
154 storage->Initialize(cache_directory, cache_thread); | 191 storage->Initialize(cache_directory, cache_thread); |
155 storage_.reset(storage); | 192 storage_.reset(storage); |
156 } | 193 } |
157 | 194 |
195 void AppCacheService::CanHandleMainResourceOffline( | |
196 const GURL& url, | |
197 net::CompletionCallback* callback) { | |
198 CanHandleOfflineHelper* helper = | |
199 new CanHandleOfflineHelper(this, url, callback); | |
200 helper->Start(); | |
201 } | |
202 | |
158 void AppCacheService::GetAllAppCacheInfo(AppCacheInfoCollection* collection, | 203 void AppCacheService::GetAllAppCacheInfo(AppCacheInfoCollection* collection, |
159 net::CompletionCallback* callback) { | 204 net::CompletionCallback* callback) { |
160 DCHECK(collection); | 205 DCHECK(collection); |
161 GetInfoHelper* helper = new GetInfoHelper(this, collection, callback); | 206 GetInfoHelper* helper = new GetInfoHelper(this, collection, callback); |
162 helper->Start(); | 207 helper->Start(); |
163 } | 208 } |
164 | 209 |
165 void AppCacheService::DeleteAppCacheGroup(const GURL& manifest_url, | 210 void AppCacheService::DeleteAppCacheGroup(const GURL& manifest_url, |
166 net::CompletionCallback* callback) { | 211 net::CompletionCallback* callback) { |
167 DeleteHelper* helper = new DeleteHelper(this, manifest_url, callback); | 212 DeleteHelper* helper = new DeleteHelper(this, manifest_url, callback); |
168 helper->Start(); | 213 helper->Start(); |
169 } | 214 } |
170 | 215 |
171 void AppCacheService::RegisterBackend( | 216 void AppCacheService::RegisterBackend( |
172 AppCacheBackendImpl* backend_impl) { | 217 AppCacheBackendImpl* backend_impl) { |
173 DCHECK(backends_.find(backend_impl->process_id()) == backends_.end()); | 218 DCHECK(backends_.find(backend_impl->process_id()) == backends_.end()); |
174 backends_.insert( | 219 backends_.insert( |
175 BackendMap::value_type(backend_impl->process_id(), backend_impl)); | 220 BackendMap::value_type(backend_impl->process_id(), backend_impl)); |
176 } | 221 } |
177 | 222 |
178 void AppCacheService::UnregisterBackend( | 223 void AppCacheService::UnregisterBackend( |
179 AppCacheBackendImpl* backend_impl) { | 224 AppCacheBackendImpl* backend_impl) { |
180 backends_.erase(backend_impl->process_id()); | 225 backends_.erase(backend_impl->process_id()); |
181 } | 226 } |
182 | 227 |
183 } // namespace appcache | 228 } // namespace appcache |
OLD | NEW |