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

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

Issue 9296012: Hooked up NetLog to DownloadItem, DownloadFile, and FileStream. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with trunk Created 8 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 28 matching lines...) Expand all
39 39
40 class DownloadFileFactoryImpl 40 class DownloadFileFactoryImpl
41 : public DownloadFileManager::DownloadFileFactory { 41 : public DownloadFileManager::DownloadFileFactory {
42 public: 42 public:
43 DownloadFileFactoryImpl() {} 43 DownloadFileFactoryImpl() {}
44 44
45 virtual content::DownloadFile* CreateFile( 45 virtual content::DownloadFile* CreateFile(
46 DownloadCreateInfo* info, 46 DownloadCreateInfo* info,
47 const DownloadRequestHandle& request_handle, 47 const DownloadRequestHandle& request_handle,
48 DownloadManager* download_manager, 48 DownloadManager* download_manager,
49 bool calculate_hash) OVERRIDE; 49 bool calculate_hash,
50 const net::BoundNetLog& bound_net_log) OVERRIDE;
50 }; 51 };
51 52
52 DownloadFile* DownloadFileFactoryImpl::CreateFile( 53 DownloadFile* DownloadFileFactoryImpl::CreateFile(
53 DownloadCreateInfo* info, 54 DownloadCreateInfo* info,
54 const DownloadRequestHandle& request_handle, 55 const DownloadRequestHandle& request_handle,
55 DownloadManager* download_manager, 56 DownloadManager* download_manager,
56 bool calculate_hash) { 57 bool calculate_hash,
58 const net::BoundNetLog& bound_net_log) {
57 return new DownloadFileImpl(info, 59 return new DownloadFileImpl(info,
58 new DownloadRequestHandle(request_handle), 60 new DownloadRequestHandle(request_handle),
59 download_manager, calculate_hash); 61 download_manager, calculate_hash,
62 bound_net_log);
60 } 63 }
61 64
62 } // namespace 65 } // namespace
63 66
64 DownloadFileManager::DownloadFileManager(ResourceDispatcherHost* rdh, 67 DownloadFileManager::DownloadFileManager(ResourceDispatcherHost* rdh,
65 DownloadFileFactory* factory) 68 DownloadFileFactory* factory)
66 : resource_dispatcher_host_(rdh), download_file_factory_(factory) { 69 : resource_dispatcher_host_(rdh), download_file_factory_(factory) {
67 if (download_file_factory_ == NULL) 70 if (download_file_factory_ == NULL)
68 download_file_factory_.reset(new DownloadFileFactoryImpl); 71 download_file_factory_.reset(new DownloadFileFactoryImpl);
69 } 72 }
(...skipping 10 matching lines...) Expand all
80 } 83 }
81 84
82 void DownloadFileManager::OnShutdown() { 85 void DownloadFileManager::OnShutdown() {
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
84 StopUpdateTimer(); 87 StopUpdateTimer();
85 STLDeleteValues(&downloads_); 88 STLDeleteValues(&downloads_);
86 } 89 }
87 90
88 void DownloadFileManager::CreateDownloadFile( 91 void DownloadFileManager::CreateDownloadFile(
89 DownloadCreateInfo* info, const DownloadRequestHandle& request_handle, 92 DownloadCreateInfo* info, const DownloadRequestHandle& request_handle,
90 DownloadManager* download_manager, bool get_hash) { 93 DownloadManager* download_manager, bool get_hash,
94 const net::BoundNetLog& bound_net_log) {
91 DCHECK(info); 95 DCHECK(info);
92 VLOG(20) << __FUNCTION__ << "()" << " info = " << info->DebugString(); 96 VLOG(20) << __FUNCTION__ << "()" << " info = " << info->DebugString();
93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
94 98
95 // Life of |info| ends here. No more references to it after this method. 99 // Life of |info| ends here. No more references to it after this method.
96 scoped_ptr<DownloadCreateInfo> infop(info); 100 scoped_ptr<DownloadCreateInfo> infop(info);
97 101
98 scoped_ptr<DownloadFile> download_file(download_file_factory_->CreateFile( 102 scoped_ptr<DownloadFile> download_file(download_file_factory_->CreateFile(
99 info, request_handle, download_manager, get_hash)); 103 info, request_handle, download_manager, get_hash, bound_net_log));
100 if (net::OK != download_file->Initialize()) { 104 if (net::OK != download_file->Initialize()) {
101 request_handle.CancelRequest(); 105 request_handle.CancelRequest();
102 return; 106 return;
103 } 107 }
104 108
105 DCHECK(GetDownloadFile(info->download_id) == NULL); 109 DCHECK(GetDownloadFile(info->download_id) == NULL);
106 downloads_[info->download_id] = download_file.release(); 110 downloads_[info->download_id] = download_file.release();
107 111
108 // The file is now ready, we can un-pause the request and start saving data. 112 // The file is now ready, we can un-pause the request and start saving data.
109 request_handle.ResumeRequest(); 113 request_handle.ResumeRequest();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
161 DCHECK(info); 165 DCHECK(info);
162 166
163 DownloadManager* manager = request_handle.GetDownloadManager(); 167 DownloadManager* manager = request_handle.GetDownloadManager();
164 if (!manager) { 168 if (!manager) {
165 request_handle.CancelRequest(); 169 request_handle.CancelRequest();
166 delete info; 170 delete info;
167 return; 171 return;
168 } 172 }
169 173
170 manager->CreateDownloadItem(info, request_handle); 174 // |bound_net_log| will be used for logging the both the download item's and
175 // the download file's events.
176 net::BoundNetLog bound_net_log =
177 manager->CreateDownloadItem(info, request_handle);
171 bool hash_needed = manager->GenerateFileHash(); 178 bool hash_needed = manager->GenerateFileHash();
172 179
173 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 180 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
174 base::Bind(&DownloadFileManager::CreateDownloadFile, this, 181 base::Bind(&DownloadFileManager::CreateDownloadFile, this,
175 info, request_handle, make_scoped_refptr(manager), 182 info, request_handle, make_scoped_refptr(manager),
176 hash_needed)); 183 hash_needed, bound_net_log));
177 } 184 }
178 185
179 // We don't forward an update to the UI thread here, since we want to throttle 186 // We don't forward an update to the UI thread here, since we want to throttle
180 // the UI update rate via a periodic timer. If the user has cancelled the 187 // the UI update rate via a periodic timer. If the user has cancelled the
181 // download (in the UI thread), we may receive a few more updates before the IO 188 // download (in the UI thread), we may receive a few more updates before the IO
182 // thread gets the cancel message: we just delete the data since the 189 // thread gets the cancel message: we just delete the data since the
183 // DownloadFile has been deleted. 190 // DownloadFile has been deleted.
184 void DownloadFileManager::UpdateDownload( 191 void DownloadFileManager::UpdateDownload(
185 DownloadId global_id, content::DownloadBuffer* buffer) { 192 DownloadId global_id, content::DownloadBuffer* buffer) {
186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 << " id = " << global_id 476 << " id = " << global_id
470 << " download_file = " << download_file->DebugString(); 477 << " download_file = " << download_file->DebugString();
471 478
472 downloads_.erase(global_id); 479 downloads_.erase(global_id);
473 480
474 delete download_file; 481 delete download_file;
475 482
476 if (downloads_.empty()) 483 if (downloads_.empty())
477 StopUpdateTimer(); 484 StopUpdateTimer();
478 } 485 }
OLDNEW
« no previous file with comments | « content/browser/download/download_file_manager.h ('k') | content/browser/download/download_file_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698