Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1082)

Side by Side Diff: content/browser/service_worker/service_worker_context_request_handler.cc

Issue 457903002: After 24 hours, bust the browser cache when checking for ServiceWorker updates (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser/service_worker/service_worker_context_request_handler. h" 5 #include "content/browser/service_worker/service_worker_context_request_handler. h"
6 6
7 #include "content/browser/service_worker/service_worker_context_core.h" 7 #include "content/browser/service_worker/service_worker_context_core.h"
8 #include "content/browser/service_worker/service_worker_provider_host.h" 8 #include "content/browser/service_worker/service_worker_provider_host.h"
9 #include "content/browser/service_worker/service_worker_read_from_cache_job.h" 9 #include "content/browser/service_worker/service_worker_read_from_cache_job.h"
10 #include "content/browser/service_worker/service_worker_storage.h" 10 #include "content/browser/service_worker/service_worker_storage.h"
11 #include "content/browser/service_worker/service_worker_version.h" 11 #include "content/browser/service_worker/service_worker_version.h"
12 #include "content/browser/service_worker/service_worker_write_to_cache_job.h" 12 #include "content/browser/service_worker/service_worker_write_to_cache_job.h"
13 #include "net/base/load_flags.h"
13 #include "net/url_request/url_request.h" 14 #include "net/url_request/url_request.h"
14 15
15 namespace content { 16 namespace content {
16 17
17 ServiceWorkerContextRequestHandler::ServiceWorkerContextRequestHandler( 18 ServiceWorkerContextRequestHandler::ServiceWorkerContextRequestHandler(
18 base::WeakPtr<ServiceWorkerContextCore> context, 19 base::WeakPtr<ServiceWorkerContextCore> context,
19 base::WeakPtr<ServiceWorkerProviderHost> provider_host, 20 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
20 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context, 21 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context,
21 ResourceType resource_type) 22 ResourceType resource_type)
22 : ServiceWorkerRequestHandler(context, 23 : ServiceWorkerRequestHandler(context,
(...skipping 21 matching lines...) Expand all
44 // importScripts(), even if a cached script is xhr'd, we don't 45 // importScripts(), even if a cached script is xhr'd, we don't
45 // retrieve it from the script cache. 46 // retrieve it from the script cache.
46 // TODO(michaeln): Get the desired behavior clarified in the spec, 47 // TODO(michaeln): Get the desired behavior clarified in the spec,
47 // and make tweak the behavior here to match. 48 // and make tweak the behavior here to match.
48 if (resource_type_ != RESOURCE_TYPE_SERVICE_WORKER && 49 if (resource_type_ != RESOURCE_TYPE_SERVICE_WORKER &&
49 resource_type_ != RESOURCE_TYPE_SCRIPT) { 50 resource_type_ != RESOURCE_TYPE_SCRIPT) {
50 return NULL; 51 return NULL;
51 } 52 }
52 53
53 if (ShouldAddToScriptCache(request->url())) { 54 if (ShouldAddToScriptCache(request->url())) {
55 ServiceWorkerRegistration* registration =
56 context_->GetLiveRegistration(version_->registration_id());
57 DCHECK(registration); // We're registering or updating so must be there.
58
54 int64 response_id = context_->storage()->NewResourceId(); 59 int64 response_id = context_->storage()->NewResourceId();
55 if (response_id == kInvalidServiceWorkerResponseId) 60 if (response_id == kInvalidServiceWorkerResponseId)
56 return NULL; 61 return NULL;
62
63 // Bypass the browser cache for initial installs and update
64 // checks after 24 hours have passed.
65 // TODO(michaeln): When loading imports the last_update_check time has
66 // already been updated by the UPDATE_JOB so we never set the bypass
67 // flag for them, but probably should.
68 int extra_load_flags = 0;
69 base::TimeDelta time_since_last_check =
70 base::Time::Now() - registration->last_update_check();
71 if (time_since_last_check > base::TimeDelta::FromHours(24))
72 extra_load_flags = net::LOAD_BYPASS_CACHE;
73
57 return new ServiceWorkerWriteToCacheJob(request, 74 return new ServiceWorkerWriteToCacheJob(request,
58 network_delegate, 75 network_delegate,
59 resource_type_, 76 resource_type_,
60 context_, 77 context_,
61 version_, 78 version_,
79 extra_load_flags,
62 response_id); 80 response_id);
63 } 81 }
64 82
65 int64 response_id = kInvalidServiceWorkerResponseId; 83 int64 response_id = kInvalidServiceWorkerResponseId;
66 if (ShouldReadFromScriptCache(request->url(), &response_id)) { 84 if (ShouldReadFromScriptCache(request->url(), &response_id)) {
67 return new ServiceWorkerReadFromCacheJob( 85 return new ServiceWorkerReadFromCacheJob(
68 request, network_delegate, context_, response_id); 86 request, network_delegate, context_, response_id);
69 } 87 }
70 88
71 // NULL means use the network. 89 // NULL means use the network.
(...skipping 22 matching lines...) Expand all
94 const GURL& url, int64* response_id_out) { 112 const GURL& url, int64* response_id_out) {
95 // We don't read from the script cache until the version is INSTALLED. 113 // We don't read from the script cache until the version is INSTALLED.
96 if (version_->status() == ServiceWorkerVersion::NEW || 114 if (version_->status() == ServiceWorkerVersion::NEW ||
97 version_->status() == ServiceWorkerVersion::INSTALLING) 115 version_->status() == ServiceWorkerVersion::INSTALLING)
98 return false; 116 return false;
99 *response_id_out = version_->script_cache_map()->Lookup(url); 117 *response_id_out = version_->script_cache_map()->Lookup(url);
100 return *response_id_out != kInvalidServiceWorkerResponseId; 118 return *response_id_out != kInvalidServiceWorkerResponseId;
101 } 119 }
102 120
103 } // namespace content 121 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698