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

Side by Side Diff: content/browser/appcache/appcache_update_job.cc

Issue 2867693004: Snapshot of all changes to get jumbo in blink and content.
Patch Set: Rebased again Created 3 years, 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/appcache/appcache_update_job.h" 5 #include "content/browser/appcache/appcache_update_job.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 11 matching lines...) Expand all
22 #include "net/http/http_request_headers.h" 22 #include "net/http/http_request_headers.h"
23 #include "net/http/http_response_headers.h" 23 #include "net/http/http_response_headers.h"
24 #include "net/traffic_annotation/network_traffic_annotation.h" 24 #include "net/traffic_annotation/network_traffic_annotation.h"
25 #include "net/url_request/url_request_context.h" 25 #include "net/url_request/url_request_context.h"
26 #include "url/origin.h" 26 #include "url/origin.h"
27 27
28 namespace content { 28 namespace content {
29 29
30 namespace { 30 namespace {
31 31
32 const int kBufferSize = 32768; 32 const int kAppCacheFetchBufferSize = 32768;
33 const size_t kMaxConcurrentUrlFetches = 2; 33 const size_t kMaxConcurrentUrlFetches = 2;
34 const int kMax503Retries = 3; 34 const int kMax503Retries = 3;
35 35
36 std::string FormatUrlErrorMessage( 36 std::string FormatUrlErrorMessage(
37 const char* format, const GURL& url, 37 const char* format, const GURL& url,
38 AppCacheUpdateJob::ResultType error, 38 AppCacheUpdateJob::ResultType error,
39 int response_code) { 39 int response_code) {
40 // Show the net response code if we have one. 40 // Show the net response code if we have one.
41 int code = response_code; 41 int code = response_code;
42 if (error != AppCacheUpdateJob::SERVER_ERROR) 42 if (error != AppCacheUpdateJob::SERVER_ERROR)
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 // Helper class to fetch resources. Depending on the fetch type, 181 // Helper class to fetch resources. Depending on the fetch type,
182 // can either fetch to an in-memory string or write the response 182 // can either fetch to an in-memory string or write the response
183 // data out to the disk cache. 183 // data out to the disk cache.
184 AppCacheUpdateJob::URLFetcher::URLFetcher(const GURL& url, 184 AppCacheUpdateJob::URLFetcher::URLFetcher(const GURL& url,
185 FetchType fetch_type, 185 FetchType fetch_type,
186 AppCacheUpdateJob* job) 186 AppCacheUpdateJob* job)
187 : url_(url), 187 : url_(url),
188 job_(job), 188 job_(job),
189 fetch_type_(fetch_type), 189 fetch_type_(fetch_type),
190 retry_503_attempts_(0), 190 retry_503_attempts_(0),
191 buffer_(new net::IOBuffer(kBufferSize)), 191 buffer_(new net::IOBuffer(kAppCacheFetchBufferSize)),
192 request_( 192 request_(
193 job->service_->request_context()->CreateRequest(url, 193 job->service_->request_context()->CreateRequest(url,
194 net::DEFAULT_PRIORITY, 194 net::DEFAULT_PRIORITY,
195 this, 195 this,
196 kTrafficAnnotation)), 196 kTrafficAnnotation)),
197 result_(UPDATE_OK), 197 result_(UPDATE_OK),
198 redirect_response_code_(-1) {} 198 redirect_response_code_(-1) {}
199 199
200 AppCacheUpdateJob::URLFetcher::~URLFetcher() { 200 AppCacheUpdateJob::URLFetcher::~URLFetcher() {
201 // To defend against URLRequest calling delegate methods during 201 // To defend against URLRequest calling delegate methods during
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 if (!request_) 296 if (!request_)
297 return; 297 return;
298 DCHECK_NE(net::ERR_IO_PENDING, bytes_read); 298 DCHECK_NE(net::ERR_IO_PENDING, bytes_read);
299 DCHECK_EQ(request_.get(), request); 299 DCHECK_EQ(request_.get(), request);
300 bool data_consumed = true; 300 bool data_consumed = true;
301 if (bytes_read > 0) { 301 if (bytes_read > 0) {
302 job_->MadeProgress(); 302 job_->MadeProgress();
303 data_consumed = ConsumeResponseData(bytes_read); 303 data_consumed = ConsumeResponseData(bytes_read);
304 if (data_consumed) { 304 if (data_consumed) {
305 while (true) { 305 while (true) {
306 bytes_read = request->Read(buffer_.get(), kBufferSize); 306 bytes_read = request->Read(buffer_.get(), kAppCacheFetchBufferSize);
307 if (bytes_read <= 0) 307 if (bytes_read <= 0)
308 break; 308 break;
309 data_consumed = ConsumeResponseData(bytes_read); 309 data_consumed = ConsumeResponseData(bytes_read);
310 if (!data_consumed) 310 if (!data_consumed)
311 break; 311 break;
312 } 312 }
313 } 313 }
314 } 314 }
315 315
316 if (data_consumed && bytes_read != net::ERR_IO_PENDING) { 316 if (data_consumed && bytes_read != net::ERR_IO_PENDING) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 OnResponseCompleted(net::ERR_ABORTED); 353 OnResponseCompleted(net::ERR_ABORTED);
354 return; 354 return;
355 } 355 }
356 ReadResponseData(); 356 ReadResponseData();
357 } 357 }
358 358
359 void AppCacheUpdateJob::URLFetcher::ReadResponseData() { 359 void AppCacheUpdateJob::URLFetcher::ReadResponseData() {
360 InternalUpdateState state = job_->internal_state_; 360 InternalUpdateState state = job_->internal_state_;
361 if (state == CACHE_FAILURE || state == CANCELLED || state == COMPLETED) 361 if (state == CACHE_FAILURE || state == CANCELLED || state == COMPLETED)
362 return; 362 return;
363 int bytes_read = request_->Read(buffer_.get(), kBufferSize); 363 int bytes_read = request_->Read(buffer_.get(), kAppCacheFetchBufferSize);
364 if (bytes_read != net::ERR_IO_PENDING) 364 if (bytes_read != net::ERR_IO_PENDING)
365 OnReadCompleted(request_.get(), bytes_read); 365 OnReadCompleted(request_.get(), bytes_read);
366 } 366 }
367 367
368 // Returns false if response data is processed asynchronously, in which 368 // Returns false if response data is processed asynchronously, in which
369 // case ReadResponseData will be invoked when it is safe to continue 369 // case ReadResponseData will be invoked when it is safe to continue
370 // reading more response data from the request. 370 // reading more response data from the request.
371 bool AppCacheUpdateJob::URLFetcher::ConsumeResponseData(int bytes_read) { 371 bool AppCacheUpdateJob::URLFetcher::ConsumeResponseData(int bytes_read) {
372 DCHECK_GT(bytes_read, 0); 372 DCHECK_GT(bytes_read, 0);
373 switch (fetch_type_) { 373 switch (fetch_type_) {
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 AppCacheHistograms::AddMissingManifestEntrySample(); 1201 AppCacheHistograms::AddMissingManifestEntrySample();
1202 service->DeleteAppCacheGroup(manifest_url_, net::CompletionCallback()); 1202 service->DeleteAppCacheGroup(manifest_url_, net::CompletionCallback());
1203 } 1203 }
1204 return; 1204 return;
1205 } 1205 }
1206 1206
1207 // Load manifest data from storage to compare against fetched manifest. 1207 // Load manifest data from storage to compare against fetched manifest.
1208 manifest_response_reader_.reset( 1208 manifest_response_reader_.reset(
1209 storage_->CreateResponseReader(manifest_url_, 1209 storage_->CreateResponseReader(manifest_url_,
1210 entry->response_id())); 1210 entry->response_id()));
1211 read_manifest_buffer_ = new net::IOBuffer(kBufferSize); 1211 read_manifest_buffer_ = new net::IOBuffer(kAppCacheFetchBufferSize);
1212 manifest_response_reader_->ReadData( 1212 manifest_response_reader_->ReadData(
1213 read_manifest_buffer_.get(), 1213 read_manifest_buffer_.get(),
1214 kBufferSize, 1214 kAppCacheFetchBufferSize,
1215 base::Bind(&AppCacheUpdateJob::OnManifestDataReadComplete, 1215 base::Bind(&AppCacheUpdateJob::OnManifestDataReadComplete,
1216 base::Unretained(this))); // async read 1216 base::Unretained(this))); // async read
1217 } 1217 }
1218 1218
1219 void AppCacheUpdateJob::OnManifestDataReadComplete(int result) { 1219 void AppCacheUpdateJob::OnManifestDataReadComplete(int result) {
1220 if (result > 0) { 1220 if (result > 0) {
1221 loaded_manifest_data_.append(read_manifest_buffer_->data(), result); 1221 loaded_manifest_data_.append(read_manifest_buffer_->data(), result);
1222 manifest_response_reader_->ReadData( 1222 manifest_response_reader_->ReadData(
1223 read_manifest_buffer_.get(), 1223 read_manifest_buffer_.get(),
1224 kBufferSize, 1224 kAppCacheFetchBufferSize,
1225 base::Bind(&AppCacheUpdateJob::OnManifestDataReadComplete, 1225 base::Bind(&AppCacheUpdateJob::OnManifestDataReadComplete,
1226 base::Unretained(this))); // read more 1226 base::Unretained(this))); // read more
1227 } else { 1227 } else {
1228 read_manifest_buffer_ = NULL; 1228 read_manifest_buffer_ = NULL;
1229 manifest_response_reader_.reset(); 1229 manifest_response_reader_.reset();
1230 ContinueHandleManifestFetchCompleted( 1230 ContinueHandleManifestFetchCompleted(
1231 result < 0 || manifest_data_ != loaded_manifest_data_); 1231 result < 0 || manifest_data_ != loaded_manifest_data_);
1232 } 1232 }
1233 } 1233 }
1234 1234
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
1755 // on this object after we've posted a task to delete ourselves. 1755 // on this object after we've posted a task to delete ourselves.
1756 if (group_) { 1756 if (group_) {
1757 group_->SetUpdateAppCacheStatus(AppCacheGroup::IDLE); 1757 group_->SetUpdateAppCacheStatus(AppCacheGroup::IDLE);
1758 group_ = NULL; 1758 group_ = NULL;
1759 } 1759 }
1760 1760
1761 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); 1761 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
1762 } 1762 }
1763 1763
1764 } // namespace content 1764 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/appcache/appcache_storage_impl.cc ('k') | content/browser/blob_storage/chrome_blob_storage_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698