| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 10 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 11 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 12 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 13 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 14 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 15 #include "chrome/browser/net/chrome_url_request_context.h" | 17 #include "chrome/browser/net/chrome_url_request_context.h" |
| 16 #include "chrome/browser/net/view_blob_internals_job_factory.h" | 18 #include "chrome/browser/net/view_blob_internals_job_factory.h" |
| 17 #include "chrome/browser/net/view_http_cache_job_factory.h" | 19 #include "chrome/browser/net/view_http_cache_job_factory.h" |
| 18 #include "chrome/browser/ui/webui/shared_resources_data_source.h" | 20 #include "chrome/browser/ui/webui/shared_resources_data_source.h" |
| 19 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
| 20 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 109 |
| 108 // For async reads, we keep around a pointer to the buffer that | 110 // For async reads, we keep around a pointer to the buffer that |
| 109 // we're reading into. | 111 // we're reading into. |
| 110 scoped_refptr<net::IOBuffer> pending_buf_; | 112 scoped_refptr<net::IOBuffer> pending_buf_; |
| 111 int pending_buf_size_; | 113 int pending_buf_size_; |
| 112 std::string mime_type_; | 114 std::string mime_type_; |
| 113 | 115 |
| 114 // The backend is owned by ChromeURLRequestContext and always outlives us. | 116 // The backend is owned by ChromeURLRequestContext and always outlives us. |
| 115 ChromeURLDataManagerBackend* backend_; | 117 ChromeURLDataManagerBackend* backend_; |
| 116 | 118 |
| 117 ScopedRunnableMethodFactory<URLRequestChromeJob> method_factory_; | 119 base::WeakPtrFactory<URLRequestChromeJob> weak_factory_; |
| 118 | 120 |
| 119 DISALLOW_COPY_AND_ASSIGN(URLRequestChromeJob); | 121 DISALLOW_COPY_AND_ASSIGN(URLRequestChromeJob); |
| 120 }; | 122 }; |
| 121 | 123 |
| 122 URLRequestChromeJob::URLRequestChromeJob(net::URLRequest* request, | 124 URLRequestChromeJob::URLRequestChromeJob(net::URLRequest* request, |
| 123 ChromeURLDataManagerBackend* backend) | 125 ChromeURLDataManagerBackend* backend) |
| 124 : net::URLRequestJob(request), | 126 : net::URLRequestJob(request), |
| 125 data_offset_(0), | 127 data_offset_(0), |
| 126 pending_buf_size_(0), | 128 pending_buf_size_(0), |
| 127 backend_(backend), | 129 backend_(backend), |
| 128 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 130 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 129 DCHECK(backend); | 131 DCHECK(backend); |
| 130 } | 132 } |
| 131 | 133 |
| 132 URLRequestChromeJob::~URLRequestChromeJob() { | 134 URLRequestChromeJob::~URLRequestChromeJob() { |
| 133 CHECK(!backend_->HasPendingJob(this)); | 135 CHECK(!backend_->HasPendingJob(this)); |
| 134 } | 136 } |
| 135 | 137 |
| 136 void URLRequestChromeJob::Start() { | 138 void URLRequestChromeJob::Start() { |
| 137 // Start reading asynchronously so that all error reporting and data | 139 // Start reading asynchronously so that all error reporting and data |
| 138 // callbacks happen as they would for network requests. | 140 // callbacks happen as they would for network requests. |
| 139 MessageLoop::current()->PostTask(FROM_HERE, method_factory_.NewRunnableMethod( | 141 MessageLoop::current()->PostTask( |
| 140 &URLRequestChromeJob::StartAsync)); | 142 FROM_HERE, |
| 143 base::Bind(&URLRequestChromeJob::StartAsync, |
| 144 weak_factory_.GetWeakPtr())); |
| 141 } | 145 } |
| 142 | 146 |
| 143 void URLRequestChromeJob::Kill() { | 147 void URLRequestChromeJob::Kill() { |
| 144 backend_->RemoveRequest(this); | 148 backend_->RemoveRequest(this); |
| 145 } | 149 } |
| 146 | 150 |
| 147 bool URLRequestChromeJob::GetMimeType(std::string* mime_type) const { | 151 bool URLRequestChromeJob::GetMimeType(std::string* mime_type) const { |
| 148 *mime_type = mime_type_; | 152 *mime_type = mime_type_; |
| 149 return !mime_type_.empty(); | 153 return !mime_type_.empty(); |
| 150 } | 154 } |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 if (!target_message_loop) { | 364 if (!target_message_loop) { |
| 361 // The DataSource is agnostic to which thread StartDataRequest is called | 365 // The DataSource is agnostic to which thread StartDataRequest is called |
| 362 // on for this path. Call directly into it from this thread, the IO | 366 // on for this path. Call directly into it from this thread, the IO |
| 363 // thread. | 367 // thread. |
| 364 source->StartDataRequest(path, context->is_incognito(), request_id); | 368 source->StartDataRequest(path, context->is_incognito(), request_id); |
| 365 } else { | 369 } else { |
| 366 // The DataSource wants StartDataRequest to be called on a specific thread, | 370 // The DataSource wants StartDataRequest to be called on a specific thread, |
| 367 // usually the UI thread, for this path. | 371 // usually the UI thread, for this path. |
| 368 target_message_loop->PostTask( | 372 target_message_loop->PostTask( |
| 369 FROM_HERE, | 373 FROM_HERE, |
| 370 NewRunnableMethod(source, | 374 base::Bind(&ChromeURLDataManager::DataSource::StartDataRequest, source, |
| 371 &ChromeURLDataManager::DataSource::StartDataRequest, | 375 path, context->is_incognito(), request_id)); |
| 372 path, context->is_incognito(), request_id)); | |
| 373 } | 376 } |
| 374 return true; | 377 return true; |
| 375 } | 378 } |
| 376 | 379 |
| 377 void ChromeURLDataManagerBackend::RemoveRequest(URLRequestChromeJob* job) { | 380 void ChromeURLDataManagerBackend::RemoveRequest(URLRequestChromeJob* job) { |
| 378 // Remove the request from our list of pending requests. | 381 // Remove the request from our list of pending requests. |
| 379 // If/when the source sends the data that was requested, the data will just | 382 // If/when the source sends the data that was requested, the data will just |
| 380 // be thrown away. | 383 // be thrown away. |
| 381 for (PendingRequestMap::iterator i = pending_requests_.begin(); | 384 for (PendingRequestMap::iterator i = pending_requests_.begin(); |
| 382 i != pending_requests_.end(); ++i) { | 385 i != pending_requests_.end(); ++i) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 | 492 |
| 490 return new URLRequestChromeJob(request, backend_); | 493 return new URLRequestChromeJob(request, backend_); |
| 491 } | 494 } |
| 492 | 495 |
| 493 } // namespace | 496 } // namespace |
| 494 | 497 |
| 495 net::URLRequestJobFactory::ProtocolHandler* | 498 net::URLRequestJobFactory::ProtocolHandler* |
| 496 CreateDevToolsProtocolHandler(ChromeURLDataManagerBackend* backend) { | 499 CreateDevToolsProtocolHandler(ChromeURLDataManagerBackend* backend) { |
| 497 return new DevToolsJobFactory(backend); | 500 return new DevToolsJobFactory(backend); |
| 498 } | 501 } |
| OLD | NEW |