Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/child/appcache/web_application_cache_host_impl.h" | 5 #include "content/child/appcache/web_application_cache_host_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/id_map.h" | 10 #include "base/id_map.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 | 58 |
| 59 WebApplicationCacheHostImpl::WebApplicationCacheHostImpl( | 59 WebApplicationCacheHostImpl::WebApplicationCacheHostImpl( |
| 60 WebApplicationCacheHostClient* client, | 60 WebApplicationCacheHostClient* client, |
| 61 AppCacheBackend* backend, | 61 AppCacheBackend* backend, |
| 62 int appcache_host_id) | 62 int appcache_host_id) |
| 63 : client_(client), | 63 : client_(client), |
| 64 backend_(backend), | 64 backend_(backend), |
| 65 status_(APPCACHE_STATUS_UNCACHED), | 65 status_(APPCACHE_STATUS_UNCACHED), |
| 66 is_scheme_supported_(false), | 66 is_scheme_supported_(false), |
| 67 is_get_method_(false), | 67 is_get_method_(false), |
| 68 is_new_master_entry_(MAYBE), | 68 is_new_master_entry_(MAYBE_NEW_ENTRY), |
| 69 was_select_cache_called_(false) { | 69 was_select_cache_called_(false) { |
| 70 DCHECK(client && backend); | 70 DCHECK(client && backend); |
| 71 // PlzNavigate: The browser passes the ID to be used. | 71 // PlzNavigate: The browser passes the ID to be used. |
| 72 if (appcache_host_id != kAppCacheNoHostId) { | 72 if (appcache_host_id != kAppCacheNoHostId) { |
| 73 DCHECK(IsBrowserSideNavigationEnabled()); | 73 DCHECK(IsBrowserSideNavigationEnabled()); |
| 74 all_hosts()->AddWithID(this, appcache_host_id); | 74 all_hosts()->AddWithID(this, appcache_host_id); |
| 75 host_id_ = appcache_host_id; | 75 host_id_ = appcache_host_id; |
| 76 } else { | 76 } else { |
| 77 host_id_ = all_hosts()->Add(this); | 77 host_id_ = all_hosts()->Add(this); |
| 78 } | 78 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 request.setAppCacheHostID(host_id_); | 194 request.setAppCacheHostID(host_id_); |
| 195 } | 195 } |
| 196 | 196 |
| 197 void WebApplicationCacheHostImpl::selectCacheWithoutManifest() { | 197 void WebApplicationCacheHostImpl::selectCacheWithoutManifest() { |
| 198 if (was_select_cache_called_) | 198 if (was_select_cache_called_) |
| 199 return; | 199 return; |
| 200 was_select_cache_called_ = true; | 200 was_select_cache_called_ = true; |
| 201 | 201 |
| 202 status_ = (document_response_.appCacheID() == kAppCacheNoCacheId) ? | 202 status_ = (document_response_.appCacheID() == kAppCacheNoCacheId) ? |
| 203 APPCACHE_STATUS_UNCACHED : APPCACHE_STATUS_CHECKING; | 203 APPCACHE_STATUS_UNCACHED : APPCACHE_STATUS_CHECKING; |
| 204 is_new_master_entry_ = NO; | 204 is_new_master_entry_ = OLD_ENTRY; |
|
michaeln
2017/02/03 00:43:55
would MAYBE, YUP, NOPE be more readable?
lgtm
Patti Lor
2017/02/03 01:08:14
Yeah, I was also a bit worried about losing a bit
| |
| 205 backend_->SelectCache(host_id_, document_url_, | 205 backend_->SelectCache(host_id_, document_url_, |
| 206 document_response_.appCacheID(), | 206 document_response_.appCacheID(), |
| 207 GURL()); | 207 GURL()); |
| 208 } | 208 } |
| 209 | 209 |
| 210 bool WebApplicationCacheHostImpl::selectCacheWithManifest( | 210 bool WebApplicationCacheHostImpl::selectCacheWithManifest( |
| 211 const WebURL& manifest_url) { | 211 const WebURL& manifest_url) { |
| 212 if (was_select_cache_called_) | 212 if (was_select_cache_called_) |
| 213 return true; | 213 return true; |
| 214 was_select_cache_called_ = true; | 214 was_select_cache_called_ = true; |
| 215 | 215 |
| 216 GURL manifest_gurl(ClearUrlRef(manifest_url)); | 216 GURL manifest_gurl(ClearUrlRef(manifest_url)); |
| 217 | 217 |
| 218 // 6.9.6 The application cache selection algorithm | 218 // 6.9.6 The application cache selection algorithm |
| 219 // Check for new 'master' entries. | 219 // Check for new 'master' entries. |
| 220 if (document_response_.appCacheID() == kAppCacheNoCacheId) { | 220 if (document_response_.appCacheID() == kAppCacheNoCacheId) { |
| 221 if (is_scheme_supported_ && is_get_method_ && | 221 if (is_scheme_supported_ && is_get_method_ && |
| 222 (manifest_gurl.GetOrigin() == document_url_.GetOrigin())) { | 222 (manifest_gurl.GetOrigin() == document_url_.GetOrigin())) { |
| 223 status_ = APPCACHE_STATUS_CHECKING; | 223 status_ = APPCACHE_STATUS_CHECKING; |
| 224 is_new_master_entry_ = YES; | 224 is_new_master_entry_ = NEW_ENTRY; |
| 225 } else { | 225 } else { |
| 226 status_ = APPCACHE_STATUS_UNCACHED; | 226 status_ = APPCACHE_STATUS_UNCACHED; |
| 227 is_new_master_entry_ = NO; | 227 is_new_master_entry_ = OLD_ENTRY; |
| 228 manifest_gurl = GURL(); | 228 manifest_gurl = GURL(); |
| 229 } | 229 } |
| 230 backend_->SelectCache( | 230 backend_->SelectCache( |
| 231 host_id_, document_url_, kAppCacheNoCacheId, manifest_gurl); | 231 host_id_, document_url_, kAppCacheNoCacheId, manifest_gurl); |
| 232 return true; | 232 return true; |
| 233 } | 233 } |
| 234 | 234 |
| 235 DCHECK_EQ(NO, is_new_master_entry_); | 235 DCHECK_EQ(OLD_ENTRY, is_new_master_entry_); |
| 236 | 236 |
| 237 // 6.9.6 The application cache selection algorithm | 237 // 6.9.6 The application cache selection algorithm |
| 238 // Check for 'foreign' entries. | 238 // Check for 'foreign' entries. |
| 239 GURL document_manifest_gurl(document_response_.appCacheManifestURL()); | 239 GURL document_manifest_gurl(document_response_.appCacheManifestURL()); |
| 240 if (document_manifest_gurl != manifest_gurl) { | 240 if (document_manifest_gurl != manifest_gurl) { |
| 241 backend_->MarkAsForeignEntry(host_id_, document_url_, | 241 backend_->MarkAsForeignEntry(host_id_, document_url_, |
| 242 document_response_.appCacheID()); | 242 document_response_.appCacheID()); |
| 243 status_ = APPCACHE_STATUS_UNCACHED; | 243 status_ = APPCACHE_STATUS_UNCACHED; |
| 244 return false; // the navigation will be restarted | 244 return false; // the navigation will be restarted |
| 245 } | 245 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 257 const WebURLResponse& response) { | 257 const WebURLResponse& response) { |
| 258 document_response_ = response; | 258 document_response_ = response; |
| 259 document_url_ = ClearUrlRef(document_response_.url()); | 259 document_url_ = ClearUrlRef(document_response_.url()); |
| 260 if (document_url_ != original_main_resource_url_) | 260 if (document_url_ != original_main_resource_url_) |
| 261 is_get_method_ = true; // A redirect was involved. | 261 is_get_method_ = true; // A redirect was involved. |
| 262 original_main_resource_url_ = GURL(); | 262 original_main_resource_url_ = GURL(); |
| 263 | 263 |
| 264 is_scheme_supported_ = IsSchemeSupportedForAppCache(document_url_); | 264 is_scheme_supported_ = IsSchemeSupportedForAppCache(document_url_); |
| 265 if ((document_response_.appCacheID() != kAppCacheNoCacheId) || | 265 if ((document_response_.appCacheID() != kAppCacheNoCacheId) || |
| 266 !is_scheme_supported_ || !is_get_method_) | 266 !is_scheme_supported_ || !is_get_method_) |
| 267 is_new_master_entry_ = NO; | 267 is_new_master_entry_ = OLD_ENTRY; |
| 268 } | 268 } |
| 269 | 269 |
| 270 void WebApplicationCacheHostImpl::didReceiveDataForMainResource( | 270 void WebApplicationCacheHostImpl::didReceiveDataForMainResource( |
| 271 const char* data, unsigned len) { | 271 const char* data, unsigned len) { |
| 272 if (is_new_master_entry_ == NO) | 272 if (is_new_master_entry_ == OLD_ENTRY) |
| 273 return; | 273 return; |
| 274 // TODO(michaeln): write me | 274 // TODO(michaeln): write me |
| 275 } | 275 } |
| 276 | 276 |
| 277 void WebApplicationCacheHostImpl::didFinishLoadingMainResource(bool success) { | 277 void WebApplicationCacheHostImpl::didFinishLoadingMainResource(bool success) { |
| 278 if (is_new_master_entry_ == NO) | 278 if (is_new_master_entry_ == OLD_ENTRY) |
| 279 return; | 279 return; |
| 280 // TODO(michaeln): write me | 280 // TODO(michaeln): write me |
| 281 } | 281 } |
| 282 | 282 |
| 283 WebApplicationCacheHost::Status WebApplicationCacheHostImpl::getStatus() { | 283 WebApplicationCacheHost::Status WebApplicationCacheHostImpl::getStatus() { |
| 284 return static_cast<WebApplicationCacheHost::Status>(status_); | 284 return static_cast<WebApplicationCacheHost::Status>(status_); |
| 285 } | 285 } |
| 286 | 286 |
| 287 bool WebApplicationCacheHostImpl::startUpdate() { | 287 bool WebApplicationCacheHostImpl::startUpdate() { |
| 288 if (!backend_->StartUpdate(host_id_)) | 288 if (!backend_->StartUpdate(host_id_)) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 web_resources[i].isExplicit = resource_infos[i].is_explicit; | 326 web_resources[i].isExplicit = resource_infos[i].is_explicit; |
| 327 web_resources[i].isManifest = resource_infos[i].is_manifest; | 327 web_resources[i].isManifest = resource_infos[i].is_manifest; |
| 328 web_resources[i].isForeign = resource_infos[i].is_foreign; | 328 web_resources[i].isForeign = resource_infos[i].is_foreign; |
| 329 web_resources[i].isFallback = resource_infos[i].is_fallback; | 329 web_resources[i].isFallback = resource_infos[i].is_fallback; |
| 330 web_resources[i].url = resource_infos[i].url; | 330 web_resources[i].url = resource_infos[i].url; |
| 331 } | 331 } |
| 332 resources->swap(web_resources); | 332 resources->swap(web_resources); |
| 333 } | 333 } |
| 334 | 334 |
| 335 } // namespace content | 335 } // namespace content |
| OLD | NEW |