OLD | NEW |
---|---|
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_impl.h" | 5 #include "content/browser/download/download_file_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 53 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
54 power_save_blocker_(power_save_blocker.Pass()) { | 54 power_save_blocker_(power_save_blocker.Pass()) { |
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
56 DCHECK(download_manager.get()); | 56 DCHECK(download_manager.get()); |
57 } | 57 } |
58 | 58 |
59 DownloadFileImpl::~DownloadFileImpl() { | 59 DownloadFileImpl::~DownloadFileImpl() { |
60 } | 60 } |
61 | 61 |
62 content::DownloadInterruptReason DownloadFileImpl::Initialize() { | 62 content::DownloadInterruptReason DownloadFileImpl::Initialize() { |
63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
64 | |
63 update_timer_.reset(new base::RepeatingTimer<DownloadFileImpl>()); | 65 update_timer_.reset(new base::RepeatingTimer<DownloadFileImpl>()); |
64 net::Error result = file_.Initialize(default_download_directory_); | 66 net::Error net_result = file_.Initialize(default_download_directory_); |
65 if (result != net::OK) { | 67 if (net_result != net::OK) { |
66 return content::ConvertNetErrorToInterruptReason( | 68 return content::ConvertNetErrorToInterruptReason( |
67 result, content::DOWNLOAD_INTERRUPT_FROM_DISK); | 69 net_result, content::DOWNLOAD_INTERRUPT_FROM_DISK); |
68 } | 70 } |
69 | 71 |
70 stream_reader_->RegisterCallback( | 72 stream_reader_->RegisterCallback( |
71 base::Bind(&DownloadFileImpl::StreamActive, weak_factory_.GetWeakPtr())); | 73 base::Bind(&DownloadFileImpl::StreamActive, weak_factory_.GetWeakPtr())); |
72 | 74 |
73 download_start_ = base::TimeTicks::Now(); | 75 download_start_ = base::TimeTicks::Now(); |
76 | |
74 // Initial pull from the straw. | 77 // Initial pull from the straw. |
75 StreamActive(); | 78 StreamActive(); |
76 | 79 |
77 return content::DOWNLOAD_INTERRUPT_REASON_NONE; | 80 return content::DOWNLOAD_INTERRUPT_REASON_NONE; |
78 } | 81 } |
79 | 82 |
80 content::DownloadInterruptReason DownloadFileImpl::AppendDataToFile( | 83 content::DownloadInterruptReason DownloadFileImpl::AppendDataToFile( |
81 const char* data, size_t data_len) { | 84 const char* data, size_t data_len) { |
82 if (!update_timer_->IsRunning()) { | 85 if (!update_timer_->IsRunning()) { |
83 update_timer_->Start(FROM_HERE, | 86 update_timer_->Start(FROM_HERE, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 rename_error, | 122 rename_error, |
120 content::DOWNLOAD_INTERRUPT_FROM_DISK); | 123 content::DOWNLOAD_INTERRUPT_FROM_DISK); |
121 new_path.clear(); | 124 new_path.clear(); |
122 } | 125 } |
123 | 126 |
124 BrowserThread::PostTask( | 127 BrowserThread::PostTask( |
125 BrowserThread::UI, FROM_HERE, | 128 BrowserThread::UI, FROM_HERE, |
126 base::Bind(callback, reason, new_path)); | 129 base::Bind(callback, reason, new_path)); |
127 } | 130 } |
128 | 131 |
129 void DownloadFileImpl::Detach() { | 132 void DownloadFileImpl::Detach(base::Closure callback) { |
133 // Doing the annotation here leaves a small window during | |
134 // which the file has the final name but hasn't been marked with the | |
135 // Mark Of The Web. However, it allows anti-virus scanners on Windows | |
136 // to actually see the data (http://crbug.com/127999), and the Window | |
137 // is pretty small (round trip to the UI thread). | |
138 AnnotateWithSourceInformation(); | |
139 | |
130 file_.Detach(); | 140 file_.Detach(); |
141 | |
142 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); | |
benjhayden
2012/09/19 15:44:35
Seems like there should be a less magical way to d
Randy Smith (Not in Mondays)
2012/09/19 20:46:39
Because I wanted to be able to write a test to del
| |
131 } | 143 } |
132 | 144 |
133 void DownloadFileImpl::Cancel() { | 145 void DownloadFileImpl::Cancel() { |
134 file_.Cancel(); | 146 file_.Cancel(); |
135 } | 147 } |
136 | 148 |
137 void DownloadFileImpl::AnnotateWithSourceInformation() { | 149 void DownloadFileImpl::AnnotateWithSourceInformation() { |
138 bound_net_log_.BeginEvent(net::NetLog::TYPE_DOWNLOAD_FILE_ANNOTATED); | 150 bound_net_log_.BeginEvent(net::NetLog::TYPE_DOWNLOAD_FILE_ANNOTATED); |
139 file_.AnnotateWithSourceInformation(); | 151 file_.AnnotateWithSourceInformation(); |
140 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_FILE_ANNOTATED); | 152 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_FILE_ANNOTATED); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 } | 307 } |
296 } | 308 } |
297 | 309 |
298 void DownloadFileImpl::SendUpdate() { | 310 void DownloadFileImpl::SendUpdate() { |
299 BrowserThread::PostTask( | 311 BrowserThread::PostTask( |
300 BrowserThread::UI, FROM_HERE, | 312 BrowserThread::UI, FROM_HERE, |
301 base::Bind(&DownloadManager::UpdateDownload, | 313 base::Bind(&DownloadManager::UpdateDownload, |
302 download_manager_, id_.local(), | 314 download_manager_, id_.local(), |
303 BytesSoFar(), CurrentSpeed(), GetHashState())); | 315 BytesSoFar(), CurrentSpeed(), GetHashState())); |
304 } | 316 } |
OLD | NEW |