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_entry.h" |
11 #include "webkit/appcache/appcache_storage_impl.h" | 12 #include "webkit/appcache/appcache_storage_impl.h" |
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 |
(...skipping 32 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, |
| 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_; |
| 87 DISALLOW_COPY_AND_ASSIGN(CanHandleOfflineHelper); |
| 88 }; |
| 89 |
| 90 void AppCacheService::CanHandleOfflineHelper::OnMainResponseFound( |
| 91 const GURL& url, const AppCacheEntry& entry, |
| 92 const GURL& fallback_url, const AppCacheEntry& fallback_entry, |
| 93 int64 cache_id, const GURL& mainfest_url, |
| 94 bool was_blocked_by_policy) { |
| 95 bool can = !was_blocked_by_policy && |
| 96 (entry.has_response_id() || fallback_entry.has_response_id()); |
| 97 CallCallback(can ? net::OK : net::ERR_FAILED); |
| 98 delete this; |
| 99 } |
| 100 |
63 // DeleteHelper ------- | 101 // DeleteHelper ------- |
64 | 102 |
65 class AppCacheService::DeleteHelper : public AsyncHelper { | 103 class AppCacheService::DeleteHelper : public AsyncHelper { |
66 public: | 104 public: |
67 DeleteHelper( | 105 DeleteHelper( |
68 AppCacheService* service, const GURL& manifest_url, | 106 AppCacheService* service, const GURL& manifest_url, |
69 net::CompletionCallback* callback) | 107 net::CompletionCallback* callback) |
70 : AsyncHelper(service, callback), manifest_url_(manifest_url) { | 108 : AsyncHelper(service, callback), manifest_url_(manifest_url) { |
71 } | 109 } |
72 | 110 |
73 virtual void Start() { | 111 virtual void Start() { |
74 service_->storage()->LoadOrCreateGroup(manifest_url_, this); | 112 service_->storage()->LoadOrCreateGroup(manifest_url_, this); |
75 } | 113 } |
76 | 114 |
77 private: | 115 private: |
78 // AppCacheStorage::Delegate methods | 116 // AppCacheStorage::Delegate methods |
79 virtual void OnGroupLoaded( | 117 virtual void OnGroupLoaded( |
80 appcache::AppCacheGroup* group, const GURL& manifest_url); | 118 appcache::AppCacheGroup* group, const GURL& manifest_url); |
81 virtual void OnGroupMadeObsolete( | 119 virtual void OnGroupMadeObsolete( |
82 appcache::AppCacheGroup* group, bool success); | 120 appcache::AppCacheGroup* group, bool success); |
83 | 121 |
84 GURL manifest_url_; | 122 GURL manifest_url_; |
| 123 DISALLOW_COPY_AND_ASSIGN(DeleteHelper); |
85 }; | 124 }; |
86 | 125 |
87 void AppCacheService::DeleteHelper::OnGroupLoaded( | 126 void AppCacheService::DeleteHelper::OnGroupLoaded( |
88 appcache::AppCacheGroup* group, const GURL& manifest_url) { | 127 appcache::AppCacheGroup* group, const GURL& manifest_url) { |
89 if (group) { | 128 if (group) { |
90 group->set_being_deleted(true); | 129 group->set_being_deleted(true); |
91 group->CancelUpdate(); | 130 group->CancelUpdate(); |
92 service_->storage()->MakeGroupObsolete(group, this); | 131 service_->storage()->MakeGroupObsolete(group, this); |
93 } else { | 132 } else { |
94 CallCallback(net::ERR_FAILED); | 133 CallCallback(net::ERR_FAILED); |
(...skipping 19 matching lines...) Expand all Loading... |
114 | 153 |
115 virtual void Start() { | 154 virtual void Start() { |
116 service_->storage()->GetAllInfo(this); | 155 service_->storage()->GetAllInfo(this); |
117 } | 156 } |
118 | 157 |
119 private: | 158 private: |
120 // AppCacheStorage::Delegate override | 159 // AppCacheStorage::Delegate override |
121 virtual void OnAllInfo(AppCacheInfoCollection* collection); | 160 virtual void OnAllInfo(AppCacheInfoCollection* collection); |
122 | 161 |
123 scoped_refptr<AppCacheInfoCollection> collection_; | 162 scoped_refptr<AppCacheInfoCollection> collection_; |
| 163 DISALLOW_COPY_AND_ASSIGN(GetInfoHelper); |
124 }; | 164 }; |
125 | 165 |
126 void AppCacheService::GetInfoHelper::OnAllInfo( | 166 void AppCacheService::GetInfoHelper::OnAllInfo( |
127 AppCacheInfoCollection* collection) { | 167 AppCacheInfoCollection* collection) { |
128 if (collection) | 168 if (collection) |
129 collection->infos_by_origin.swap(collection_->infos_by_origin); | 169 collection->infos_by_origin.swap(collection_->infos_by_origin); |
130 CallCallback(collection ? net::OK : net::ERR_FAILED); | 170 CallCallback(collection ? net::OK : net::ERR_FAILED); |
131 delete this; | 171 delete this; |
132 } | 172 } |
133 | 173 |
(...skipping 14 matching lines...) Expand all Loading... |
148 } | 188 } |
149 | 189 |
150 void AppCacheService::Initialize(const FilePath& cache_directory, | 190 void AppCacheService::Initialize(const FilePath& cache_directory, |
151 base::MessageLoopProxy* cache_thread) { | 191 base::MessageLoopProxy* cache_thread) { |
152 DCHECK(!storage_.get()); | 192 DCHECK(!storage_.get()); |
153 AppCacheStorageImpl* storage = new AppCacheStorageImpl(this); | 193 AppCacheStorageImpl* storage = new AppCacheStorageImpl(this); |
154 storage->Initialize(cache_directory, cache_thread); | 194 storage->Initialize(cache_directory, cache_thread); |
155 storage_.reset(storage); | 195 storage_.reset(storage); |
156 } | 196 } |
157 | 197 |
| 198 void AppCacheService::CanHandleMainResourceOffline( |
| 199 const GURL& url, |
| 200 net::CompletionCallback* callback) { |
| 201 CanHandleOfflineHelper* helper = |
| 202 new CanHandleOfflineHelper(this, url, callback); |
| 203 helper->Start(); |
| 204 } |
| 205 |
158 void AppCacheService::GetAllAppCacheInfo(AppCacheInfoCollection* collection, | 206 void AppCacheService::GetAllAppCacheInfo(AppCacheInfoCollection* collection, |
159 net::CompletionCallback* callback) { | 207 net::CompletionCallback* callback) { |
160 DCHECK(collection); | 208 DCHECK(collection); |
161 GetInfoHelper* helper = new GetInfoHelper(this, collection, callback); | 209 GetInfoHelper* helper = new GetInfoHelper(this, collection, callback); |
162 helper->Start(); | 210 helper->Start(); |
163 } | 211 } |
164 | 212 |
165 void AppCacheService::DeleteAppCacheGroup(const GURL& manifest_url, | 213 void AppCacheService::DeleteAppCacheGroup(const GURL& manifest_url, |
166 net::CompletionCallback* callback) { | 214 net::CompletionCallback* callback) { |
167 DeleteHelper* helper = new DeleteHelper(this, manifest_url, callback); | 215 DeleteHelper* helper = new DeleteHelper(this, manifest_url, callback); |
168 helper->Start(); | 216 helper->Start(); |
169 } | 217 } |
170 | 218 |
171 void AppCacheService::RegisterBackend( | 219 void AppCacheService::RegisterBackend( |
172 AppCacheBackendImpl* backend_impl) { | 220 AppCacheBackendImpl* backend_impl) { |
173 DCHECK(backends_.find(backend_impl->process_id()) == backends_.end()); | 221 DCHECK(backends_.find(backend_impl->process_id()) == backends_.end()); |
174 backends_.insert( | 222 backends_.insert( |
175 BackendMap::value_type(backend_impl->process_id(), backend_impl)); | 223 BackendMap::value_type(backend_impl->process_id(), backend_impl)); |
176 } | 224 } |
177 | 225 |
178 void AppCacheService::UnregisterBackend( | 226 void AppCacheService::UnregisterBackend( |
179 AppCacheBackendImpl* backend_impl) { | 227 AppCacheBackendImpl* backend_impl) { |
180 backends_.erase(backend_impl->process_id()); | 228 backends_.erase(backend_impl->process_id()); |
181 } | 229 } |
182 | 230 |
183 } // namespace appcache | 231 } // namespace appcache |
OLD | NEW |