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

Unified Diff: content/browser/download/base_file.cc

Issue 2123023002: [Downloads] Consolidate MOTW annotation APIs into a single API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move-safe-util-to-downloads
Patch Set: [win] Verify that the Zone.Identifier stream has the correct contents. Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/download/base_file.cc
diff --git a/content/browser/download/base_file.cc b/content/browser/download/base_file.cc
index f1fbd87219863472d4dc95897c843ae5db0cdbe2..87b25e724717d00fe54a311b903d4a9594e81947 100644
--- a/content/browser/download/base_file.cc
+++ b/content/browser/download/base_file.cc
@@ -18,6 +18,7 @@
#include "content/browser/download/download_interrupt_reasons_impl.h"
#include "content/browser/download/download_net_log_parameters.h"
#include "content/browser/download/download_stats.h"
+#include "content/browser/download/quarantine.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
#include "crypto/secure_hash.h"
@@ -193,16 +194,6 @@ std::unique_ptr<crypto::SecureHash> BaseFile::Finish() {
return std::move(secure_hash_);
}
-// OS_WIN, OS_MACOSX and OS_LINUX have specialized implementations.
-#if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(OS_LINUX)
-DownloadInterruptReason BaseFile::AnnotateWithSourceInformation(
- const std::string& client_guid,
- const GURL& source_url,
- const GURL& referrer_url) {
- return DOWNLOAD_INTERRUPT_REASON_NONE;
-}
-#endif
-
std::string BaseFile::DebugString() const {
return base::StringPrintf(
"{ "
@@ -384,4 +375,61 @@ DownloadInterruptReason BaseFile::LogInterruptReason(
return reason;
}
+#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
+DownloadInterruptReason BaseFile::AnnotateWithSourceInformation(
+ const std::string& client_guid,
+ const GURL& source_url,
+ const GURL& referrer_url) {
+ DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ DCHECK(!detached_);
+ DCHECK(!full_path_.empty());
+
+ bound_net_log_.BeginEvent(net::NetLogEventType::DOWNLOAD_FILE_ANNOTATED);
+ QuarantineFileResult result =
+ QuarantineFile(full_path_, source_url, referrer_url, client_guid);
+ bound_net_log_.EndEvent(net::NetLogEventType::DOWNLOAD_FILE_ANNOTATED);
+ switch (result) {
+ case QuarantineFileResult::OK:
+ return DOWNLOAD_INTERRUPT_REASON_NONE;
+ case QuarantineFileResult::VIRUS_INFECTED:
+ return DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED;
+ case QuarantineFileResult::SECURITY_CHECK_FAILED:
+ return DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED;
+ case QuarantineFileResult::BLOCKED_BY_POLICY:
+ return DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED;
+ case QuarantineFileResult::ACCESS_DENIED:
+ return DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED;
+
+ case QuarantineFileResult::FILE_MISSING:
+ // Don't have a good interrupt reason here. This return code means that
+ // the file at |full_path_| went missing before QuarantineFile got to look
+ // at it. Not expected to happen, but we've seen instances where a file
+ // goes missing immediately after BaseFile closes the handle.
+ //
+ // Intentionally using a different error message than
+ // SECURITY_CHECK_FAILED in order to distinguish the two.
+ return DOWNLOAD_INTERRUPT_REASON_FILE_FAILED;
+
+ case QuarantineFileResult::ANNOTATION_FAILED:
+ // This means that the mark-of-the-web couldn't be applied. The file is
+ // already on the file system under its final target name.
+ //
+ // Causes of failed annotations typically aren't transient. E.g. the
+ // target file system may not support extended attributes or alternate
+ // streams. We are going to allow these downloads to progress on the
+ // assumption that failures to apply MOTW can't reliably be introduced
+ // remotely.
+ return DOWNLOAD_INTERRUPT_REASON_NONE;
+ }
+ return DOWNLOAD_INTERRUPT_REASON_FILE_FAILED;
+}
+#else // !OS_WIN && !OS_MACOSX && !OS_LINUX
+DownloadInterruptReason BaseFile::AnnotateWithSourceInformation(
+ const std::string& client_guid,
+ const GURL& source_url,
+ const GURL& referrer_url) {
+ return DOWNLOAD_INTERRUPT_REASON_NONE;
+}
+#endif
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698