| OLD | NEW |
| 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_impl.h" | 5 #include "content/browser/download/download_file_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 } | 79 } |
| 80 | 80 |
| 81 return -1; | 81 return -1; |
| 82 } | 82 } |
| 83 | 83 |
| 84 } | 84 } |
| 85 | 85 |
| 86 DownloadFileImpl::DownloadFileImpl( | 86 DownloadFileImpl::DownloadFileImpl( |
| 87 const DownloadCreateInfo* info, | 87 const DownloadCreateInfo* info, |
| 88 DownloadRequestHandleInterface* request_handle, | 88 DownloadRequestHandleInterface* request_handle, |
| 89 content::DownloadManager* download_manager) | 89 content::DownloadManager* download_manager, |
| 90 bool calculate_hash) |
| 90 : file_(info->save_info.file_path, | 91 : file_(info->save_info.file_path, |
| 91 info->url(), | 92 info->url(), |
| 92 info->referrer_url, | 93 info->referrer_url, |
| 93 info->received_bytes, | 94 info->received_bytes, |
| 95 calculate_hash, |
| 96 info->save_info.hash_state, |
| 94 info->save_info.file_stream), | 97 info->save_info.file_stream), |
| 95 id_(info->download_id), | 98 id_(info->download_id), |
| 96 request_handle_(request_handle), | 99 request_handle_(request_handle), |
| 97 download_manager_(download_manager) { | 100 download_manager_(download_manager) { |
| 98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 99 } | 102 } |
| 100 | 103 |
| 101 DownloadFileImpl::~DownloadFileImpl() { | 104 DownloadFileImpl::~DownloadFileImpl() { |
| 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 103 } | 106 } |
| 104 | 107 |
| 105 // BaseFile delegated functions. | 108 // BaseFile delegated functions. |
| 106 net::Error DownloadFileImpl::Initialize(bool calculate_hash) { | 109 net::Error DownloadFileImpl::Initialize() { |
| 107 return file_.Initialize(calculate_hash); | 110 return file_.Initialize(); |
| 108 } | 111 } |
| 109 | 112 |
| 110 net::Error DownloadFileImpl::AppendDataToFile(const char* data, | 113 net::Error DownloadFileImpl::AppendDataToFile(const char* data, |
| 111 size_t data_len) { | 114 size_t data_len) { |
| 112 return file_.AppendDataToFile(data, data_len); | 115 return file_.AppendDataToFile(data, data_len); |
| 113 } | 116 } |
| 114 | 117 |
| 115 net::Error DownloadFileImpl::Rename(const FilePath& full_path) { | 118 net::Error DownloadFileImpl::Rename(const FilePath& full_path) { |
| 116 return file_.Rename(full_path); | 119 return file_.Rename(full_path); |
| 117 } | 120 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 141 } | 144 } |
| 142 | 145 |
| 143 int64 DownloadFileImpl::BytesSoFar() const { | 146 int64 DownloadFileImpl::BytesSoFar() const { |
| 144 return file_.bytes_so_far(); | 147 return file_.bytes_so_far(); |
| 145 } | 148 } |
| 146 | 149 |
| 147 int64 DownloadFileImpl::CurrentSpeed() const { | 150 int64 DownloadFileImpl::CurrentSpeed() const { |
| 148 return file_.CurrentSpeed(); | 151 return file_.CurrentSpeed(); |
| 149 } | 152 } |
| 150 | 153 |
| 151 bool DownloadFileImpl::GetSha256Hash(std::string* hash) { | 154 bool DownloadFileImpl::GetHash(std::string* hash) { |
| 152 return file_.GetSha256Hash(hash); | 155 return file_.GetHash(hash); |
| 156 } |
| 157 |
| 158 std::string DownloadFileImpl::GetHashState() { |
| 159 return file_.GetHashState(); |
| 153 } | 160 } |
| 154 | 161 |
| 155 // DownloadFileInterface implementation. | 162 // DownloadFileInterface implementation. |
| 156 void DownloadFileImpl::CancelDownloadRequest() { | 163 void DownloadFileImpl::CancelDownloadRequest() { |
| 157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 158 request_handle_->CancelRequest(); | 165 request_handle_->CancelRequest(); |
| 159 } | 166 } |
| 160 | 167 |
| 161 int DownloadFileImpl::Id() const { | 168 int DownloadFileImpl::Id() const { |
| 162 return id_.local(); | 169 return id_.local(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 174 std::string DownloadFileImpl::DebugString() const { | 181 std::string DownloadFileImpl::DebugString() const { |
| 175 return base::StringPrintf("{" | 182 return base::StringPrintf("{" |
| 176 " id_ = " "%d" | 183 " id_ = " "%d" |
| 177 " request_handle = %s" | 184 " request_handle = %s" |
| 178 " Base File = %s" | 185 " Base File = %s" |
| 179 " }", | 186 " }", |
| 180 id_.local(), | 187 id_.local(), |
| 181 request_handle_->DebugString().c_str(), | 188 request_handle_->DebugString().c_str(), |
| 182 file_.DebugString().c_str()); | 189 file_.DebugString().c_str()); |
| 183 } | 190 } |
| OLD | NEW |