Chromium Code Reviews| 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" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/thread.h" | 12 #include "base/thread.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chrome_thread.h" | |
| 15 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
| 16 #include "chrome/common/ref_counted_util.h" | 17 #include "chrome/common/ref_counted_util.h" |
| 17 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 18 #include "googleurl/src/url_util.h" | 19 #include "googleurl/src/url_util.h" |
| 19 #include "net/base/io_buffer.h" | 20 #include "net/base/io_buffer.h" |
| 20 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
| 21 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
| 22 #include "net/url_request/url_request_file_job.h" | 23 #include "net/url_request/url_request_file_job.h" |
| 23 #include "net/url_request/url_request_job.h" | 24 #include "net/url_request/url_request_job.h" |
| 24 | 25 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 // Save this request so we know where to send the data. | 219 // Save this request so we know where to send the data. |
| 219 RequestID request_id = next_request_id_++; | 220 RequestID request_id = next_request_id_++; |
| 220 pending_requests_.insert(std::make_pair(request_id, job)); | 221 pending_requests_.insert(std::make_pair(request_id, job)); |
| 221 | 222 |
| 222 // TODO(eroman): would be nicer if the mimetype were set at the same time | 223 // TODO(eroman): would be nicer if the mimetype were set at the same time |
| 223 // as the data blob. For now do it here, since NotifyHeadersComplete() is | 224 // as the data blob. For now do it here, since NotifyHeadersComplete() is |
| 224 // going to get called once we return. | 225 // going to get called once we return. |
| 225 job->SetMimeType(source->GetMimeType(path)); | 226 job->SetMimeType(source->GetMimeType(path)); |
| 226 | 227 |
| 227 // Forward along the request to the data source. | 228 // Forward along the request to the data source. |
| 228 source->message_loop()->PostTask(FROM_HERE, | 229 MessageLoop* target_message_loop = source->MessageLoopForRequestPath(path); |
| 229 NewRunnableMethod(source, &DataSource::StartDataRequest, | 230 if (!target_message_loop) { |
| 230 path, request_id)); | 231 // The DataSource is agnostic to which thread StartDataRequest is called |
| 232 // on for this path. Call directly into it from this thread, the IO | |
| 233 // thread. | |
| 234 source->StartDataRequest(path, request_id); | |
| 235 } else { | |
| 236 // The DataSource wants StartDataRequest to be called on a specific thread, | |
| 237 // usually the UI thread, for this path. | |
| 238 target_message_loop->PostTask(FROM_HERE, | |
| 239 NewRunnableMethod(source, &DataSource::StartDataRequest, | |
| 240 path, request_id)); | |
| 241 } | |
| 231 return true; | 242 return true; |
| 232 } | 243 } |
| 233 | 244 |
| 234 void ChromeURLDataManager::RemoveRequest(URLRequestChromeJob* job) { | 245 void ChromeURLDataManager::RemoveRequest(URLRequestChromeJob* job) { |
| 235 // Remove the request from our list of pending requests. | 246 // Remove the request from our list of pending requests. |
| 236 // If/when the source sends the data that was requested, the data will just | 247 // If/when the source sends the data that was requested, the data will just |
| 237 // be thrown away. | 248 // be thrown away. |
| 238 for (PendingRequestMap::iterator i = pending_requests_.begin(); | 249 for (PendingRequestMap::iterator i = pending_requests_.begin(); |
| 239 i != pending_requests_.end(); ++i) { | 250 i != pending_requests_.end(); ++i) { |
| 240 if (i->second == job) { | 251 if (i->second == job) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 254 // feet of any method invoked here (we could trigger a callback). | 265 // feet of any method invoked here (we could trigger a callback). |
| 255 scoped_refptr<URLRequestChromeJob> job = i->second; | 266 scoped_refptr<URLRequestChromeJob> job = i->second; |
| 256 pending_requests_.erase(i); | 267 pending_requests_.erase(i); |
| 257 job->DataAvailable(bytes); | 268 job->DataAvailable(bytes); |
| 258 } | 269 } |
| 259 } | 270 } |
| 260 | 271 |
| 261 void ChromeURLDataManager::DataSource::SendResponse( | 272 void ChromeURLDataManager::DataSource::SendResponse( |
| 262 RequestID request_id, | 273 RequestID request_id, |
| 263 RefCountedBytes* bytes) { | 274 RefCountedBytes* bytes) { |
| 264 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | 275 ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask(FROM_HERE, |
|
Mark Mentovai
2009/09/02 19:49:36
Here.
| |
| 265 NewRunnableMethod(&chrome_url_data_manager, | 276 NewRunnableMethod(&chrome_url_data_manager, |
| 266 &ChromeURLDataManager::DataAvailable, | 277 &ChromeURLDataManager::DataAvailable, |
| 267 request_id, scoped_refptr<RefCountedBytes>(bytes))); | 278 request_id, scoped_refptr<RefCountedBytes>(bytes))); |
| 268 } | 279 } |
| 269 | 280 |
| 281 MessageLoop* ChromeURLDataManager::DataSource::MessageLoopForRequestPath( | |
| 282 const std::string& path) const { | |
| 283 return message_loop_; | |
| 284 } | |
| 285 | |
| 270 // static | 286 // static |
| 271 void ChromeURLDataManager::DataSource::SetFontAndTextDirection( | 287 void ChromeURLDataManager::DataSource::SetFontAndTextDirection( |
| 272 DictionaryValue* localized_strings) { | 288 DictionaryValue* localized_strings) { |
| 273 localized_strings->SetString(L"fontfamily", | 289 localized_strings->SetString(L"fontfamily", |
| 274 l10n_util::GetString(IDS_WEB_FONT_FAMILY)); | 290 l10n_util::GetString(IDS_WEB_FONT_FAMILY)); |
| 275 localized_strings->SetString(L"fontsize", | 291 localized_strings->SetString(L"fontsize", |
| 276 l10n_util::GetString(IDS_WEB_FONT_SIZE)); | 292 l10n_util::GetString(IDS_WEB_FONT_SIZE)); |
| 277 | 293 |
| 278 localized_strings->SetString(L"textdirection", | 294 localized_strings->SetString(L"textdirection", |
| 279 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ? | 295 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ? |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 net::ERR_INVALID_URL)); | 390 net::ERR_INVALID_URL)); |
| 375 } | 391 } |
| 376 } | 392 } |
| 377 | 393 |
| 378 URLRequestChromeFileJob::URLRequestChromeFileJob(URLRequest* request, | 394 URLRequestChromeFileJob::URLRequestChromeFileJob(URLRequest* request, |
| 379 const FilePath& path) | 395 const FilePath& path) |
| 380 : URLRequestFileJob(request, path) { | 396 : URLRequestFileJob(request, path) { |
| 381 } | 397 } |
| 382 | 398 |
| 383 URLRequestChromeFileJob::~URLRequestChromeFileJob() { } | 399 URLRequestChromeFileJob::~URLRequestChromeFileJob() { } |
| OLD | NEW |