| OLD | NEW |
| 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/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/profiler/scoped_tracker.h" | |
| 12 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 14 #include "content/browser/appcache/appcache_group.h" | 13 #include "content/browser/appcache/appcache_group.h" |
| 15 #include "content/browser/appcache/appcache_histograms.h" | 14 #include "content/browser/appcache/appcache_histograms.h" |
| 16 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
| 17 #include "net/base/load_flags.h" | 16 #include "net/base/load_flags.h" |
| 18 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 19 #include "net/base/request_priority.h" | 18 #include "net/base/request_priority.h" |
| 20 #include "net/http/http_request_headers.h" | 19 #include "net/http/http_request_headers.h" |
| 21 #include "net/http/http_response_headers.h" | 20 #include "net/http/http_response_headers.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 // Redirect is not allowed by the update process. | 145 // Redirect is not allowed by the update process. |
| 147 job_->MadeProgress(); | 146 job_->MadeProgress(); |
| 148 redirect_response_code_ = request->GetResponseCode(); | 147 redirect_response_code_ = request->GetResponseCode(); |
| 149 request->Cancel(); | 148 request->Cancel(); |
| 150 result_ = REDIRECT_ERROR; | 149 result_ = REDIRECT_ERROR; |
| 151 OnResponseCompleted(); | 150 OnResponseCompleted(); |
| 152 } | 151 } |
| 153 | 152 |
| 154 void AppCacheUpdateJob::URLFetcher::OnResponseStarted( | 153 void AppCacheUpdateJob::URLFetcher::OnResponseStarted( |
| 155 net::URLRequest *request) { | 154 net::URLRequest *request) { |
| 156 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | |
| 157 tracked_objects::ScopedTracker tracking_profile( | |
| 158 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
| 159 "422516 AppCacheUpdateJob::URLFetcher::OnResponseStarted")); | |
| 160 | |
| 161 DCHECK(request == request_); | 155 DCHECK(request == request_); |
| 162 int response_code = -1; | 156 int response_code = -1; |
| 163 if (request->status().is_success()) { | 157 if (request->status().is_success()) { |
| 164 response_code = request->GetResponseCode(); | 158 response_code = request->GetResponseCode(); |
| 165 job_->MadeProgress(); | 159 job_->MadeProgress(); |
| 166 } | 160 } |
| 167 | 161 |
| 168 if ((response_code / 100) != 2) { | 162 if ((response_code / 100) != 2) { |
| 169 if (response_code > 0) | 163 if (response_code > 0) |
| 170 result_ = SERVER_ERROR; | 164 result_ = SERVER_ERROR; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 response_writer_->WriteInfo( | 204 response_writer_->WriteInfo( |
| 211 io_buffer.get(), | 205 io_buffer.get(), |
| 212 base::Bind(&URLFetcher::OnWriteComplete, base::Unretained(this))); | 206 base::Bind(&URLFetcher::OnWriteComplete, base::Unretained(this))); |
| 213 } else { | 207 } else { |
| 214 ReadResponseData(); | 208 ReadResponseData(); |
| 215 } | 209 } |
| 216 } | 210 } |
| 217 | 211 |
| 218 void AppCacheUpdateJob::URLFetcher::OnReadCompleted( | 212 void AppCacheUpdateJob::URLFetcher::OnReadCompleted( |
| 219 net::URLRequest* request, int bytes_read) { | 213 net::URLRequest* request, int bytes_read) { |
| 220 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | |
| 221 tracked_objects::ScopedTracker tracking_profile( | |
| 222 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
| 223 "422516 AppCacheUpdateJob::URLFetcher::OnReadCompleted")); | |
| 224 | |
| 225 DCHECK(request_ == request); | 214 DCHECK(request_ == request); |
| 226 bool data_consumed = true; | 215 bool data_consumed = true; |
| 227 if (request->status().is_success() && bytes_read > 0) { | 216 if (request->status().is_success() && bytes_read > 0) { |
| 228 job_->MadeProgress(); | 217 job_->MadeProgress(); |
| 229 data_consumed = ConsumeResponseData(bytes_read); | 218 data_consumed = ConsumeResponseData(bytes_read); |
| 230 if (data_consumed) { | 219 if (data_consumed) { |
| 231 bytes_read = 0; | 220 bytes_read = 0; |
| 232 while (request->Read(buffer_.get(), kBufferSize, &bytes_read)) { | 221 while (request->Read(buffer_.get(), kBufferSize, &bytes_read)) { |
| 233 if (bytes_read > 0) { | 222 if (bytes_read > 0) { |
| 234 data_consumed = ConsumeResponseData(bytes_read); | 223 data_consumed = ConsumeResponseData(bytes_read); |
| (...skipping 1386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1621 | 1610 |
| 1622 // Break the connection with the group so the group cannot call delete | 1611 // Break the connection with the group so the group cannot call delete |
| 1623 // on this object after we've posted a task to delete ourselves. | 1612 // on this object after we've posted a task to delete ourselves. |
| 1624 group_->SetUpdateAppCacheStatus(AppCacheGroup::IDLE); | 1613 group_->SetUpdateAppCacheStatus(AppCacheGroup::IDLE); |
| 1625 group_ = NULL; | 1614 group_ = NULL; |
| 1626 | 1615 |
| 1627 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 1616 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 1628 } | 1617 } |
| 1629 | 1618 |
| 1630 } // namespace content | 1619 } // namespace content |
| OLD | NEW |