| 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/base_file.h" | 5 #include "content/browser/download/base_file.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/pickle.h" | 14 #include "base/pickle.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 18 #include "content/browser/download/download_interrupt_reasons_impl.h" | 18 #include "content/browser/download/download_interrupt_reasons_impl.h" |
| 19 #include "content/browser/download/download_net_log_parameters.h" | 19 #include "content/browser/download/download_net_log_parameters.h" |
| 20 #include "content/browser/download/download_stats.h" | 20 #include "content/browser/download/download_stats.h" |
| 21 #include "content/browser/download/quarantine.h" |
| 21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/content_browser_client.h" | 23 #include "content/public/browser/content_browser_client.h" |
| 23 #include "crypto/secure_hash.h" | 24 #include "crypto/secure_hash.h" |
| 24 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
| 25 | 26 |
| 26 namespace content { | 27 namespace content { |
| 27 | 28 |
| 28 BaseFile::BaseFile(const net::BoundNetLog& bound_net_log) | 29 BaseFile::BaseFile(const net::BoundNetLog& bound_net_log) |
| 29 : bound_net_log_(bound_net_log) {} | 30 : bound_net_log_(bound_net_log) {} |
| 30 | 31 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 179 |
| 179 Detach(); | 180 Detach(); |
| 180 } | 181 } |
| 181 | 182 |
| 182 std::unique_ptr<crypto::SecureHash> BaseFile::Finish() { | 183 std::unique_ptr<crypto::SecureHash> BaseFile::Finish() { |
| 183 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 184 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 184 Close(); | 185 Close(); |
| 185 return std::move(secure_hash_); | 186 return std::move(secure_hash_); |
| 186 } | 187 } |
| 187 | 188 |
| 188 // OS_WIN, OS_MACOSX and OS_LINUX have specialized implementations. | |
| 189 #if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(OS_LINUX) | |
| 190 DownloadInterruptReason BaseFile::AnnotateWithSourceInformation( | |
| 191 const std::string& client_guid, | |
| 192 const GURL& source_url, | |
| 193 const GURL& referrer_url) { | |
| 194 return DOWNLOAD_INTERRUPT_REASON_NONE; | |
| 195 } | |
| 196 #endif | |
| 197 | |
| 198 std::string BaseFile::DebugString() const { | 189 std::string BaseFile::DebugString() const { |
| 199 return base::StringPrintf( | 190 return base::StringPrintf( |
| 200 "{ " | 191 "{ " |
| 201 " full_path_ = \"%" PRFilePath | 192 " full_path_ = \"%" PRFilePath |
| 202 "\"" | 193 "\"" |
| 203 " bytes_so_far_ = %" PRId64 " detached_ = %c }", | 194 " bytes_so_far_ = %" PRId64 " detached_ = %c }", |
| 204 full_path_.value().c_str(), | 195 full_path_.value().c_str(), |
| 205 bytes_so_far_, | 196 bytes_so_far_, |
| 206 detached_ ? 'T' : 'F'); | 197 detached_ ? 'T' : 'F'); |
| 207 } | 198 } |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 DownloadInterruptReason reason) { | 362 DownloadInterruptReason reason) { |
| 372 DVLOG(1) << __FUNCTION__ << "() operation:" << operation | 363 DVLOG(1) << __FUNCTION__ << "() operation:" << operation |
| 373 << " os_error:" << os_error | 364 << " os_error:" << os_error |
| 374 << " reason:" << DownloadInterruptReasonToString(reason); | 365 << " reason:" << DownloadInterruptReasonToString(reason); |
| 375 bound_net_log_.AddEvent( | 366 bound_net_log_.AddEvent( |
| 376 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, | 367 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, |
| 377 base::Bind(&FileInterruptedNetLogCallback, operation, os_error, reason)); | 368 base::Bind(&FileInterruptedNetLogCallback, operation, os_error, reason)); |
| 378 return reason; | 369 return reason; |
| 379 } | 370 } |
| 380 | 371 |
| 372 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) |
| 373 DownloadInterruptReason BaseFile::AnnotateWithSourceInformation( |
| 374 const std::string& client_guid, |
| 375 const GURL& source_url, |
| 376 const GURL& referrer_url) { |
| 377 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 378 DCHECK(!detached_); |
| 379 DCHECK(!full_path_.empty()); |
| 380 |
| 381 bound_net_log_.BeginEvent(net::NetLog::TYPE_DOWNLOAD_FILE_ANNOTATED); |
| 382 QuarantineFileResult result = |
| 383 QuarantineFile(full_path_, source_url, referrer_url, client_guid); |
| 384 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_FILE_ANNOTATED); |
| 385 switch (result) { |
| 386 case QuarantineFileResult::OK: |
| 387 return DOWNLOAD_INTERRUPT_REASON_NONE; |
| 388 case QuarantineFileResult::VIRUS_INFECTED: |
| 389 return DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED; |
| 390 case QuarantineFileResult::SECURITY_CHECK_FAILED: |
| 391 return DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED; |
| 392 case QuarantineFileResult::BLOCKED_BY_POLICY: |
| 393 return DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED; |
| 394 case QuarantineFileResult::ACCESS_DENIED: |
| 395 return DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED; |
| 396 |
| 397 case QuarantineFileResult::FILE_MISSING: |
| 398 // Don't have a good interrupt reason here. This return code means that |
| 399 // the file at |full_path_| went missing before QuarantineFile got to look |
| 400 // at it. Not expected to happen, but we've seen instances where a file |
| 401 // goes missing immediately after BaseFile closes the handle. |
| 402 // |
| 403 // Intentonally using a different error message than SECURITY_CHECK_FAILED |
| 404 // in order to distinguish the two. |
| 405 return DOWNLOAD_INTERRUPT_REASON_FILE_FAILED; |
| 406 |
| 407 case QuarantineFileResult::ANNOTATION_FAILED: |
| 408 // This means that the mark-of-the-web couldn't be applied. The file is |
| 409 // already on the file system under its final target name. |
| 410 // |
| 411 // Causes of failed annotations typically aren't transient. E.g. the |
| 412 // target file system may not support extended attributes or alternate |
| 413 // streams. We are going to allow these downloads to progress on the |
| 414 // assumption that failures to apply MOTW can't reliably be introduced |
| 415 // remotely. |
| 416 return DOWNLOAD_INTERRUPT_REASON_NONE; |
| 417 } |
| 418 return DOWNLOAD_INTERRUPT_REASON_FILE_FAILED; |
| 419 } |
| 420 #else // !OS_WIN && !OS_MACOSX && !OS_LINUX |
| 421 DownloadInterruptReason BaseFile::AnnotateWithSourceInformation( |
| 422 const std::string& client_guid, |
| 423 const GURL& source_url, |
| 424 const GURL& referrer_url) { |
| 425 return DOWNLOAD_INTERRUPT_REASON_NONE; |
| 426 } |
| 427 #endif |
| 428 |
| 381 } // namespace content | 429 } // namespace content |
| OLD | NEW |