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