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

Side by Side Diff: content/browser/download/download_file_manager.cc

Issue 8371009: Make passing of DownloadRequestHandle separate from DownloadCreateInfo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to LKGR. Created 9 years, 1 month 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
OLDNEW
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 "content/browser/download/download_file_manager.h" 5 #include "content/browser/download/download_file_manager.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/task.h" 10 #include "base/task.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "content/browser/browser_thread.h" 12 #include "content/browser/browser_thread.h"
13 #include "content/browser/download/download_buffer.h" 13 #include "content/browser/download/download_buffer.h"
14 #include "content/browser/download/download_create_info.h"
14 #include "content/browser/download/download_file.h" 15 #include "content/browser/download/download_file.h"
15 #include "content/browser/download/download_create_info.h"
16 #include "content/browser/download/download_manager.h" 16 #include "content/browser/download/download_manager.h"
17 #include "content/browser/download/download_request_handle.h"
17 #include "content/browser/renderer_host/resource_dispatcher_host.h" 18 #include "content/browser/renderer_host/resource_dispatcher_host.h"
18 #include "content/browser/tab_contents/tab_contents.h" 19 #include "content/browser/tab_contents/tab_contents.h"
19 #include "content/public/browser/download_manager_delegate.h" 20 #include "content/public/browser/download_manager_delegate.h"
20 #include "googleurl/src/gurl.h" 21 #include "googleurl/src/gurl.h"
21 #include "net/base/io_buffer.h" 22 #include "net/base/io_buffer.h"
22 23
23 namespace { 24 namespace {
24 25
25 // Throttle updates to the UI thread so that a fast moving download doesn't 26 // Throttle updates to the UI thread so that a fast moving download doesn't
26 // cause it to become unresponsive (in milliseconds). 27 // cause it to become unresponsive (in milliseconds).
(...skipping 15 matching lines...) Expand all
42 BrowserThread::FILE, FROM_HERE, 43 BrowserThread::FILE, FROM_HERE,
43 NewRunnableMethod(this, &DownloadFileManager::OnShutdown)); 44 NewRunnableMethod(this, &DownloadFileManager::OnShutdown));
44 } 45 }
45 46
46 void DownloadFileManager::OnShutdown() { 47 void DownloadFileManager::OnShutdown() {
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
48 StopUpdateTimer(); 49 StopUpdateTimer();
49 STLDeleteValues(&downloads_); 50 STLDeleteValues(&downloads_);
50 } 51 }
51 52
52 void DownloadFileManager::CreateDownloadFile(DownloadCreateInfo* info, 53 void DownloadFileManager::CreateDownloadFile(
53 DownloadManager* download_manager, 54 DownloadCreateInfo* info, const DownloadRequestHandle& request_handle,
54 bool get_hash) { 55 DownloadManager* download_manager, bool get_hash) {
55 DCHECK(info); 56 DCHECK(info);
56 VLOG(20) << __FUNCTION__ << "()" << " info = " << info->DebugString(); 57 VLOG(20) << __FUNCTION__ << "()" << " info = " << info->DebugString();
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
58 59
59 // Life of |info| ends here. No more references to it after this method. 60 // Life of |info| ends here. No more references to it after this method.
60 scoped_ptr<DownloadCreateInfo> infop(info); 61 scoped_ptr<DownloadCreateInfo> infop(info);
61 62
62 scoped_ptr<DownloadFile> 63 scoped_ptr<DownloadFile>
63 download_file(new DownloadFile(info, download_manager)); 64 download_file(new DownloadFile(info, request_handle, download_manager));
64 if (net::OK != download_file->Initialize(get_hash)) { 65 if (net::OK != download_file->Initialize(get_hash)) {
65 info->request_handle.CancelRequest(); 66 request_handle.CancelRequest();
66 return; 67 return;
67 } 68 }
68 69
69 DownloadId global_id(download_manager, info->download_id); 70 DownloadId global_id(download_manager, info->download_id);
70 DCHECK(GetDownloadFile(global_id) == NULL); 71 DCHECK(GetDownloadFile(global_id) == NULL);
71 downloads_[global_id] = download_file.release(); 72 downloads_[global_id] = download_file.release();
72 73
73 // The file is now ready, we can un-pause the request and start saving data. 74 // The file is now ready, we can un-pause the request and start saving data.
74 info->request_handle.ResumeRequest(); 75 request_handle.ResumeRequest();
75 76
76 StartUpdateTimer(); 77 StartUpdateTimer();
77 78
78 BrowserThread::PostTask( 79 BrowserThread::PostTask(
79 BrowserThread::UI, FROM_HERE, 80 BrowserThread::UI, FROM_HERE,
80 NewRunnableMethod(download_manager, 81 NewRunnableMethod(download_manager,
81 &DownloadManager::StartDownload, info->download_id)); 82 &DownloadManager::StartDownload, info->download_id));
82 } 83 }
83 84
84 DownloadFile* DownloadFileManager::GetDownloadFile(DownloadId global_id) { 85 DownloadFile* DownloadFileManager::GetDownloadFile(DownloadId global_id) {
(...skipping 23 matching lines...) Expand all
108 DownloadFile* download_file = i->second; 109 DownloadFile* download_file = i->second;
109 DownloadManager* manager = download_file->GetDownloadManager(); 110 DownloadManager* manager = download_file->GetDownloadManager();
110 if (manager) { 111 if (manager) {
111 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 112 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
112 NewRunnableMethod(manager, &DownloadManager::UpdateDownload, 113 NewRunnableMethod(manager, &DownloadManager::UpdateDownload,
113 global_id.local(), download_file->bytes_so_far())); 114 global_id.local(), download_file->bytes_so_far()));
114 } 115 }
115 } 116 }
116 } 117 }
117 118
118 void DownloadFileManager::StartDownload(DownloadCreateInfo* info) { 119 void DownloadFileManager::StartDownload(
120 DownloadCreateInfo* info, const DownloadRequestHandle& request_handle) {
119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
120 DCHECK(info); 122 DCHECK(info);
121 123
122 DownloadManager* manager = info->request_handle.GetDownloadManager(); 124 DownloadManager* manager = request_handle.GetDownloadManager();
123 if (!manager) { 125 if (!manager) {
124 info->request_handle.CancelRequest(); 126 request_handle.CancelRequest();
125 delete info; 127 delete info;
126 return; 128 return;
127 } 129 }
128 130
129 // TODO(phajdan.jr): fix the duplication of path info below. 131 // TODO(phajdan.jr): fix the duplication of path info below.
130 info->path = info->save_info.file_path; 132 info->path = info->save_info.file_path;
131 133
132 manager->CreateDownloadItem(info); 134 manager->CreateDownloadItem(info, request_handle);
133 bool hash_needed = manager->delegate()->GenerateFileHash(); 135 bool hash_needed = manager->delegate()->GenerateFileHash();
134 136
135 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 137 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
136 NewRunnableMethod(this, &DownloadFileManager::CreateDownloadFile, 138 NewRunnableMethod(this, &DownloadFileManager::CreateDownloadFile,
137 info, make_scoped_refptr(manager), hash_needed)); 139 info, request_handle, make_scoped_refptr(manager),
140 hash_needed));
138 } 141 }
139 142
140 // We don't forward an update to the UI thread here, since we want to throttle 143 // We don't forward an update to the UI thread here, since we want to throttle
141 // the UI update rate via a periodic timer. If the user has cancelled the 144 // the UI update rate via a periodic timer. If the user has cancelled the
142 // download (in the UI thread), we may receive a few more updates before the IO 145 // download (in the UI thread), we may receive a few more updates before the IO
143 // thread gets the cancel message: we just delete the data since the 146 // thread gets the cancel message: we just delete the data since the
144 // DownloadFile has been deleted. 147 // DownloadFile has been deleted.
145 void DownloadFileManager::UpdateDownload( 148 void DownloadFileManager::UpdateDownload(
146 DownloadId global_id, content::DownloadBuffer* buffer) { 149 DownloadId global_id, content::DownloadBuffer* buffer) {
147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 << " id = " << global_id 430 << " id = " << global_id
428 << " download_file = " << download_file->DebugString(); 431 << " download_file = " << download_file->DebugString();
429 432
430 downloads_.erase(global_id); 433 downloads_.erase(global_id);
431 434
432 delete download_file; 435 delete download_file;
433 436
434 if (downloads_.empty()) 437 if (downloads_.empty())
435 StopUpdateTimer(); 438 StopUpdateTimer();
436 } 439 }
OLDNEW
« no previous file with comments | « content/browser/download/download_file_manager.h ('k') | content/browser/download/download_file_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698