| 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_host.h" | 5 #include "webkit/appcache/appcache_host.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "net/url_request/url_request.h" | 10 #include "net/url_request/url_request.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 pending_selected_cache_id_(kNoCacheId), | 51 pending_selected_cache_id_(kNoCacheId), |
| 52 frontend_(frontend), service_(service), | 52 frontend_(frontend), service_(service), |
| 53 pending_callback_param_(NULL), | 53 pending_callback_param_(NULL), |
| 54 main_resource_was_namespace_entry_(false), | 54 main_resource_was_namespace_entry_(false), |
| 55 main_resource_blocked_(false), | 55 main_resource_blocked_(false), |
| 56 associated_cache_info_pending_(false) { | 56 associated_cache_info_pending_(false) { |
| 57 } | 57 } |
| 58 | 58 |
| 59 AppCacheHost::~AppCacheHost() { | 59 AppCacheHost::~AppCacheHost() { |
| 60 FOR_EACH_OBSERVER(Observer, observers_, OnDestructionImminent(this)); | 60 FOR_EACH_OBSERVER(Observer, observers_, OnDestructionImminent(this)); |
| 61 if (associated_cache_) | 61 if (associated_cache_.get()) |
| 62 associated_cache_->UnassociateHost(this); | 62 associated_cache_->UnassociateHost(this); |
| 63 if (group_being_updated_) | 63 if (group_being_updated_.get()) |
| 64 group_being_updated_->RemoveUpdateObserver(this); | 64 group_being_updated_->RemoveUpdateObserver(this); |
| 65 service_->storage()->CancelDelegateCallbacks(this); | 65 service_->storage()->CancelDelegateCallbacks(this); |
| 66 if (service()->quota_manager_proxy() && !origin_in_use_.is_empty()) | 66 if (service()->quota_manager_proxy() && !origin_in_use_.is_empty()) |
| 67 service()->quota_manager_proxy()->NotifyOriginNoLongerInUse(origin_in_use_); | 67 service()->quota_manager_proxy()->NotifyOriginNoLongerInUse(origin_in_use_); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void AppCacheHost::AddObserver(Observer* observer) { | 70 void AppCacheHost::AddObserver(Observer* observer) { |
| 71 observers_.AddObserver(observer); | 71 observers_.AddObserver(observer); |
| 72 } | 72 } |
| 73 | 73 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 return; | 201 return; |
| 202 | 202 |
| 203 DoPendingStartUpdate(); | 203 DoPendingStartUpdate(); |
| 204 } | 204 } |
| 205 | 205 |
| 206 void AppCacheHost::DoPendingStartUpdate() { | 206 void AppCacheHost::DoPendingStartUpdate() { |
| 207 DCHECK_EQ(false, pending_start_update_callback_.is_null()); | 207 DCHECK_EQ(false, pending_start_update_callback_.is_null()); |
| 208 | 208 |
| 209 // 6.9.8 Application cache API | 209 // 6.9.8 Application cache API |
| 210 bool success = false; | 210 bool success = false; |
| 211 if (associated_cache_ && associated_cache_->owning_group()) { | 211 if (associated_cache_.get() && associated_cache_->owning_group()) { |
| 212 AppCacheGroup* group = associated_cache_->owning_group(); | 212 AppCacheGroup* group = associated_cache_->owning_group(); |
| 213 if (!group->is_obsolete() && !group->is_being_deleted()) { | 213 if (!group->is_obsolete() && !group->is_being_deleted()) { |
| 214 success = true; | 214 success = true; |
| 215 group->StartUpdate(); | 215 group->StartUpdate(); |
| 216 } | 216 } |
| 217 } | 217 } |
| 218 | 218 |
| 219 pending_start_update_callback_.Run(success, pending_callback_param_); | 219 pending_start_update_callback_.Run(success, pending_callback_param_); |
| 220 pending_start_update_callback_.Reset(); | 220 pending_start_update_callback_.Reset(); |
| 221 pending_callback_param_ = NULL; | 221 pending_callback_param_ = NULL; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 233 return; | 233 return; |
| 234 | 234 |
| 235 DoPendingSwapCache(); | 235 DoPendingSwapCache(); |
| 236 } | 236 } |
| 237 | 237 |
| 238 void AppCacheHost::DoPendingSwapCache() { | 238 void AppCacheHost::DoPendingSwapCache() { |
| 239 DCHECK_EQ(false, pending_swap_cache_callback_.is_null()); | 239 DCHECK_EQ(false, pending_swap_cache_callback_.is_null()); |
| 240 | 240 |
| 241 // 6.9.8 Application cache API | 241 // 6.9.8 Application cache API |
| 242 bool success = false; | 242 bool success = false; |
| 243 if (associated_cache_ && associated_cache_->owning_group()) { | 243 if (associated_cache_.get() && associated_cache_->owning_group()) { |
| 244 if (associated_cache_->owning_group()->is_obsolete()) { | 244 if (associated_cache_->owning_group()->is_obsolete()) { |
| 245 success = true; | 245 success = true; |
| 246 AssociateNoCache(GURL()); | 246 AssociateNoCache(GURL()); |
| 247 } else if (swappable_cache_) { | 247 } else if (swappable_cache_.get()) { |
| 248 DCHECK(swappable_cache_.get() == | 248 DCHECK(swappable_cache_.get() == |
| 249 swappable_cache_->owning_group()->newest_complete_cache()); | 249 swappable_cache_->owning_group()->newest_complete_cache()); |
| 250 success = true; | 250 success = true; |
| 251 AssociateCompleteCache(swappable_cache_); | 251 AssociateCompleteCache(swappable_cache_.get()); |
| 252 } | 252 } |
| 253 } | 253 } |
| 254 | 254 |
| 255 pending_swap_cache_callback_.Run(success, pending_callback_param_); | 255 pending_swap_cache_callback_.Run(success, pending_callback_param_); |
| 256 pending_swap_cache_callback_.Reset(); | 256 pending_swap_cache_callback_.Reset(); |
| 257 pending_callback_param_ = NULL; | 257 pending_callback_param_ = NULL; |
| 258 } | 258 } |
| 259 | 259 |
| 260 void AppCacheHost::SetSpawningHostId( | 260 void AppCacheHost::SetSpawningHostId( |
| 261 int spawning_process_id, int spawning_host_id) { | 261 int spawning_process_id, int spawning_host_id) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 // during the application cache update process. | 314 // during the application cache update process. |
| 315 if (!cache->owning_group()) | 315 if (!cache->owning_group()) |
| 316 return DOWNLOADING; | 316 return DOWNLOADING; |
| 317 | 317 |
| 318 if (cache->owning_group()->is_obsolete()) | 318 if (cache->owning_group()->is_obsolete()) |
| 319 return OBSOLETE; | 319 return OBSOLETE; |
| 320 if (cache->owning_group()->update_status() == AppCacheGroup::CHECKING) | 320 if (cache->owning_group()->update_status() == AppCacheGroup::CHECKING) |
| 321 return CHECKING; | 321 return CHECKING; |
| 322 if (cache->owning_group()->update_status() == AppCacheGroup::DOWNLOADING) | 322 if (cache->owning_group()->update_status() == AppCacheGroup::DOWNLOADING) |
| 323 return DOWNLOADING; | 323 return DOWNLOADING; |
| 324 if (swappable_cache_) | 324 if (swappable_cache_.get()) |
| 325 return UPDATE_READY; | 325 return UPDATE_READY; |
| 326 return IDLE; | 326 return IDLE; |
| 327 } | 327 } |
| 328 | 328 |
| 329 void AppCacheHost::LoadOrCreateGroup(const GURL& manifest_url) { | 329 void AppCacheHost::LoadOrCreateGroup(const GURL& manifest_url) { |
| 330 DCHECK(manifest_url.is_valid()); | 330 DCHECK(manifest_url.is_valid()); |
| 331 pending_selected_manifest_url_ = manifest_url; | 331 pending_selected_manifest_url_ = manifest_url; |
| 332 service_->storage()->LoadOrCreateGroup(manifest_url, this); | 332 service_->storage()->LoadOrCreateGroup(manifest_url, this); |
| 333 } | 333 } |
| 334 | 334 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 DoPendingGetStatus(); | 411 DoPendingGetStatus(); |
| 412 else if (!pending_start_update_callback_.is_null()) | 412 else if (!pending_start_update_callback_.is_null()) |
| 413 DoPendingStartUpdate(); | 413 DoPendingStartUpdate(); |
| 414 else if (!pending_swap_cache_callback_.is_null()) | 414 else if (!pending_swap_cache_callback_.is_null()) |
| 415 DoPendingSwapCache(); | 415 DoPendingSwapCache(); |
| 416 | 416 |
| 417 FOR_EACH_OBSERVER(Observer, observers_, OnCacheSelectionComplete(this)); | 417 FOR_EACH_OBSERVER(Observer, observers_, OnCacheSelectionComplete(this)); |
| 418 } | 418 } |
| 419 | 419 |
| 420 void AppCacheHost::ObserveGroupBeingUpdated(AppCacheGroup* group) { | 420 void AppCacheHost::ObserveGroupBeingUpdated(AppCacheGroup* group) { |
| 421 DCHECK(!group_being_updated_); | 421 DCHECK(!group_being_updated_.get()); |
| 422 group_being_updated_ = group; | 422 group_being_updated_ = group; |
| 423 newest_cache_of_group_being_updated_ = group->newest_complete_cache(); | 423 newest_cache_of_group_being_updated_ = group->newest_complete_cache(); |
| 424 group->AddUpdateObserver(this); | 424 group->AddUpdateObserver(this); |
| 425 } | 425 } |
| 426 | 426 |
| 427 void AppCacheHost::OnUpdateComplete(AppCacheGroup* group) { | 427 void AppCacheHost::OnUpdateComplete(AppCacheGroup* group) { |
| 428 DCHECK_EQ(group, group_being_updated_); | 428 DCHECK_EQ(group, group_being_updated_); |
| 429 group->RemoveUpdateObserver(this); | 429 group->RemoveUpdateObserver(this); |
| 430 | 430 |
| 431 // Add a reference to the newest complete cache. | 431 // Add a reference to the newest complete cache. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 442 associated_cache_info_pending_ = false; | 442 associated_cache_info_pending_ = false; |
| 443 frontend_->OnCacheSelected(host_id_, info); | 443 frontend_->OnCacheSelected(host_id_, info); |
| 444 } | 444 } |
| 445 } | 445 } |
| 446 | 446 |
| 447 void AppCacheHost::SetSwappableCache(AppCacheGroup* group) { | 447 void AppCacheHost::SetSwappableCache(AppCacheGroup* group) { |
| 448 if (!group) { | 448 if (!group) { |
| 449 swappable_cache_ = NULL; | 449 swappable_cache_ = NULL; |
| 450 } else { | 450 } else { |
| 451 AppCache* new_cache = group->newest_complete_cache(); | 451 AppCache* new_cache = group->newest_complete_cache(); |
| 452 if (new_cache != associated_cache_) | 452 if (new_cache != associated_cache_.get()) |
| 453 swappable_cache_ = new_cache; | 453 swappable_cache_ = new_cache; |
| 454 else | 454 else |
| 455 swappable_cache_ = NULL; | 455 swappable_cache_ = NULL; |
| 456 } | 456 } |
| 457 } | 457 } |
| 458 | 458 |
| 459 void AppCacheHost::LoadMainResourceCache(int64 cache_id) { | 459 void AppCacheHost::LoadMainResourceCache(int64 cache_id) { |
| 460 DCHECK(cache_id != kNoCacheId); | 460 DCHECK(cache_id != kNoCacheId); |
| 461 if (pending_main_resource_cache_id_ == cache_id || | 461 if (pending_main_resource_cache_id_ == cache_id || |
| 462 (main_resource_cache_ && main_resource_cache_->cache_id() == cache_id)) { | 462 (main_resource_cache_.get() && |
| 463 main_resource_cache_->cache_id() == cache_id)) { |
| 463 return; | 464 return; |
| 464 } | 465 } |
| 465 pending_main_resource_cache_id_ = cache_id; | 466 pending_main_resource_cache_id_ = cache_id; |
| 466 service_->storage()->LoadCache(cache_id, this); | 467 service_->storage()->LoadCache(cache_id, this); |
| 467 } | 468 } |
| 468 | 469 |
| 469 void AppCacheHost::NotifyMainResourceIsNamespaceEntry( | 470 void AppCacheHost::NotifyMainResourceIsNamespaceEntry( |
| 470 const GURL& namespace_entry_url) { | 471 const GURL& namespace_entry_url) { |
| 471 main_resource_was_namespace_entry_ = true; | 472 main_resource_was_namespace_entry_ = true; |
| 472 namespace_entry_url_ = namespace_entry_url; | 473 namespace_entry_url_ = namespace_entry_url; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 489 AssociateCacheHelper(cache, manifest_url); | 490 AssociateCacheHelper(cache, manifest_url); |
| 490 } | 491 } |
| 491 | 492 |
| 492 void AppCacheHost::AssociateCompleteCache(AppCache* cache) { | 493 void AppCacheHost::AssociateCompleteCache(AppCache* cache) { |
| 493 DCHECK(cache && cache->is_complete()); | 494 DCHECK(cache && cache->is_complete()); |
| 494 AssociateCacheHelper(cache, cache->owning_group()->manifest_url()); | 495 AssociateCacheHelper(cache, cache->owning_group()->manifest_url()); |
| 495 } | 496 } |
| 496 | 497 |
| 497 void AppCacheHost::AssociateCacheHelper(AppCache* cache, | 498 void AppCacheHost::AssociateCacheHelper(AppCache* cache, |
| 498 const GURL& manifest_url) { | 499 const GURL& manifest_url) { |
| 499 if (associated_cache_) { | 500 if (associated_cache_.get()) { |
| 500 associated_cache_->UnassociateHost(this); | 501 associated_cache_->UnassociateHost(this); |
| 501 } | 502 } |
| 502 | 503 |
| 503 associated_cache_ = cache; | 504 associated_cache_ = cache; |
| 504 SetSwappableCache(cache ? cache->owning_group() : NULL); | 505 SetSwappableCache(cache ? cache->owning_group() : NULL); |
| 505 associated_cache_info_pending_ = cache && !cache->is_complete(); | 506 associated_cache_info_pending_ = cache && !cache->is_complete(); |
| 506 AppCacheInfo info; | 507 AppCacheInfo info; |
| 507 if (cache) | 508 if (cache) |
| 508 cache->AssociateHost(this); | 509 cache->AssociateHost(this); |
| 509 | 510 |
| 510 FillCacheInfo(cache, manifest_url, GetStatus(), &info); | 511 FillCacheInfo(cache, manifest_url, GetStatus(), &info); |
| 511 frontend_->OnCacheSelected(host_id_, info); | 512 frontend_->OnCacheSelected(host_id_, info); |
| 512 } | 513 } |
| 513 | 514 |
| 514 } // namespace appcache | 515 } // namespace appcache |
| OLD | NEW |