Chromium Code Reviews| 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 #include "net/log/net_log.h" | 26 #include "net/log/net_log.h" |
| 26 #include "net/log/net_log_event_type.h" | 27 #include "net/log/net_log_event_type.h" |
| 27 | 28 |
| 28 namespace content { | 29 namespace content { |
| 29 | 30 |
| 30 BaseFile::BaseFile(const net::BoundNetLog& bound_net_log) | 31 BaseFile::BaseFile(const net::BoundNetLog& bound_net_log) |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 | 187 |
| 187 Detach(); | 188 Detach(); |
| 188 } | 189 } |
| 189 | 190 |
| 190 std::unique_ptr<crypto::SecureHash> BaseFile::Finish() { | 191 std::unique_ptr<crypto::SecureHash> BaseFile::Finish() { |
| 191 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 192 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 192 Close(); | 193 Close(); |
| 193 return std::move(secure_hash_); | 194 return std::move(secure_hash_); |
| 194 } | 195 } |
| 195 | 196 |
| 196 // OS_WIN, OS_MACOSX and OS_LINUX have specialized implementations. | |
| 197 #if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(OS_LINUX) | |
| 198 DownloadInterruptReason BaseFile::AnnotateWithSourceInformation( | |
| 199 const std::string& client_guid, | |
| 200 const GURL& source_url, | |
| 201 const GURL& referrer_url) { | |
| 202 return DOWNLOAD_INTERRUPT_REASON_NONE; | |
| 203 } | |
| 204 #endif | |
| 205 | |
| 206 std::string BaseFile::DebugString() const { | 197 std::string BaseFile::DebugString() const { |
| 207 return base::StringPrintf( | 198 return base::StringPrintf( |
| 208 "{ " | 199 "{ " |
| 209 " full_path_ = \"%" PRFilePath | 200 " full_path_ = \"%" PRFilePath |
| 210 "\"" | 201 "\"" |
| 211 " bytes_so_far_ = %" PRId64 " detached_ = %c }", | 202 " bytes_so_far_ = %" PRId64 " detached_ = %c }", |
| 212 full_path_.value().c_str(), | 203 full_path_.value().c_str(), |
| 213 bytes_so_far_, | 204 bytes_so_far_, |
| 214 detached_ ? 'T' : 'F'); | 205 detached_ ? 'T' : 'F'); |
| 215 } | 206 } |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 DownloadInterruptReason reason) { | 368 DownloadInterruptReason reason) { |
| 378 DVLOG(1) << __func__ << "() operation:" << operation | 369 DVLOG(1) << __func__ << "() operation:" << operation |
| 379 << " os_error:" << os_error | 370 << " os_error:" << os_error |
| 380 << " reason:" << DownloadInterruptReasonToString(reason); | 371 << " reason:" << DownloadInterruptReasonToString(reason); |
| 381 bound_net_log_.AddEvent( | 372 bound_net_log_.AddEvent( |
| 382 net::NetLogEventType::DOWNLOAD_FILE_ERROR, | 373 net::NetLogEventType::DOWNLOAD_FILE_ERROR, |
| 383 base::Bind(&FileInterruptedNetLogCallback, operation, os_error, reason)); | 374 base::Bind(&FileInterruptedNetLogCallback, operation, os_error, reason)); |
| 384 return reason; | 375 return reason; |
| 385 } | 376 } |
| 386 | 377 |
| 378 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) | |
| 379 DownloadInterruptReason BaseFile::AnnotateWithSourceInformation( | |
| 380 const std::string& client_guid, | |
| 381 const GURL& source_url, | |
| 382 const GURL& referrer_url) { | |
| 383 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | |
| 384 DCHECK(!detached_); | |
| 385 DCHECK(!full_path_.empty()); | |
| 386 | |
| 387 bound_net_log_.BeginEvent(net::NetLogEventType::DOWNLOAD_FILE_ANNOTATED); | |
| 388 QuarantineFileResult result = | |
| 389 QuarantineFile(full_path_, source_url, referrer_url, client_guid); | |
| 390 bound_net_log_.EndEvent(net::NetLogEventType::DOWNLOAD_FILE_ANNOTATED); | |
| 391 switch (result) { | |
| 392 case QuarantineFileResult::OK: | |
| 393 return DOWNLOAD_INTERRUPT_REASON_NONE; | |
| 394 case QuarantineFileResult::VIRUS_INFECTED: | |
| 395 return DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED; | |
| 396 case QuarantineFileResult::SECURITY_CHECK_FAILED: | |
| 397 return DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED; | |
| 398 case QuarantineFileResult::BLOCKED_BY_POLICY: | |
| 399 return DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED; | |
| 400 case QuarantineFileResult::ACCESS_DENIED: | |
| 401 return DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED; | |
| 402 | |
| 403 case QuarantineFileResult::FILE_MISSING: | |
| 404 // Don't have a good interrupt reason here. This return code means that | |
| 405 // the file at |full_path_| went missing before QuarantineFile got to look | |
| 406 // at it. Not expected to happen, but we've seen instances where a file | |
| 407 // goes missing immediately after BaseFile closes the handle. | |
| 408 // | |
|
cpu_(ooo_6.6-7.5)
2016/09/20 15:52:33
On windows the attachment service can delete the f
asanka
2016/09/21 14:57:00
Got it. This status specifically addresses the cas
| |
| 409 // Intentonally using a different error message than SECURITY_CHECK_FAILED | |
| 410 // in order to distinguish the two. | |
| 411 return DOWNLOAD_INTERRUPT_REASON_FILE_FAILED; | |
| 412 | |
| 413 case QuarantineFileResult::ANNOTATION_FAILED: | |
| 414 // This means that the mark-of-the-web couldn't be applied. The file is | |
| 415 // already on the file system under its final target name. | |
| 416 // | |
| 417 // Causes of failed annotations typically aren't transient. E.g. the | |
| 418 // target file system may not support extended attributes or alternate | |
| 419 // streams. We are going to allow these downloads to progress on the | |
| 420 // assumption that failures to apply MOTW can't reliably be introduced | |
| 421 // remotely. | |
| 422 return DOWNLOAD_INTERRUPT_REASON_NONE; | |
| 423 } | |
| 424 return DOWNLOAD_INTERRUPT_REASON_FILE_FAILED; | |
| 425 } | |
| 426 #else // !OS_WIN && !OS_MACOSX && !OS_LINUX | |
| 427 DownloadInterruptReason BaseFile::AnnotateWithSourceInformation( | |
| 428 const std::string& client_guid, | |
| 429 const GURL& source_url, | |
| 430 const GURL& referrer_url) { | |
| 431 return DOWNLOAD_INTERRUPT_REASON_NONE; | |
| 432 } | |
| 433 #endif | |
| 434 | |
| 387 } // namespace content | 435 } // namespace content |
| OLD | NEW |