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

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

Issue 1166433003: Service Worker: Don't write to disk during update until proven necessary (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: patch for review Created 5 years, 6 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
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 "base/time/time.h" 7 #include "base/time/time.h"
8 #include "content/browser/service_worker/service_worker_context_core.h" 8 #include "content/browser/service_worker/service_worker_context_core.h"
9 #include "content/browser/service_worker/service_worker_provider_host.h" 9 #include "content/browser/service_worker/service_worker_provider_host.h"
10 #include "content/browser/service_worker/service_worker_read_from_cache_job.h" 10 #include "content/browser/service_worker/service_worker_read_from_cache_job.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // Bypass the browser cache for initial installs and update 66 // Bypass the browser cache for initial installs and update
67 // checks after 24 hours have passed. 67 // checks after 24 hours have passed.
68 int extra_load_flags = 0; 68 int extra_load_flags = 0;
69 base::TimeDelta time_since_last_check = 69 base::TimeDelta time_since_last_check =
70 base::Time::Now() - registration->last_update_check(); 70 base::Time::Now() - registration->last_update_check();
71 if (time_since_last_check > base::TimeDelta::FromHours(24) || 71 if (time_since_last_check > base::TimeDelta::FromHours(24) ||
72 version_->force_bypass_cache_for_scripts()) { 72 version_->force_bypass_cache_for_scripts()) {
73 extra_load_flags = net::LOAD_BYPASS_CACHE; 73 extra_load_flags = net::LOAD_BYPASS_CACHE;
74 } 74 }
75 75
76 return new ServiceWorkerWriteToCacheJob(request, 76 ServiceWorkerVersion* stored_version = registration->waiting_version()
77 network_delegate, 77 ? registration->waiting_version()
78 resource_type_, 78 : registration->active_version();
79 context_, 79 int64 incumbent_response_id = kInvalidServiceWorkerResourceId;
80 version_.get(), 80 if (stored_version && stored_version->script_url() == request->url())
81 extra_load_flags, 81 incumbent_response_id =
82 response_id); 82 stored_version->script_cache_map()->LookupResourceId(request->url());
nhiroki 2015/06/03 05:36:14 nit: Can you wrap this if-statement body with {}?
falken 2015/06/03 09:07:40 Done.
83 return new ServiceWorkerWriteToCacheJob(
84 request, network_delegate, resource_type_, context_, version_.get(),
85 extra_load_flags, response_id, incumbent_response_id);
83 } 86 }
84 87
85 int64 response_id = kInvalidServiceWorkerResponseId; 88 int64 response_id = kInvalidServiceWorkerResponseId;
86 if (ShouldReadFromScriptCache(request->url(), &response_id)) { 89 if (ShouldReadFromScriptCache(request->url(), &response_id)) {
87 return new ServiceWorkerReadFromCacheJob( 90 return new ServiceWorkerReadFromCacheJob(
88 request, network_delegate, context_, version_, response_id); 91 request, network_delegate, context_, version_, response_id);
89 } 92 }
90 93
91 // NULL means use the network. 94 // NULL means use the network.
92 return NULL; 95 return NULL;
(...skipping 27 matching lines...) Expand all
120 const GURL& url, int64* response_id_out) { 123 const GURL& url, int64* response_id_out) {
121 // We don't read from the script cache until the version is INSTALLED. 124 // We don't read from the script cache until the version is INSTALLED.
122 if (version_->status() == ServiceWorkerVersion::NEW || 125 if (version_->status() == ServiceWorkerVersion::NEW ||
123 version_->status() == ServiceWorkerVersion::INSTALLING) 126 version_->status() == ServiceWorkerVersion::INSTALLING)
124 return false; 127 return false;
125 *response_id_out = version_->script_cache_map()->LookupResourceId(url); 128 *response_id_out = version_->script_cache_map()->LookupResourceId(url);
126 return *response_id_out != kInvalidServiceWorkerResponseId; 129 return *response_id_out != kInvalidServiceWorkerResponseId;
127 } 130 }
128 131
129 } // namespace content 132 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698