| 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 "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" | 5 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/debug/trace_event.h" |
| 13 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 14 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 15 #include "base/memory/ref_counted_memory.h" | 16 #include "base/memory/ref_counted_memory.h" |
| 16 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 17 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
| 18 #include "base/path_service.h" | 19 #include "base/path_service.h" |
| 19 #include "base/string_util.h" | 20 #include "base/string_util.h" |
| 20 #include "chrome/browser/net/chrome_url_request_context.h" | 21 #include "chrome/browser/net/chrome_url_request_context.h" |
| 21 #include "chrome/browser/ui/webui/shared_resources_data_source.h" | 22 #include "chrome/browser/ui/webui/shared_resources_data_source.h" |
| 22 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 CHECK(!backend_->HasPendingJob(this)); | 229 CHECK(!backend_->HasPendingJob(this)); |
| 229 } | 230 } |
| 230 | 231 |
| 231 void URLRequestChromeJob::Start() { | 232 void URLRequestChromeJob::Start() { |
| 232 // Start reading asynchronously so that all error reporting and data | 233 // Start reading asynchronously so that all error reporting and data |
| 233 // callbacks happen as they would for network requests. | 234 // callbacks happen as they would for network requests. |
| 234 MessageLoop::current()->PostTask( | 235 MessageLoop::current()->PostTask( |
| 235 FROM_HERE, | 236 FROM_HERE, |
| 236 base::Bind(&URLRequestChromeJob::StartAsync, | 237 base::Bind(&URLRequestChromeJob::StartAsync, |
| 237 weak_factory_.GetWeakPtr())); | 238 weak_factory_.GetWeakPtr())); |
| 239 |
| 240 TRACE_EVENT_ASYNC_BEGIN1("browser", "DataManager:Request", this, "URL", |
| 241 request_->url().possibly_invalid_spec()); |
| 238 } | 242 } |
| 239 | 243 |
| 240 void URLRequestChromeJob::Kill() { | 244 void URLRequestChromeJob::Kill() { |
| 241 backend_->RemoveRequest(this); | 245 backend_->RemoveRequest(this); |
| 242 } | 246 } |
| 243 | 247 |
| 244 bool URLRequestChromeJob::GetMimeType(std::string* mime_type) const { | 248 bool URLRequestChromeJob::GetMimeType(std::string* mime_type) const { |
| 245 *mime_type = mime_type_; | 249 *mime_type = mime_type_; |
| 246 return !mime_type_.empty(); | 250 return !mime_type_.empty(); |
| 247 } | 251 } |
| 248 | 252 |
| 249 void URLRequestChromeJob::GetResponseInfo(net::HttpResponseInfo* info) { | 253 void URLRequestChromeJob::GetResponseInfo(net::HttpResponseInfo* info) { |
| 250 DCHECK(!info->headers); | 254 DCHECK(!info->headers); |
| 251 // Set the headers so that requests serviced by ChromeURLDataManager return a | 255 // Set the headers so that requests serviced by ChromeURLDataManager return a |
| 252 // status code of 200. Without this they return a 0, which makes the status | 256 // status code of 200. Without this they return a 0, which makes the status |
| 253 // indistiguishable from other error types. Instant relies on getting a 200. | 257 // indistiguishable from other error types. Instant relies on getting a 200. |
| 254 info->headers = new net::HttpResponseHeaders("HTTP/1.1 200 OK"); | 258 info->headers = new net::HttpResponseHeaders("HTTP/1.1 200 OK"); |
| 255 AddContentSecurityPolicyHeader(request_->url(), info->headers); | 259 AddContentSecurityPolicyHeader(request_->url(), info->headers); |
| 256 } | 260 } |
| 257 | 261 |
| 258 void URLRequestChromeJob::DataAvailable(RefCountedMemory* bytes) { | 262 void URLRequestChromeJob::DataAvailable(RefCountedMemory* bytes) { |
| 263 TRACE_EVENT_ASYNC_END0("browser", "DataManager:Request", this); |
| 259 if (bytes) { | 264 if (bytes) { |
| 260 // The request completed, and we have all the data. | 265 // The request completed, and we have all the data. |
| 261 // Clear any IO pending status. | 266 // Clear any IO pending status. |
| 262 SetStatus(net::URLRequestStatus()); | 267 SetStatus(net::URLRequestStatus()); |
| 263 | 268 |
| 264 data_ = bytes; | 269 data_ = bytes; |
| 265 int bytes_read; | 270 int bytes_read; |
| 266 if (pending_buf_.get()) { | 271 if (pending_buf_.get()) { |
| 267 CHECK(pending_buf_->data()); | 272 CHECK(pending_buf_->data()); |
| 268 CompleteRead(pending_buf_, pending_buf_size_, &bytes_read); | 273 CompleteRead(pending_buf_, pending_buf_size_, &bytes_read); |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 | 558 |
| 554 return new URLRequestChromeJob(request, backend_); | 559 return new URLRequestChromeJob(request, backend_); |
| 555 } | 560 } |
| 556 | 561 |
| 557 } // namespace | 562 } // namespace |
| 558 | 563 |
| 559 net::URLRequestJobFactory::ProtocolHandler* | 564 net::URLRequestJobFactory::ProtocolHandler* |
| 560 CreateDevToolsProtocolHandler(ChromeURLDataManagerBackend* backend) { | 565 CreateDevToolsProtocolHandler(ChromeURLDataManagerBackend* backend) { |
| 561 return new DevToolsJobFactory(backend); | 566 return new DevToolsJobFactory(backend); |
| 562 } | 567 } |
| OLD | NEW |