| 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" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 virtual void Start() OVERRIDE; | 168 virtual void Start() OVERRIDE; |
| 169 virtual void Kill() OVERRIDE; | 169 virtual void Kill() OVERRIDE; |
| 170 virtual bool ReadRawData(net::IOBuffer* buf, | 170 virtual bool ReadRawData(net::IOBuffer* buf, |
| 171 int buf_size, | 171 int buf_size, |
| 172 int* bytes_read) OVERRIDE; | 172 int* bytes_read) OVERRIDE; |
| 173 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; | 173 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; |
| 174 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE; | 174 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE; |
| 175 | 175 |
| 176 // Called by ChromeURLDataManager to notify us that the data blob is ready | 176 // Called by ChromeURLDataManager to notify us that the data blob is ready |
| 177 // for us. | 177 // for us. |
| 178 void DataAvailable(RefCountedMemory* bytes); | 178 void DataAvailable(base::RefCountedMemory* bytes); |
| 179 | 179 |
| 180 void SetMimeType(const std::string& mime_type) { | 180 void SetMimeType(const std::string& mime_type) { |
| 181 mime_type_ = mime_type; | 181 mime_type_ = mime_type; |
| 182 } | 182 } |
| 183 | 183 |
| 184 private: | 184 private: |
| 185 virtual ~URLRequestChromeJob(); | 185 virtual ~URLRequestChromeJob(); |
| 186 | 186 |
| 187 // Helper for Start(), to let us start asynchronously. | 187 // Helper for Start(), to let us start asynchronously. |
| 188 // (This pattern is shared by most net::URLRequestJob implementations.) | 188 // (This pattern is shared by most net::URLRequestJob implementations.) |
| 189 void StartAsync(); | 189 void StartAsync(); |
| 190 | 190 |
| 191 // Do the actual copy from data_ (the data we're serving) into |buf|. | 191 // Do the actual copy from data_ (the data we're serving) into |buf|. |
| 192 // Separate from ReadRawData so we can handle async I/O. | 192 // Separate from ReadRawData so we can handle async I/O. |
| 193 void CompleteRead(net::IOBuffer* buf, int buf_size, int* bytes_read); | 193 void CompleteRead(net::IOBuffer* buf, int buf_size, int* bytes_read); |
| 194 | 194 |
| 195 // The actual data we're serving. NULL until it's been fetched. | 195 // The actual data we're serving. NULL until it's been fetched. |
| 196 scoped_refptr<RefCountedMemory> data_; | 196 scoped_refptr<base::RefCountedMemory> data_; |
| 197 // The current offset into the data that we're handing off to our | 197 // The current offset into the data that we're handing off to our |
| 198 // callers via the Read interfaces. | 198 // callers via the Read interfaces. |
| 199 int data_offset_; | 199 int data_offset_; |
| 200 | 200 |
| 201 // For async reads, we keep around a pointer to the buffer that | 201 // For async reads, we keep around a pointer to the buffer that |
| 202 // we're reading into. | 202 // we're reading into. |
| 203 scoped_refptr<net::IOBuffer> pending_buf_; | 203 scoped_refptr<net::IOBuffer> pending_buf_; |
| 204 int pending_buf_size_; | 204 int pending_buf_size_; |
| 205 std::string mime_type_; | 205 std::string mime_type_; |
| 206 | 206 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 249 |
| 250 void URLRequestChromeJob::GetResponseInfo(net::HttpResponseInfo* info) { | 250 void URLRequestChromeJob::GetResponseInfo(net::HttpResponseInfo* info) { |
| 251 DCHECK(!info->headers); | 251 DCHECK(!info->headers); |
| 252 // Set the headers so that requests serviced by ChromeURLDataManager return a | 252 // Set the headers so that requests serviced by ChromeURLDataManager return a |
| 253 // status code of 200. Without this they return a 0, which makes the status | 253 // status code of 200. Without this they return a 0, which makes the status |
| 254 // indistiguishable from other error types. Instant relies on getting a 200. | 254 // indistiguishable from other error types. Instant relies on getting a 200. |
| 255 info->headers = new net::HttpResponseHeaders("HTTP/1.1 200 OK"); | 255 info->headers = new net::HttpResponseHeaders("HTTP/1.1 200 OK"); |
| 256 AddContentSecurityPolicyHeader(request_->url(), info->headers); | 256 AddContentSecurityPolicyHeader(request_->url(), info->headers); |
| 257 } | 257 } |
| 258 | 258 |
| 259 void URLRequestChromeJob::DataAvailable(RefCountedMemory* bytes) { | 259 void URLRequestChromeJob::DataAvailable(base::RefCountedMemory* bytes) { |
| 260 TRACE_EVENT_ASYNC_END0("browser", "DataManager:Request", this); | 260 TRACE_EVENT_ASYNC_END0("browser", "DataManager:Request", this); |
| 261 if (bytes) { | 261 if (bytes) { |
| 262 // The request completed, and we have all the data. | 262 // The request completed, and we have all the data. |
| 263 // Clear any IO pending status. | 263 // Clear any IO pending status. |
| 264 SetStatus(net::URLRequestStatus()); | 264 SetStatus(net::URLRequestStatus()); |
| 265 | 265 |
| 266 data_ = bytes; | 266 data_ = bytes; |
| 267 int bytes_read; | 267 int bytes_read; |
| 268 if (pending_buf_.get()) { | 268 if (pending_buf_.get()) { |
| 269 CHECK(pending_buf_->data()); | 269 CHECK(pending_buf_->data()); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 for (PendingRequestMap::iterator i = pending_requests_.begin(); | 447 for (PendingRequestMap::iterator i = pending_requests_.begin(); |
| 448 i != pending_requests_.end(); ++i) { | 448 i != pending_requests_.end(); ++i) { |
| 449 if (i->second == job) { | 449 if (i->second == job) { |
| 450 pending_requests_.erase(i); | 450 pending_requests_.erase(i); |
| 451 return; | 451 return; |
| 452 } | 452 } |
| 453 } | 453 } |
| 454 } | 454 } |
| 455 | 455 |
| 456 void ChromeURLDataManagerBackend::DataAvailable(RequestID request_id, | 456 void ChromeURLDataManagerBackend::DataAvailable(RequestID request_id, |
| 457 RefCountedMemory* bytes) { | 457 base::RefCountedMemory* bytes) { |
| 458 // Forward this data on to the pending net::URLRequest, if it exists. | 458 // Forward this data on to the pending net::URLRequest, if it exists. |
| 459 PendingRequestMap::iterator i = pending_requests_.find(request_id); | 459 PendingRequestMap::iterator i = pending_requests_.find(request_id); |
| 460 if (i != pending_requests_.end()) { | 460 if (i != pending_requests_.end()) { |
| 461 URLRequestChromeJob* job(i->second); | 461 URLRequestChromeJob* job(i->second); |
| 462 pending_requests_.erase(i); | 462 pending_requests_.erase(i); |
| 463 job->DataAvailable(bytes); | 463 job->DataAvailable(bytes); |
| 464 } | 464 } |
| 465 } | 465 } |
| 466 | 466 |
| 467 namespace { | 467 namespace { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 | 555 |
| 556 return new URLRequestChromeJob(request, backend_); | 556 return new URLRequestChromeJob(request, backend_); |
| 557 } | 557 } |
| 558 | 558 |
| 559 } // namespace | 559 } // namespace |
| 560 | 560 |
| 561 net::URLRequestJobFactory::ProtocolHandler* | 561 net::URLRequestJobFactory::ProtocolHandler* |
| 562 CreateDevToolsProtocolHandler(ChromeURLDataManagerBackend* backend) { | 562 CreateDevToolsProtocolHandler(ChromeURLDataManagerBackend* backend) { |
| 563 return new DevToolsJobFactory(backend); | 563 return new DevToolsJobFactory(backend); |
| 564 } | 564 } |
| OLD | NEW |