Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Side by Side Diff: chrome/browser/download/download_file.cc

Issue 258008: Move initialization of ChromeURLRequestContexts to the IO thread. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync again, just in case Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/download/download_file.h ('k') | chrome/browser/download/download_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/download/download_file.h" 5 #include "chrome/browser/download/download_file.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/task.h" 11 #include "base/task.h"
12 #include "base/thread.h" 12 #include "base/thread.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/download/download_manager.h" 15 #include "chrome/browser/download/download_manager.h"
16 #include "chrome/browser/net/chrome_url_request_context.h"
16 #include "chrome/browser/profile.h" 17 #include "chrome/browser/profile.h"
17 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" 18 #include "chrome/browser/renderer_host/resource_dispatcher_host.h"
18 #include "chrome/browser/tab_contents/tab_util.h" 19 #include "chrome/browser/tab_contents/tab_util.h"
19 #include "chrome/browser/tab_contents/tab_contents.h" 20 #include "chrome/browser/tab_contents/tab_contents.h"
20 #include "chrome/common/chrome_paths.h" 21 #include "chrome/common/chrome_paths.h"
21 #include "chrome/common/platform_util.h" 22 #include "chrome/common/platform_util.h"
22 #include "googleurl/src/gurl.h" 23 #include "googleurl/src/gurl.h"
23 #include "net/base/io_buffer.h" 24 #include "net/base/io_buffer.h"
24 #include "net/base/net_util.h" 25 #include "net/base/net_util.h"
25 #include "net/url_request/url_request_context.h" 26 #include "net/url_request/url_request_context.h"
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 void DownloadFileManager::OnDownloadFinished(int id, 416 void DownloadFileManager::OnDownloadFinished(int id,
416 int64 bytes_so_far) { 417 int64 bytes_so_far) {
417 DCHECK(MessageLoop::current() == ui_loop_); 418 DCHECK(MessageLoop::current() == ui_loop_);
418 DownloadManager* manager = LookupManager(id); 419 DownloadManager* manager = LookupManager(id);
419 if (manager) 420 if (manager)
420 manager->DownloadFinished(id, bytes_so_far); 421 manager->DownloadFinished(id, bytes_so_far);
421 RemoveDownload(id, manager); 422 RemoveDownload(id, manager);
422 RemoveDownloadFromUIProgress(id); 423 RemoveDownloadFromUIProgress(id);
423 } 424 }
424 425
425 void DownloadFileManager::DownloadUrl(const GURL& url, 426 void DownloadFileManager::DownloadUrl(
426 const GURL& referrer, 427 const GURL& url,
427 int render_process_host_id, 428 const GURL& referrer,
428 int render_view_id, 429 const std::string& referrer_charset,
429 URLRequestContext* request_context) { 430 int render_process_host_id,
431 int render_view_id,
432 URLRequestContextGetter* request_context_getter) {
430 DCHECK(MessageLoop::current() == ui_loop_); 433 DCHECK(MessageLoop::current() == ui_loop_);
431 base::Thread* thread = g_browser_process->io_thread(); 434 base::Thread* thread = g_browser_process->io_thread();
432 if (thread) { 435 if (thread) {
433 thread->message_loop()->PostTask(FROM_HERE, 436 thread->message_loop()->PostTask(FROM_HERE,
434 NewRunnableMethod(this, 437 NewRunnableMethod(this,
435 &DownloadFileManager::OnDownloadUrl, 438 &DownloadFileManager::OnDownloadUrl,
436 url, 439 url,
437 referrer, 440 referrer,
441 referrer_charset,
438 render_process_host_id, 442 render_process_host_id,
439 render_view_id, 443 render_view_id,
440 request_context)); 444 request_context_getter));
441 } 445 }
442 } 446 }
443 447
444 // Relate a download ID to its owning DownloadManager. 448 // Relate a download ID to its owning DownloadManager.
445 DownloadManager* DownloadFileManager::LookupManager(int download_id) { 449 DownloadManager* DownloadFileManager::LookupManager(int download_id) {
446 DCHECK(MessageLoop::current() == ui_loop_); 450 DCHECK(MessageLoop::current() == ui_loop_);
447 DownloadManagerMap::iterator it = managers_.find(download_id); 451 DownloadManagerMap::iterator it = managers_.find(download_id);
448 if (it != managers_.end()) 452 if (it != managers_.end())
449 return it->second; 453 return it->second;
450 return NULL; 454 return NULL;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 } 513 }
510 } 514 }
511 515
512 requests_.erase(it); 516 requests_.erase(it);
513 } 517 }
514 518
515 519
516 // Notifications from the UI thread and run on the IO thread 520 // Notifications from the UI thread and run on the IO thread
517 521
518 // Initiate a request for URL to be downloaded. 522 // Initiate a request for URL to be downloaded.
519 void DownloadFileManager::OnDownloadUrl(const GURL& url, 523 void DownloadFileManager::OnDownloadUrl(
520 const GURL& referrer, 524 const GURL& url,
521 int render_process_host_id, 525 const GURL& referrer,
522 int render_view_id, 526 const std::string& referrer_charset,
523 URLRequestContext* request_context) { 527 int render_process_host_id,
528 int render_view_id,
529 URLRequestContextGetter* request_context_getter) {
524 DCHECK(MessageLoop::current() == io_loop_); 530 DCHECK(MessageLoop::current() == io_loop_);
531
532 URLRequestContext* context = request_context_getter->GetURLRequestContext();
533 context->set_referrer_charset(referrer_charset);
534
525 resource_dispatcher_host_->BeginDownload(url, 535 resource_dispatcher_host_->BeginDownload(url,
526 referrer, 536 referrer,
527 render_process_host_id, 537 render_process_host_id,
528 render_view_id, 538 render_view_id,
529 request_context); 539 context);
530 } 540 }
531 541
532 // Actions from the UI thread and run on the download thread 542 // Actions from the UI thread and run on the download thread
533 543
534 // Open a download, or show it in a file explorer window. We run on this 544 // Open a download, or show it in a file explorer window. We run on this
535 // thread to avoid blocking the UI with (potentially) slow Shell operations. 545 // thread to avoid blocking the UI with (potentially) slow Shell operations.
536 // TODO(paulg): File 'stat' operations. 546 // TODO(paulg): File 'stat' operations.
537 #if !defined(OS_MACOSX) 547 #if !defined(OS_MACOSX)
538 void DownloadFileManager::OnShowDownloadInShell(const FilePath& full_path) { 548 void DownloadFileManager::OnShowDownloadInShell(const FilePath& full_path) {
539 DCHECK(MessageLoop::current() == file_loop_); 549 DCHECK(MessageLoop::current() == file_loop_);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( 624 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(
615 this, &DownloadFileManager::StopUpdateTimer)); 625 this, &DownloadFileManager::StopUpdateTimer));
616 } 626 }
617 627
618 // static 628 // static
619 void DownloadFileManager::DeleteFile(const FilePath& path) { 629 void DownloadFileManager::DeleteFile(const FilePath& path) {
620 // Make sure we only delete files. 630 // Make sure we only delete files.
621 if (!file_util::DirectoryExists(path)) 631 if (!file_util::DirectoryExists(path))
622 file_util::Delete(path, false); 632 file_util::Delete(path, false);
623 } 633 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_file.h ('k') | chrome/browser/download/download_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698