| OLD | NEW |
| 1 // Copyright (c) 2010 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 "webkit/appcache/appcache.h" | 10 #include "webkit/appcache/appcache.h" |
| 11 #include "webkit/appcache/appcache_backend_impl.h" | 11 #include "webkit/appcache/appcache_backend_impl.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 26 info->last_update_time = cache->update_time(); | 26 info->last_update_time = cache->update_time(); |
| 27 info->creation_time = cache->owning_group()->creation_time(); | 27 info->creation_time = cache->owning_group()->creation_time(); |
| 28 info->size = cache->cache_size(); | 28 info->size = cache->cache_size(); |
| 29 } | 29 } |
| 30 } | 30 } |
| 31 | 31 |
| 32 } // Anonymous namespace | 32 } // Anonymous namespace |
| 33 | 33 |
| 34 AppCacheHost::AppCacheHost(int host_id, AppCacheFrontend* frontend, | 34 AppCacheHost::AppCacheHost(int host_id, AppCacheFrontend* frontend, |
| 35 AppCacheService* service) | 35 AppCacheService* service) |
| 36 : host_id_(host_id), parent_host_id_(kNoHostId), parent_process_id_(0), | 36 : host_id_(host_id), |
| 37 spawning_host_id_(kNoHostId), spawning_process_id_(0), |
| 38 parent_host_id_(kNoHostId), parent_process_id_(0), |
| 37 pending_main_resource_cache_id_(kNoCacheId), | 39 pending_main_resource_cache_id_(kNoCacheId), |
| 38 pending_selected_cache_id_(kNoCacheId), | 40 pending_selected_cache_id_(kNoCacheId), |
| 39 frontend_(frontend), service_(service), | 41 frontend_(frontend), service_(service), |
| 40 pending_get_status_callback_(NULL), pending_start_update_callback_(NULL), | 42 pending_get_status_callback_(NULL), pending_start_update_callback_(NULL), |
| 41 pending_swap_cache_callback_(NULL), pending_callback_param_(NULL), | 43 pending_swap_cache_callback_(NULL), pending_callback_param_(NULL), |
| 42 main_resource_was_fallback_(false), main_resource_blocked_(false), | 44 main_resource_was_fallback_(false), main_resource_blocked_(false), |
| 43 associated_cache_info_pending_(false) { | 45 associated_cache_info_pending_(false) { |
| 44 } | 46 } |
| 45 | 47 |
| 46 AppCacheHost::~AppCacheHost() { | 48 AppCacheHost::~AppCacheHost() { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 if (cache_document_was_loaded_from != kNoCacheId) { | 84 if (cache_document_was_loaded_from != kNoCacheId) { |
| 83 LoadSelectedCache(cache_document_was_loaded_from); | 85 LoadSelectedCache(cache_document_was_loaded_from); |
| 84 return; | 86 return; |
| 85 } | 87 } |
| 86 | 88 |
| 87 if (!manifest_url.is_empty() && | 89 if (!manifest_url.is_empty() && |
| 88 (manifest_url.GetOrigin() == document_url.GetOrigin())) { | 90 (manifest_url.GetOrigin() == document_url.GetOrigin())) { |
| 89 // Note: The client detects if the document was not loaded using HTTP GET | 91 // Note: The client detects if the document was not loaded using HTTP GET |
| 90 // and invokes SelectCache without a manifest url, so that detection step | 92 // and invokes SelectCache without a manifest url, so that detection step |
| 91 // is also skipped here. See WebApplicationCacheHostImpl.cc | 93 // is also skipped here. See WebApplicationCacheHostImpl.cc |
| 94 set_preferred_manifest_url(manifest_url); |
| 92 new_master_entry_url_ = document_url; | 95 new_master_entry_url_ = document_url; |
| 93 LoadOrCreateGroup(manifest_url); | 96 LoadOrCreateGroup(manifest_url); |
| 94 return; | 97 return; |
| 95 } | 98 } |
| 96 | 99 |
| 97 // TODO(michaeln): If there was a manifest URL, the user agent may report | 100 // TODO(michaeln): If there was a manifest URL, the user agent may report |
| 98 // to the user that it was ignored, to aid in application development. | 101 // to the user that it was ignored, to aid in application development. |
| 99 FinishCacheSelection(NULL, NULL); | 102 FinishCacheSelection(NULL, NULL); |
| 100 } | 103 } |
| 101 | 104 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 } | 226 } |
| 224 } | 227 } |
| 225 | 228 |
| 226 pending_swap_cache_callback_->Run( | 229 pending_swap_cache_callback_->Run( |
| 227 success, pending_callback_param_); | 230 success, pending_callback_param_); |
| 228 | 231 |
| 229 pending_swap_cache_callback_ = NULL; | 232 pending_swap_cache_callback_ = NULL; |
| 230 pending_callback_param_ = NULL; | 233 pending_callback_param_ = NULL; |
| 231 } | 234 } |
| 232 | 235 |
| 236 void AppCacheHost::SetSpawningHostId( |
| 237 int spawning_process_id, int spawning_host_id) { |
| 238 spawning_process_id_ = spawning_process_id; |
| 239 spawning_host_id_ = spawning_host_id; |
| 240 } |
| 241 |
| 242 const AppCacheHost* AppCacheHost::GetSpawningHost() const { |
| 243 AppCacheBackendImpl* backend = service_->GetBackend(spawning_process_id_); |
| 244 return backend ? backend->GetHost(spawning_host_id_) : NULL; |
| 245 } |
| 246 |
| 233 AppCacheHost* AppCacheHost::GetParentAppCacheHost() const { | 247 AppCacheHost* AppCacheHost::GetParentAppCacheHost() const { |
| 234 DCHECK(is_for_dedicated_worker()); | 248 DCHECK(is_for_dedicated_worker()); |
| 235 AppCacheBackendImpl* backend = service_->GetBackend(parent_process_id_); | 249 AppCacheBackendImpl* backend = service_->GetBackend(parent_process_id_); |
| 236 return backend ? backend->GetHost(parent_host_id_) : NULL; | 250 return backend ? backend->GetHost(parent_host_id_) : NULL; |
| 237 } | 251 } |
| 238 | 252 |
| 239 AppCacheRequestHandler* AppCacheHost::CreateRequestHandler( | 253 AppCacheRequestHandler* AppCacheHost::CreateRequestHandler( |
| 240 net::URLRequest* request, | 254 net::URLRequest* request, |
| 241 ResourceType::Type resource_type) { | 255 ResourceType::Type resource_type) { |
| 242 if (is_for_dedicated_worker()) { | 256 if (is_for_dedicated_worker()) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 DCHECK(!associated_cache()); | 345 DCHECK(!associated_cache()); |
| 332 | 346 |
| 333 // 6.9.6 The application cache selection algorithm | 347 // 6.9.6 The application cache selection algorithm |
| 334 if (cache) { | 348 if (cache) { |
| 335 // If document was loaded from an application cache, Associate document | 349 // If document was loaded from an application cache, Associate document |
| 336 // with the application cache from which it was loaded. Invoke the | 350 // with the application cache from which it was loaded. Invoke the |
| 337 // application cache update process for that cache and with the browsing | 351 // application cache update process for that cache and with the browsing |
| 338 // context being navigated. | 352 // context being navigated. |
| 339 DCHECK(cache->owning_group()); | 353 DCHECK(cache->owning_group()); |
| 340 DCHECK(new_master_entry_url_.is_empty()); | 354 DCHECK(new_master_entry_url_.is_empty()); |
| 355 DCHECK_EQ(cache->owning_group()->manifest_url(), preferred_manifest_url_); |
| 341 AppCacheGroup* owing_group = cache->owning_group(); | 356 AppCacheGroup* owing_group = cache->owning_group(); |
| 342 const char* kFormatString = | 357 const char* kFormatString = |
| 343 "Document was loaded from Application Cache with manifest %s"; | 358 "Document was loaded from Application Cache with manifest %s"; |
| 344 frontend_->OnLogMessage( | 359 frontend_->OnLogMessage( |
| 345 host_id_, LOG_INFO, | 360 host_id_, LOG_INFO, |
| 346 base::StringPrintf( | 361 base::StringPrintf( |
| 347 kFormatString, owing_group->manifest_url().spec().c_str())); | 362 kFormatString, owing_group->manifest_url().spec().c_str())); |
| 348 AssociateCache(cache); | 363 AssociateCache(cache); |
| 349 if (!owing_group->is_obsolete() && !owing_group->is_being_deleted()) { | 364 if (!owing_group->is_obsolete() && !owing_group->is_being_deleted()) { |
| 350 owing_group->StartUpdateWithHost(this); | 365 owing_group->StartUpdateWithHost(this); |
| 351 ObserveGroupBeingUpdated(owing_group); | 366 ObserveGroupBeingUpdated(owing_group); |
| 352 } | 367 } |
| 353 } else if (group && !group->is_being_deleted()) { | 368 } else if (group && !group->is_being_deleted()) { |
| 354 // If document was loaded using HTTP GET or equivalent, and, there is a | 369 // If document was loaded using HTTP GET or equivalent, and, there is a |
| 355 // manifest URL, and manifest URL has the same origin as document. | 370 // manifest URL, and manifest URL has the same origin as document. |
| 356 // Invoke the application cache update process for manifest URL, with | 371 // Invoke the application cache update process for manifest URL, with |
| 357 // the browsing context being navigated, and with document and the | 372 // the browsing context being navigated, and with document and the |
| 358 // resource from which document was loaded as the new master resourse. | 373 // resource from which document was loaded as the new master resourse. |
| 359 DCHECK(!group->is_obsolete()); | 374 DCHECK(!group->is_obsolete()); |
| 360 DCHECK(new_master_entry_url_.is_valid()); | 375 DCHECK(new_master_entry_url_.is_valid()); |
| 376 DCHECK_EQ(group->manifest_url(), preferred_manifest_url_); |
| 361 const char* kFormatString = group->HasCache() ? | 377 const char* kFormatString = group->HasCache() ? |
| 362 "Adding master entry to Application Cache with manifest %s" : | 378 "Adding master entry to Application Cache with manifest %s" : |
| 363 "Creating Application Cache with manifest %s"; | 379 "Creating Application Cache with manifest %s"; |
| 364 frontend_->OnLogMessage( | 380 frontend_->OnLogMessage( |
| 365 host_id_, LOG_INFO, | 381 host_id_, LOG_INFO, |
| 366 base::StringPrintf(kFormatString, | 382 base::StringPrintf(kFormatString, |
| 367 group->manifest_url().spec().c_str())); | 383 group->manifest_url().spec().c_str())); |
| 368 AssociateCache(NULL); // The UpdateJob may produce one for us later. | 384 AssociateCache(NULL); // The UpdateJob may produce one for us later. |
| 369 group->StartUpdateWithNewMasterEntry(this, new_master_entry_url_); | 385 group->StartUpdateWithNewMasterEntry(this, new_master_entry_url_); |
| 370 ObserveGroupBeingUpdated(group); | 386 ObserveGroupBeingUpdated(group); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 associated_cache_info_pending_ = cache && !cache->is_complete(); | 473 associated_cache_info_pending_ = cache && !cache->is_complete(); |
| 458 AppCacheInfo info; | 474 AppCacheInfo info; |
| 459 if (cache) { | 475 if (cache) { |
| 460 cache->AssociateHost(this); | 476 cache->AssociateHost(this); |
| 461 FillCacheInfo(cache, GetStatus(), &info); | 477 FillCacheInfo(cache, GetStatus(), &info); |
| 462 } | 478 } |
| 463 frontend_->OnCacheSelected(host_id_, info); | 479 frontend_->OnCacheSelected(host_id_, info); |
| 464 } | 480 } |
| 465 | 481 |
| 466 } // namespace appcache | 482 } // namespace appcache |
| OLD | NEW |