| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/dom_ui/chrome_url_data_manager.h" | 5 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 const std::wstring& file_path) { | 192 const std::wstring& file_path) { |
| 193 DCHECK(file_sources_.count(source_name) == 0); | 193 DCHECK(file_sources_.count(source_name) == 0); |
| 194 file_sources_[source_name] = file_path; | 194 file_sources_[source_name] = file_path; |
| 195 } | 195 } |
| 196 | 196 |
| 197 void ChromeURLDataManager::RemoveFileSource(const std::string& source_name) { | 197 void ChromeURLDataManager::RemoveFileSource(const std::string& source_name) { |
| 198 DCHECK(file_sources_.count(source_name) == 1); | 198 DCHECK(file_sources_.count(source_name) == 1); |
| 199 file_sources_.erase(source_name); | 199 file_sources_.erase(source_name); |
| 200 } | 200 } |
| 201 | 201 |
| 202 bool ChromeURLDataManager::HasPendingJob(URLRequestChromeJob* job) const { | |
| 203 for (PendingRequestMap::const_iterator i = pending_requests_.begin(); | |
| 204 i != pending_requests_.end(); ++i) { | |
| 205 if (i->second == job) | |
| 206 return true; | |
| 207 } | |
| 208 | |
| 209 return false; | |
| 210 } | |
| 211 | |
| 212 bool ChromeURLDataManager::StartRequest(const GURL& url, | 202 bool ChromeURLDataManager::StartRequest(const GURL& url, |
| 213 URLRequestChromeJob* job) { | 203 URLRequestChromeJob* job) { |
| 214 // Parse the URL into a request for a source and path. | 204 // Parse the URL into a request for a source and path. |
| 215 std::string source_name; | 205 std::string source_name; |
| 216 std::string path; | 206 std::string path; |
| 217 URLToRequest(url, &source_name, &path); | 207 URLToRequest(url, &source_name, &path); |
| 218 | 208 |
| 219 // Look up the data source for the request. | 209 // Look up the data source for the request. |
| 220 DataSourceMap::iterator i = data_sources_.find(source_name); | 210 DataSourceMap::iterator i = data_sources_.find(source_name); |
| 221 if (i == data_sources_.end()) | 211 if (i == data_sources_.end()) |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 FilePath::FromWStringHack(path)); | 286 FilePath::FromWStringHack(path)); |
| 297 | 287 |
| 298 // Fall back to using a custom handler | 288 // Fall back to using a custom handler |
| 299 return new URLRequestChromeJob(request); | 289 return new URLRequestChromeJob(request); |
| 300 } | 290 } |
| 301 | 291 |
| 302 URLRequestChromeJob::URLRequestChromeJob(URLRequest* request) | 292 URLRequestChromeJob::URLRequestChromeJob(URLRequest* request) |
| 303 : URLRequestJob(request), data_offset_(0) {} | 293 : URLRequestJob(request), data_offset_(0) {} |
| 304 | 294 |
| 305 URLRequestChromeJob::~URLRequestChromeJob() { | 295 URLRequestChromeJob::~URLRequestChromeJob() { |
| 306 CHECK(!chrome_url_data_manager.HasPendingJob(this)); | |
| 307 } | 296 } |
| 308 | 297 |
| 309 void URLRequestChromeJob::Start() { | 298 void URLRequestChromeJob::Start() { |
| 310 // Start reading asynchronously so that all error reporting and data | 299 // Start reading asynchronously so that all error reporting and data |
| 311 // callbacks happen as they would for network requests. | 300 // callbacks happen as they would for network requests. |
| 312 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 301 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
| 313 this, &URLRequestChromeJob::StartAsync)); | 302 this, &URLRequestChromeJob::StartAsync)); |
| 314 } | 303 } |
| 315 | 304 |
| 316 void URLRequestChromeJob::Kill() { | 305 void URLRequestChromeJob::Kill() { |
| 317 chrome_url_data_manager.RemoveRequest(this); | 306 chrome_url_data_manager.RemoveRequest(this); |
| 318 } | 307 } |
| 319 | 308 |
| 320 bool URLRequestChromeJob::GetMimeType(std::string* mime_type) const { | 309 bool URLRequestChromeJob::GetMimeType(std::string* mime_type) const { |
| 321 *mime_type = mime_type_; | 310 *mime_type = mime_type_; |
| 322 return !mime_type_.empty(); | 311 return !mime_type_.empty(); |
| 323 } | 312 } |
| 324 | 313 |
| 325 void URLRequestChromeJob::DataAvailable(RefCountedBytes* bytes) { | 314 void URLRequestChromeJob::DataAvailable(RefCountedBytes* bytes) { |
| 326 if (bytes) { | 315 if (bytes) { |
| 327 // The request completed, and we have all the data. | 316 // The request completed, and we have all the data. |
| 328 // Clear any IO pending status. | 317 // Clear any IO pending status. |
| 329 SetStatus(URLRequestStatus()); | 318 SetStatus(URLRequestStatus()); |
| 330 | 319 |
| 331 data_ = bytes; | 320 data_ = bytes; |
| 332 int bytes_read; | 321 int bytes_read; |
| 333 if (pending_buf_.get()) { | 322 if (pending_buf_.get()) { |
| 334 CHECK(pending_buf_->data()); | |
| 335 CompleteRead(pending_buf_, pending_buf_size_, &bytes_read); | 323 CompleteRead(pending_buf_, pending_buf_size_, &bytes_read); |
| 336 pending_buf_ = NULL; | 324 pending_buf_ = NULL; |
| 337 NotifyReadComplete(bytes_read); | 325 NotifyReadComplete(bytes_read); |
| 338 } | 326 } |
| 339 } else { | 327 } else { |
| 340 // The request failed. | 328 // The request failed. |
| 341 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, 0)); | 329 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, 0)); |
| 342 } | 330 } |
| 343 } | 331 } |
| 344 | 332 |
| 345 bool URLRequestChromeJob::ReadRawData(net::IOBuffer* buf, int buf_size, | 333 bool URLRequestChromeJob::ReadRawData(net::IOBuffer* buf, int buf_size, |
| 346 int* bytes_read) { | 334 int* bytes_read) { |
| 347 if (!data_.get()) { | 335 if (!data_.get()) { |
| 348 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 336 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 349 DCHECK(!pending_buf_.get()); | 337 DCHECK(!pending_buf_.get()); |
| 350 CHECK(buf->data()); | |
| 351 pending_buf_ = buf; | 338 pending_buf_ = buf; |
| 352 pending_buf_size_ = buf_size; | 339 pending_buf_size_ = buf_size; |
| 353 return false; // Tell the caller we're still waiting for data. | 340 return false; // Tell the caller we're still waiting for data. |
| 354 } | 341 } |
| 355 | 342 |
| 356 // Otherwise, the data is available. | 343 // Otherwise, the data is available. |
| 357 CompleteRead(buf, buf_size, bytes_read); | 344 CompleteRead(buf, buf_size, bytes_read); |
| 358 return true; | 345 return true; |
| 359 } | 346 } |
| 360 | 347 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 381 net::ERR_INVALID_URL)); | 368 net::ERR_INVALID_URL)); |
| 382 } | 369 } |
| 383 } | 370 } |
| 384 | 371 |
| 385 URLRequestChromeFileJob::URLRequestChromeFileJob(URLRequest* request, | 372 URLRequestChromeFileJob::URLRequestChromeFileJob(URLRequest* request, |
| 386 const FilePath& path) | 373 const FilePath& path) |
| 387 : URLRequestFileJob(request, path) { | 374 : URLRequestFileJob(request, path) { |
| 388 } | 375 } |
| 389 | 376 |
| 390 URLRequestChromeFileJob::~URLRequestChromeFileJob() { } | 377 URLRequestChromeFileJob::~URLRequestChromeFileJob() { } |
| OLD | NEW |