| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/appcache/appcache_service.h" | 5 #include "webkit/browser/appcache/appcache_service.h" |
| 6 | 6 |
| 7 #include <functional> | 7 #include <functional> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } | 136 } |
| 137 | 137 |
| 138 virtual void Start() OVERRIDE { | 138 virtual void Start() OVERRIDE { |
| 139 service_->storage()->LoadOrCreateGroup(manifest_url_, this); | 139 service_->storage()->LoadOrCreateGroup(manifest_url_, this); |
| 140 } | 140 } |
| 141 | 141 |
| 142 private: | 142 private: |
| 143 // AppCacheStorage::Delegate implementation. | 143 // AppCacheStorage::Delegate implementation. |
| 144 virtual void OnGroupLoaded( | 144 virtual void OnGroupLoaded( |
| 145 appcache::AppCacheGroup* group, const GURL& manifest_url) OVERRIDE; | 145 appcache::AppCacheGroup* group, const GURL& manifest_url) OVERRIDE; |
| 146 virtual void OnGroupMadeObsolete( | 146 virtual void OnGroupMadeObsolete(appcache::AppCacheGroup* group, |
| 147 appcache::AppCacheGroup* group, bool success) OVERRIDE; | 147 bool success, |
| 148 int response_code) OVERRIDE; |
| 148 | 149 |
| 149 GURL manifest_url_; | 150 GURL manifest_url_; |
| 150 DISALLOW_COPY_AND_ASSIGN(DeleteHelper); | 151 DISALLOW_COPY_AND_ASSIGN(DeleteHelper); |
| 151 }; | 152 }; |
| 152 | 153 |
| 153 void AppCacheService::DeleteHelper::OnGroupLoaded( | 154 void AppCacheService::DeleteHelper::OnGroupLoaded( |
| 154 appcache::AppCacheGroup* group, const GURL& manifest_url) { | 155 appcache::AppCacheGroup* group, const GURL& manifest_url) { |
| 155 if (group) { | 156 if (group) { |
| 156 group->set_being_deleted(true); | 157 group->set_being_deleted(true); |
| 157 group->CancelUpdate(); | 158 group->CancelUpdate(); |
| 158 service_->storage()->MakeGroupObsolete(group, this); | 159 service_->storage()->MakeGroupObsolete(group, this, 0); |
| 159 } else { | 160 } else { |
| 160 CallCallback(net::ERR_FAILED); | 161 CallCallback(net::ERR_FAILED); |
| 161 delete this; | 162 delete this; |
| 162 } | 163 } |
| 163 } | 164 } |
| 164 | 165 |
| 165 void AppCacheService::DeleteHelper::OnGroupMadeObsolete( | 166 void AppCacheService::DeleteHelper::OnGroupMadeObsolete( |
| 166 appcache::AppCacheGroup* group, bool success) { | 167 appcache::AppCacheGroup* group, |
| 168 bool success, |
| 169 int response_code) { |
| 167 CallCallback(success ? net::OK : net::ERR_FAILED); | 170 CallCallback(success ? net::OK : net::ERR_FAILED); |
| 168 delete this; | 171 delete this; |
| 169 } | 172 } |
| 170 | 173 |
| 171 // DeleteOriginHelper ------- | 174 // DeleteOriginHelper ------- |
| 172 | 175 |
| 173 class AppCacheService::DeleteOriginHelper : public AsyncHelper { | 176 class AppCacheService::DeleteOriginHelper : public AsyncHelper { |
| 174 public: | 177 public: |
| 175 DeleteOriginHelper( | 178 DeleteOriginHelper( |
| 176 AppCacheService* service, const GURL& origin, | 179 AppCacheService* service, const GURL& origin, |
| 177 const net::CompletionCallback& callback) | 180 const net::CompletionCallback& callback) |
| 178 : AsyncHelper(service, callback), origin_(origin), | 181 : AsyncHelper(service, callback), origin_(origin), |
| 179 num_caches_to_delete_(0), successes_(0), failures_(0) { | 182 num_caches_to_delete_(0), successes_(0), failures_(0) { |
| 180 } | 183 } |
| 181 | 184 |
| 182 virtual void Start() OVERRIDE { | 185 virtual void Start() OVERRIDE { |
| 183 // We start by listing all caches, continues in OnAllInfo(). | 186 // We start by listing all caches, continues in OnAllInfo(). |
| 184 service_->storage()->GetAllInfo(this); | 187 service_->storage()->GetAllInfo(this); |
| 185 } | 188 } |
| 186 | 189 |
| 187 private: | 190 private: |
| 188 // AppCacheStorage::Delegate implementation. | 191 // AppCacheStorage::Delegate implementation. |
| 189 virtual void OnAllInfo(AppCacheInfoCollection* collection) OVERRIDE; | 192 virtual void OnAllInfo(AppCacheInfoCollection* collection) OVERRIDE; |
| 190 virtual void OnGroupLoaded( | 193 virtual void OnGroupLoaded( |
| 191 appcache::AppCacheGroup* group, const GURL& manifest_url) OVERRIDE; | 194 appcache::AppCacheGroup* group, const GURL& manifest_url) OVERRIDE; |
| 192 virtual void OnGroupMadeObsolete( | 195 virtual void OnGroupMadeObsolete(appcache::AppCacheGroup* group, |
| 193 appcache::AppCacheGroup* group, bool success) OVERRIDE; | 196 bool success, |
| 197 int response_code) OVERRIDE; |
| 194 | 198 |
| 195 void CacheCompleted(bool success); | 199 void CacheCompleted(bool success); |
| 196 | 200 |
| 197 GURL origin_; | 201 GURL origin_; |
| 198 int num_caches_to_delete_; | 202 int num_caches_to_delete_; |
| 199 int successes_; | 203 int successes_; |
| 200 int failures_; | 204 int failures_; |
| 201 | 205 |
| 202 DISALLOW_COPY_AND_ASSIGN(DeleteOriginHelper); | 206 DISALLOW_COPY_AND_ASSIGN(DeleteOriginHelper); |
| 203 }; | 207 }; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 229 iter != caches_to_delete.end(); ++iter) { | 233 iter != caches_to_delete.end(); ++iter) { |
| 230 service_->storage()->LoadOrCreateGroup(iter->manifest_url, this); | 234 service_->storage()->LoadOrCreateGroup(iter->manifest_url, this); |
| 231 } | 235 } |
| 232 } | 236 } |
| 233 | 237 |
| 234 void AppCacheService::DeleteOriginHelper::OnGroupLoaded( | 238 void AppCacheService::DeleteOriginHelper::OnGroupLoaded( |
| 235 appcache::AppCacheGroup* group, const GURL& manifest_url) { | 239 appcache::AppCacheGroup* group, const GURL& manifest_url) { |
| 236 if (group) { | 240 if (group) { |
| 237 group->set_being_deleted(true); | 241 group->set_being_deleted(true); |
| 238 group->CancelUpdate(); | 242 group->CancelUpdate(); |
| 239 service_->storage()->MakeGroupObsolete(group, this); | 243 service_->storage()->MakeGroupObsolete(group, this, 0); |
| 240 } else { | 244 } else { |
| 241 CacheCompleted(false); | 245 CacheCompleted(false); |
| 242 } | 246 } |
| 243 } | 247 } |
| 244 | 248 |
| 245 void AppCacheService::DeleteOriginHelper::OnGroupMadeObsolete( | 249 void AppCacheService::DeleteOriginHelper::OnGroupMadeObsolete( |
| 246 appcache::AppCacheGroup* group, bool success) { | 250 appcache::AppCacheGroup* group, |
| 251 bool success, |
| 252 int response_code) { |
| 247 CacheCompleted(success); | 253 CacheCompleted(success); |
| 248 } | 254 } |
| 249 | 255 |
| 250 void AppCacheService::DeleteOriginHelper::CacheCompleted(bool success) { | 256 void AppCacheService::DeleteOriginHelper::CacheCompleted(bool success) { |
| 251 if (success) | 257 if (success) |
| 252 ++successes_; | 258 ++successes_; |
| 253 else | 259 else |
| 254 ++failures_; | 260 ++failures_; |
| 255 if ((successes_ + failures_) < num_caches_to_delete_) | 261 if ((successes_ + failures_) < num_caches_to_delete_) |
| 256 return; | 262 return; |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 backends_.insert( | 567 backends_.insert( |
| 562 BackendMap::value_type(backend_impl->process_id(), backend_impl)); | 568 BackendMap::value_type(backend_impl->process_id(), backend_impl)); |
| 563 } | 569 } |
| 564 | 570 |
| 565 void AppCacheService::UnregisterBackend( | 571 void AppCacheService::UnregisterBackend( |
| 566 AppCacheBackendImpl* backend_impl) { | 572 AppCacheBackendImpl* backend_impl) { |
| 567 backends_.erase(backend_impl->process_id()); | 573 backends_.erase(backend_impl->process_id()); |
| 568 } | 574 } |
| 569 | 575 |
| 570 } // namespace appcache | 576 } // namespace appcache |
| OLD | NEW |