| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/appcache/appcache.h" | 9 #include "webkit/appcache/appcache.h" | 
| 10 #include "webkit/appcache/appcache_backend_impl.h" | 10 #include "webkit/appcache/appcache_backend_impl.h" | 
| 11 #include "webkit/appcache/appcache_request_handler.h" | 11 #include "webkit/appcache/appcache_request_handler.h" | 
| 12 | 12 | 
| 13 namespace appcache { | 13 namespace appcache { | 
| 14 | 14 | 
|  | 15 namespace { | 
|  | 16 | 
|  | 17 void FillCacheInfo( | 
|  | 18     const AppCache* cache, Status status, AppCacheInfo* info) { | 
|  | 19   DCHECK(cache); | 
|  | 20   info->cache_id = cache->cache_id(); | 
|  | 21   info->status = status; | 
|  | 22   info->is_complete = cache->is_complete(); | 
|  | 23   if (info->is_complete) { | 
|  | 24     info->manifest_url = cache->owning_group()->manifest_url(); | 
|  | 25     info->last_update_time = cache->update_time(); | 
|  | 26     info->creation_time = cache->owning_group()->creation_time(); | 
|  | 27     info->size = cache->cache_size(); | 
|  | 28   } | 
|  | 29 } | 
|  | 30 | 
|  | 31 }  // Anonymous namespace | 
|  | 32 | 
| 15 AppCacheHost::AppCacheHost(int host_id, AppCacheFrontend* frontend, | 33 AppCacheHost::AppCacheHost(int host_id, AppCacheFrontend* frontend, | 
| 16                            AppCacheService* service) | 34                            AppCacheService* service) | 
| 17     : host_id_(host_id), parent_host_id_(kNoHostId), parent_process_id_(0), | 35     : host_id_(host_id), parent_host_id_(kNoHostId), parent_process_id_(0), | 
| 18       pending_main_resource_cache_id_(kNoCacheId), | 36       pending_main_resource_cache_id_(kNoCacheId), | 
| 19       pending_selected_cache_id_(kNoCacheId), | 37       pending_selected_cache_id_(kNoCacheId), | 
| 20       frontend_(frontend), service_(service), | 38       frontend_(frontend), service_(service), | 
| 21       pending_get_status_callback_(NULL), pending_start_update_callback_(NULL), | 39       pending_get_status_callback_(NULL), pending_start_update_callback_(NULL), | 
| 22       pending_swap_cache_callback_(NULL), pending_callback_param_(NULL), | 40       pending_swap_cache_callback_(NULL), pending_callback_param_(NULL), | 
| 23       main_resource_blocked_(false) { | 41       main_resource_blocked_(false), associated_cache_info_pending_(false) { | 
| 24 } | 42 } | 
| 25 | 43 | 
| 26 AppCacheHost::~AppCacheHost() { | 44 AppCacheHost::~AppCacheHost() { | 
| 27   FOR_EACH_OBSERVER(Observer, observers_, OnDestructionImminent(this)); | 45   FOR_EACH_OBSERVER(Observer, observers_, OnDestructionImminent(this)); | 
| 28   if (associated_cache_.get()) | 46   if (associated_cache_.get()) | 
| 29     associated_cache_->UnassociateHost(this); | 47     associated_cache_->UnassociateHost(this); | 
| 30   if (group_being_updated_.get()) | 48   if (group_being_updated_.get()) | 
| 31     group_being_updated_->RemoveUpdateObserver(this); | 49     group_being_updated_->RemoveUpdateObserver(this); | 
| 32   service_->storage()->CancelDelegateCallbacks(this); | 50   service_->storage()->CancelDelegateCallbacks(this); | 
| 33 } | 51 } | 
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 389 | 407 | 
| 390 void AppCacheHost::OnUpdateComplete(AppCacheGroup* group) { | 408 void AppCacheHost::OnUpdateComplete(AppCacheGroup* group) { | 
| 391   DCHECK_EQ(group, group_being_updated_); | 409   DCHECK_EQ(group, group_being_updated_); | 
| 392   group->RemoveUpdateObserver(this); | 410   group->RemoveUpdateObserver(this); | 
| 393 | 411 | 
| 394   // Add a reference to the newest complete cache. | 412   // Add a reference to the newest complete cache. | 
| 395   SetSwappableCache(group); | 413   SetSwappableCache(group); | 
| 396 | 414 | 
| 397   group_being_updated_ = NULL; | 415   group_being_updated_ = NULL; | 
| 398   newest_cache_of_group_being_updated_ = NULL; | 416   newest_cache_of_group_being_updated_ = NULL; | 
|  | 417 | 
|  | 418   if (associated_cache_info_pending_ && associated_cache_.get() && | 
|  | 419       associated_cache_->is_complete()) { | 
|  | 420     AppCacheInfo info; | 
|  | 421     FillCacheInfo(associated_cache_.get(), GetStatus(), &info); | 
|  | 422     associated_cache_info_pending_ = false; | 
|  | 423     frontend_->OnCacheSelected(host_id_, info); | 
|  | 424   } | 
| 399 } | 425 } | 
| 400 | 426 | 
| 401 void AppCacheHost::OnContentBlocked(AppCacheGroup* group) { | 427 void AppCacheHost::OnContentBlocked(AppCacheGroup* group) { | 
| 402   frontend_->OnContentBlocked(host_id_, group->manifest_url()); | 428   frontend_->OnContentBlocked(host_id_, group->manifest_url()); | 
| 403 } | 429 } | 
| 404 | 430 | 
| 405 void AppCacheHost::SetSwappableCache(AppCacheGroup* group) { | 431 void AppCacheHost::SetSwappableCache(AppCacheGroup* group) { | 
| 406   if (!group) { | 432   if (!group) { | 
| 407     swappable_cache_ = NULL; | 433     swappable_cache_ = NULL; | 
| 408   } else { | 434   } else { | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
| 429   blocked_manifest_url_ = manifest_url; | 455   blocked_manifest_url_ = manifest_url; | 
| 430 } | 456 } | 
| 431 | 457 | 
| 432 void AppCacheHost::AssociateCache(AppCache* cache) { | 458 void AppCacheHost::AssociateCache(AppCache* cache) { | 
| 433   if (associated_cache_.get()) { | 459   if (associated_cache_.get()) { | 
| 434     associated_cache_->UnassociateHost(this); | 460     associated_cache_->UnassociateHost(this); | 
| 435   } | 461   } | 
| 436 | 462 | 
| 437   associated_cache_ = cache; | 463   associated_cache_ = cache; | 
| 438   SetSwappableCache(cache ? cache->owning_group() : NULL); | 464   SetSwappableCache(cache ? cache->owning_group() : NULL); | 
|  | 465   associated_cache_info_pending_ = cache && !cache->is_complete(); | 
| 439   AppCacheInfo info; | 466   AppCacheInfo info; | 
| 440   if (cache) { | 467   if (cache) { | 
| 441     cache->AssociateHost(this); | 468     cache->AssociateHost(this); | 
| 442     info.cache_id = cache->cache_id(); | 469     FillCacheInfo(cache, GetStatus(), &info); | 
| 443     info.status = GetStatus(); |  | 
| 444     info.is_complete = cache->is_complete(); |  | 
| 445     if (cache->is_complete()) { |  | 
| 446       // TODO(kkanetkar): Get manifest URL info for NULL owning_group(). |  | 
| 447       info.manifest_url = cache->owning_group()->manifest_url(); |  | 
| 448       info.last_update_time = cache->update_time(); |  | 
| 449       info.creation_time = cache->owning_group()->creation_time(); |  | 
| 450       info.size = cache->cache_size(); |  | 
| 451     } |  | 
| 452     frontend_->OnCacheSelected(host_id_, info); |  | 
| 453   } else { |  | 
| 454     // No Cache. |  | 
| 455     frontend_->OnCacheSelected(host_id_, info); |  | 
| 456   } | 470   } | 
|  | 471   frontend_->OnCacheSelected(host_id_, info); | 
| 457 } | 472 } | 
| 458 | 473 | 
| 459 }  // namespace appcache | 474 }  // namespace appcache | 
| OLD | NEW | 
|---|