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 #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" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 CallCallback(can ? net::OK : net::ERR_FAILED); | 103 CallCallback(can ? net::OK : net::ERR_FAILED); |
104 delete this; | 104 delete this; |
105 } | 105 } |
106 | 106 |
107 // DeleteHelper ------- | 107 // DeleteHelper ------- |
108 | 108 |
109 class AppCacheService::DeleteHelper : public AsyncHelper { | 109 class AppCacheService::DeleteHelper : public AsyncHelper { |
110 public: | 110 public: |
111 DeleteHelper( | 111 DeleteHelper( |
112 AppCacheService* service, const GURL& manifest_url, | 112 AppCacheService* service, const GURL& manifest_url, |
113 net::CompletionCallback* callback) | 113 net::CompletionCallback* callback, bool sync) |
114 : AsyncHelper(service, callback), manifest_url_(manifest_url) { | 114 : AsyncHelper(service, callback), manifest_url_(manifest_url), |
| 115 sync_(sync) { |
115 } | 116 } |
116 | 117 |
117 virtual void Start() { | 118 virtual void Start() { |
118 service_->storage()->LoadOrCreateGroup(manifest_url_, this); | 119 if (sync_) |
| 120 service_->storage()->SyncLoadOrCreateGroup(manifest_url_, this); |
| 121 else |
| 122 service_->storage()->LoadOrCreateGroup(manifest_url_, this); |
119 } | 123 } |
120 | 124 |
121 private: | 125 private: |
122 // AppCacheStorage::Delegate methods | 126 // AppCacheStorage::Delegate methods |
123 virtual void OnGroupLoaded( | 127 virtual void OnGroupLoaded( |
124 appcache::AppCacheGroup* group, const GURL& manifest_url); | 128 appcache::AppCacheGroup* group, const GURL& manifest_url); |
125 virtual void OnGroupMadeObsolete( | 129 virtual void OnGroupMadeObsolete( |
126 appcache::AppCacheGroup* group, bool success); | 130 appcache::AppCacheGroup* group, bool success); |
127 | 131 |
128 GURL manifest_url_; | 132 GURL manifest_url_; |
| 133 bool sync_; |
| 134 |
129 DISALLOW_COPY_AND_ASSIGN(DeleteHelper); | 135 DISALLOW_COPY_AND_ASSIGN(DeleteHelper); |
130 }; | 136 }; |
131 | 137 |
132 void AppCacheService::DeleteHelper::OnGroupLoaded( | 138 void AppCacheService::DeleteHelper::OnGroupLoaded( |
133 appcache::AppCacheGroup* group, const GURL& manifest_url) { | 139 appcache::AppCacheGroup* group, const GURL& manifest_url) { |
134 if (group) { | 140 if (group) { |
135 group->set_being_deleted(true); | 141 group->set_being_deleted(true); |
136 group->CancelUpdate(); | 142 group->CancelUpdate(); |
137 service_->storage()->MakeGroupObsolete(group, this); | 143 if (sync_) |
| 144 service_->storage()->SyncMakeGroupObsolete(group, this); |
| 145 else |
| 146 service_->storage()->MakeGroupObsolete(group, this); |
138 } else { | 147 } else { |
139 CallCallback(net::ERR_FAILED); | 148 if (!sync_) |
| 149 CallCallback(net::ERR_FAILED); |
140 delete this; | 150 delete this; |
141 } | 151 } |
142 } | 152 } |
143 | 153 |
144 void AppCacheService::DeleteHelper::OnGroupMadeObsolete( | 154 void AppCacheService::DeleteHelper::OnGroupMadeObsolete( |
145 appcache::AppCacheGroup* group, bool success) { | 155 appcache::AppCacheGroup* group, bool success) { |
146 CallCallback(success ? net::OK : net::ERR_FAILED); | 156 if (!sync_) |
| 157 CallCallback(success ? net::OK : net::ERR_FAILED); |
147 delete this; | 158 delete this; |
148 } | 159 } |
149 | 160 |
150 // DeleteOriginHelper ------- | 161 // DeleteOriginHelper ------- |
151 | 162 |
152 class AppCacheService::DeleteOriginHelper : public AsyncHelper { | 163 class AppCacheService::DeleteOriginHelper : public AsyncHelper { |
153 public: | 164 public: |
154 DeleteOriginHelper( | 165 DeleteOriginHelper( |
155 AppCacheService* service, const GURL& origin, | 166 AppCacheService* service, const GURL& origin, |
156 net::CompletionCallback* callback) | 167 net::CompletionCallback* callback) |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 delete this; | 247 delete this; |
237 } | 248 } |
238 | 249 |
239 | 250 |
240 // GetInfoHelper ------- | 251 // GetInfoHelper ------- |
241 | 252 |
242 class AppCacheService::GetInfoHelper : AsyncHelper { | 253 class AppCacheService::GetInfoHelper : AsyncHelper { |
243 public: | 254 public: |
244 GetInfoHelper( | 255 GetInfoHelper( |
245 AppCacheService* service, AppCacheInfoCollection* collection, | 256 AppCacheService* service, AppCacheInfoCollection* collection, |
246 net::CompletionCallback* callback) | 257 net::CompletionCallback* callback, bool sync) |
247 : AsyncHelper(service, callback), collection_(collection) { | 258 : AsyncHelper(service, callback), collection_(collection), sync_(sync) { |
248 } | 259 } |
249 | 260 |
250 virtual void Start() { | 261 virtual void Start() { |
251 service_->storage()->GetAllInfo(this); | 262 if (sync_) |
| 263 service_->storage()->SyncGetAllInfo(this); |
| 264 else |
| 265 service_->storage()->GetAllInfo(this); |
252 } | 266 } |
253 | 267 |
254 private: | 268 private: |
255 // AppCacheStorage::Delegate override | 269 // AppCacheStorage::Delegate override |
256 virtual void OnAllInfo(AppCacheInfoCollection* collection); | 270 virtual void OnAllInfo(AppCacheInfoCollection* collection); |
257 | 271 |
258 scoped_refptr<AppCacheInfoCollection> collection_; | 272 scoped_refptr<AppCacheInfoCollection> collection_; |
| 273 bool sync_; |
| 274 |
259 DISALLOW_COPY_AND_ASSIGN(GetInfoHelper); | 275 DISALLOW_COPY_AND_ASSIGN(GetInfoHelper); |
260 }; | 276 }; |
261 | 277 |
262 void AppCacheService::GetInfoHelper::OnAllInfo( | 278 void AppCacheService::GetInfoHelper::OnAllInfo( |
263 AppCacheInfoCollection* collection) { | 279 AppCacheInfoCollection* collection) { |
264 if (collection) | 280 if (collection) |
265 collection->infos_by_origin.swap(collection_->infos_by_origin); | 281 collection->infos_by_origin.swap(collection_->infos_by_origin); |
266 CallCallback(collection ? net::OK : net::ERR_FAILED); | 282 if (!sync_) |
| 283 CallCallback(collection ? net::OK : net::ERR_FAILED); |
267 delete this; | 284 delete this; |
268 } | 285 } |
269 | 286 |
270 | 287 |
271 // AppCacheService ------- | 288 // AppCacheService ------- |
272 | 289 |
273 AppCacheService::AppCacheService(quota::QuotaManagerProxy* quota_manager_proxy) | 290 AppCacheService::AppCacheService(quota::QuotaManagerProxy* quota_manager_proxy) |
274 : appcache_policy_(NULL), quota_client_(NULL), | 291 : appcache_policy_(NULL), quota_client_(NULL), |
275 quota_manager_proxy_(quota_manager_proxy), | 292 quota_manager_proxy_(quota_manager_proxy), |
276 request_context_(NULL) { | 293 request_context_(NULL) { |
(...skipping 25 matching lines...) Expand all Loading... |
302 const GURL& url, | 319 const GURL& url, |
303 net::CompletionCallback* callback) { | 320 net::CompletionCallback* callback) { |
304 CanHandleOfflineHelper* helper = | 321 CanHandleOfflineHelper* helper = |
305 new CanHandleOfflineHelper(this, url, callback); | 322 new CanHandleOfflineHelper(this, url, callback); |
306 helper->Start(); | 323 helper->Start(); |
307 } | 324 } |
308 | 325 |
309 void AppCacheService::GetAllAppCacheInfo(AppCacheInfoCollection* collection, | 326 void AppCacheService::GetAllAppCacheInfo(AppCacheInfoCollection* collection, |
310 net::CompletionCallback* callback) { | 327 net::CompletionCallback* callback) { |
311 DCHECK(collection); | 328 DCHECK(collection); |
312 GetInfoHelper* helper = new GetInfoHelper(this, collection, callback); | 329 GetInfoHelper* helper = new GetInfoHelper(this, collection, callback, false); |
| 330 helper->Start(); |
| 331 } |
| 332 |
| 333 void AppCacheService::SyncGetAllAppCacheInfo( |
| 334 AppCacheInfoCollection* collection) { |
| 335 DCHECK(collection); |
| 336 GetInfoHelper* helper = new GetInfoHelper(this, collection, NULL, true); |
313 helper->Start(); | 337 helper->Start(); |
314 } | 338 } |
315 | 339 |
316 void AppCacheService::DeleteAppCacheGroup(const GURL& manifest_url, | 340 void AppCacheService::DeleteAppCacheGroup(const GURL& manifest_url, |
317 net::CompletionCallback* callback) { | 341 net::CompletionCallback* callback) { |
318 DeleteHelper* helper = new DeleteHelper(this, manifest_url, callback); | 342 DeleteHelper* helper = new DeleteHelper(this, manifest_url, callback, false); |
319 helper->Start(); | 343 helper->Start(); |
320 } | 344 } |
321 | 345 |
| 346 void AppCacheService::SyncDeleteAppCacheGroup(const GURL& manifest_url) { |
| 347 DeleteHelper* helper = new DeleteHelper(this, manifest_url, NULL, true); |
| 348 helper->Start(); |
| 349 } |
| 350 |
322 void AppCacheService::DeleteAppCachesForOrigin( | 351 void AppCacheService::DeleteAppCachesForOrigin( |
323 const GURL& origin, net::CompletionCallback* callback) { | 352 const GURL& origin, net::CompletionCallback* callback) { |
324 DeleteOriginHelper* helper = new DeleteOriginHelper(this, origin, callback); | 353 DeleteOriginHelper* helper = new DeleteOriginHelper(this, origin, callback); |
325 helper->Start(); | 354 helper->Start(); |
326 } | 355 } |
327 | 356 |
328 void AppCacheService::set_special_storage_policy( | 357 void AppCacheService::set_special_storage_policy( |
329 quota::SpecialStoragePolicy* policy) { | 358 quota::SpecialStoragePolicy* policy) { |
330 special_storage_policy_ = policy; | 359 special_storage_policy_ = policy; |
331 } | 360 } |
332 | 361 |
333 void AppCacheService::RegisterBackend( | 362 void AppCacheService::RegisterBackend( |
334 AppCacheBackendImpl* backend_impl) { | 363 AppCacheBackendImpl* backend_impl) { |
335 DCHECK(backends_.find(backend_impl->process_id()) == backends_.end()); | 364 DCHECK(backends_.find(backend_impl->process_id()) == backends_.end()); |
336 backends_.insert( | 365 backends_.insert( |
337 BackendMap::value_type(backend_impl->process_id(), backend_impl)); | 366 BackendMap::value_type(backend_impl->process_id(), backend_impl)); |
338 } | 367 } |
339 | 368 |
340 void AppCacheService::UnregisterBackend( | 369 void AppCacheService::UnregisterBackend( |
341 AppCacheBackendImpl* backend_impl) { | 370 AppCacheBackendImpl* backend_impl) { |
342 backends_.erase(backend_impl->process_id()); | 371 backends_.erase(backend_impl->process_id()); |
343 } | 372 } |
344 | 373 |
345 } // namespace appcache | 374 } // namespace appcache |
OLD | NEW |