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

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

Issue 10696043: Shifted DownloadFile to exporting DownloadInterruptReasons. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync'd to TOT. Created 8 years, 5 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_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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 bound_net_log_(bound_net_log), 51 bound_net_log_(bound_net_log),
52 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 52 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
53 power_save_blocker_(power_save_blocker.Pass()) { 53 power_save_blocker_(power_save_blocker.Pass()) {
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
55 DCHECK(download_manager.get()); 55 DCHECK(download_manager.get());
56 } 56 }
57 57
58 DownloadFileImpl::~DownloadFileImpl() { 58 DownloadFileImpl::~DownloadFileImpl() {
59 } 59 }
60 60
61 // BaseFile delegated functions. 61 content::DownloadInterruptReason DownloadFileImpl::Initialize() {
62 net::Error DownloadFileImpl::Initialize() {
63 update_timer_.reset(new base::RepeatingTimer<DownloadFileImpl>()); 62 update_timer_.reset(new base::RepeatingTimer<DownloadFileImpl>());
64 net::Error result = file_.Initialize(); 63 net::Error result = file_.Initialize();
65 if (result != net::OK) 64 if (result != net::OK) {
66 return result; 65 return content::ConvertNetErrorToInterruptReason(
66 result, content::DOWNLOAD_INTERRUPT_FROM_DISK);
67 }
67 68
68 stream_reader_->RegisterCallback( 69 stream_reader_->RegisterCallback(
69 base::Bind(&DownloadFileImpl::StreamActive, weak_factory_.GetWeakPtr())); 70 base::Bind(&DownloadFileImpl::StreamActive, weak_factory_.GetWeakPtr()));
70 71
71 download_start_ = base::TimeTicks::Now(); 72 download_start_ = base::TimeTicks::Now();
72 // Initial pull from the straw. 73 // Initial pull from the straw.
73 StreamActive(); 74 StreamActive();
74 75
75 return result; 76 return content::DOWNLOAD_INTERRUPT_REASON_NONE;
76 } 77 }
77 78
78 net::Error DownloadFileImpl::AppendDataToFile(const char* data, 79 content::DownloadInterruptReason DownloadFileImpl::AppendDataToFile(
79 size_t data_len) { 80 const char* data, size_t data_len) {
80 if (!update_timer_->IsRunning()) { 81 if (!update_timer_->IsRunning()) {
81 update_timer_->Start(FROM_HERE, 82 update_timer_->Start(FROM_HERE,
82 base::TimeDelta::FromMilliseconds(kUpdatePeriodMs), 83 base::TimeDelta::FromMilliseconds(kUpdatePeriodMs),
83 this, &DownloadFileImpl::SendUpdate); 84 this, &DownloadFileImpl::SendUpdate);
84 } 85 }
85 return file_.AppendDataToFile(data, data_len); 86 return content::ConvertNetErrorToInterruptReason(
87 file_.AppendDataToFile(data, data_len),
88 content::DOWNLOAD_INTERRUPT_FROM_DISK);
86 } 89 }
87 90
88 net::Error DownloadFileImpl::Rename(const FilePath& full_path) { 91 content::DownloadInterruptReason DownloadFileImpl::Rename(
89 return file_.Rename(full_path); 92 const FilePath& full_path) {
93 return content::ConvertNetErrorToInterruptReason(
94 file_.Rename(full_path),
95 content::DOWNLOAD_INTERRUPT_FROM_DISK);
90 } 96 }
91 97
92 void DownloadFileImpl::Detach() { 98 void DownloadFileImpl::Detach() {
93 file_.Detach(); 99 file_.Detach();
94 } 100 }
95 101
96 void DownloadFileImpl::Cancel() { 102 void DownloadFileImpl::Cancel() {
97 file_.Cancel(); 103 file_.Cancel();
98 } 104 }
99 105
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 content::ByteStreamReader::STREAM_EMPTY); 174 content::ByteStreamReader::STREAM_EMPTY);
169 content::DownloadInterruptReason reason = 175 content::DownloadInterruptReason reason =
170 content::DOWNLOAD_INTERRUPT_REASON_NONE; 176 content::DOWNLOAD_INTERRUPT_REASON_NONE;
171 base::TimeDelta delta( 177 base::TimeDelta delta(
172 base::TimeDelta::FromMilliseconds(kMaxTimeBlockingFileThreadMs)); 178 base::TimeDelta::FromMilliseconds(kMaxTimeBlockingFileThreadMs));
173 179
174 // Take care of any file local activity required. 180 // Take care of any file local activity required.
175 do { 181 do {
176 state = stream_reader_->Read(&incoming_data, &incoming_data_size); 182 state = stream_reader_->Read(&incoming_data, &incoming_data_size);
177 183
178 net::Error result = net::OK;
179 switch (state) { 184 switch (state) {
180 case content::ByteStreamReader::STREAM_EMPTY: 185 case content::ByteStreamReader::STREAM_EMPTY:
181 break; 186 break;
182 case content::ByteStreamReader::STREAM_HAS_DATA: 187 case content::ByteStreamReader::STREAM_HAS_DATA:
183 { 188 {
184 ++num_buffers; 189 ++num_buffers;
185 base::TimeTicks write_start(base::TimeTicks::Now()); 190 base::TimeTicks write_start(base::TimeTicks::Now());
186 result = AppendDataToFile( 191 reason = AppendDataToFile(
187 incoming_data.get()->data(), incoming_data_size); 192 incoming_data.get()->data(), incoming_data_size);
188 disk_writes_time_ += (base::TimeTicks::Now() - write_start); 193 disk_writes_time_ += (base::TimeTicks::Now() - write_start);
189 bytes_seen_ += incoming_data_size; 194 bytes_seen_ += incoming_data_size;
190 total_incoming_data_size += incoming_data_size; 195 total_incoming_data_size += incoming_data_size;
191 reason = content::ConvertNetErrorToInterruptReason(
192 result, content::DOWNLOAD_INTERRUPT_FROM_DISK);
193 } 196 }
194 break; 197 break;
195 case content::ByteStreamReader::STREAM_COMPLETE: 198 case content::ByteStreamReader::STREAM_COMPLETE:
196 { 199 {
197 reason = stream_reader_->GetStatus(); 200 reason = stream_reader_->GetStatus();
198 SendUpdate(); 201 SendUpdate();
199 base::TimeTicks close_start(base::TimeTicks::Now()); 202 base::TimeTicks close_start(base::TimeTicks::Now());
200 file_.Finish(); 203 file_.Finish();
201 base::TimeTicks now(base::TimeTicks::Now()); 204 base::TimeTicks now(base::TimeTicks::Now());
202 disk_writes_time_ += (now - close_start); 205 disk_writes_time_ += (now - close_start);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 } 264 }
262 } 265 }
263 266
264 void DownloadFileImpl::SendUpdate() { 267 void DownloadFileImpl::SendUpdate() {
265 BrowserThread::PostTask( 268 BrowserThread::PostTask(
266 BrowserThread::UI, FROM_HERE, 269 BrowserThread::UI, FROM_HERE,
267 base::Bind(&DownloadManager::UpdateDownload, 270 base::Bind(&DownloadManager::UpdateDownload,
268 download_manager_, id_.local(), 271 download_manager_, id_.local(),
269 BytesSoFar(), CurrentSpeed(), GetHashState())); 272 BytesSoFar(), CurrentSpeed(), GetHashState()));
270 } 273 }
OLDNEW
« no previous file with comments | « content/browser/download/download_file_impl.h ('k') | content/browser/download/download_file_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698