diff options
author | gbillock@chromium.org <gbillock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-10 13:49:48 +0000 |
---|---|---|
committer | gbillock@chromium.org <gbillock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-10 13:49:48 +0000 |
commit | 492c00974a1354e97e27939279eecd7fc9d8d9ce (patch) | |
tree | 899e3da8b00bb60209a012a0587564b50477c017 /content/browser/download | |
parent | 6cf51b6c67396f11d6e4c2cccb75e8ed3a020e37 (diff) | |
download | chromium_src-492c00974a1354e97e27939279eecd7fc9d8d9ce.zip chromium_src-492c00974a1354e97e27939279eecd7fc9d8d9ce.tar.gz chromium_src-492c00974a1354e97e27939279eecd7fc9d8d9ce.tar.bz2 |
[Downloads] Move client guid for AV scanning of downloaded files to chrome/
This client app should not be used by all clients of content/. Moving to chrome so it can be managed there and re-used if needed.
Review URL: https://chromiumcodereview.appspot.com/21355004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@216843 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/download')
-rw-r--r-- | content/browser/download/base_file.cc | 4 | ||||
-rw-r--r-- | content/browser/download/base_file.h | 9 | ||||
-rw-r--r-- | content/browser/download/base_file_win.cc | 14 | ||||
-rw-r--r-- | content/browser/download/download_file.h | 5 | ||||
-rw-r--r-- | content/browser/download/download_file_impl.cc | 4 | ||||
-rw-r--r-- | content/browser/download/download_file_impl.h | 1 | ||||
-rw-r--r-- | content/browser/download/download_file_unittest.cc | 2 | ||||
-rw-r--r-- | content/browser/download/download_manager_impl.cc | 7 | ||||
-rw-r--r-- | content/browser/download/download_manager_impl_unittest.cc | 11 | ||||
-rw-r--r-- | content/browser/download/mock_download_file.h | 1 | ||||
-rw-r--r-- | content/browser/download/save_file.cc | 2 |
11 files changed, 57 insertions, 3 deletions
diff --git a/content/browser/download/base_file.cc b/content/browser/download/base_file.cc index 466be32..90ab485 100644 --- a/content/browser/download/base_file.cc +++ b/content/browser/download/base_file.cc @@ -211,6 +211,10 @@ void BaseFile::Finish() { Close(); } +void BaseFile::SetClientGuid(const std::string& guid) { + client_guid_ = guid; +} + // OS_WIN, OS_MACOSX and OS_LINUX have specialized implementations. #if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(OS_LINUX) DownloadInterruptReason BaseFile::AnnotateWithSourceInformation() { diff --git a/content/browser/download/base_file.h b/content/browser/download/base_file.h index 9c1261c..f1686c8 100644 --- a/content/browser/download/base_file.h +++ b/content/browser/download/base_file.h @@ -69,8 +69,15 @@ class CONTENT_EXPORT BaseFile { // Indicate that the download has finished. No new data will be received. void Finish(); + // Set the client guid which will be used to identify the app to the + // system AV scanning function. Should be called before + // AnnotateWithSourceInformation() to take effect. + void SetClientGuid(const std::string& guid); + // Informs the OS that this file came from the internet. Returns a // DownloadInterruptReason indicating the result of the operation. + // Note: SetClientGuid() should be called before this function on + // Windows to ensure the correct app client ID is available. DownloadInterruptReason AnnotateWithSourceInformation(); base::FilePath full_path() const { return full_path_; } @@ -142,6 +149,8 @@ class CONTENT_EXPORT BaseFile { // The URL where the download was initiated. GURL referrer_url_; + std::string client_guid_; + // OS file stream for writing scoped_ptr<net::FileStream> file_stream_; diff --git a/content/browser/download/base_file_win.cc b/content/browser/download/base_file_win.cc index 398e5fc..252f0495 100644 --- a/content/browser/download/base_file_win.cc +++ b/content/browser/download/base_file_win.cc @@ -5,9 +5,12 @@ #include "content/browser/download/base_file.h" #include <windows.h> +#include <cguid.h> +#include <objbase.h> #include <shellapi.h> #include "base/file_util.h" +#include "base/guid.h" #include "base/metrics/histogram.h" #include "base/strings/utf_string_conversions.h" #include "base/threading/thread_restrictions.h" @@ -326,7 +329,16 @@ DownloadInterruptReason BaseFile::AnnotateWithSourceInformation() { bound_net_log_.BeginEvent(net::NetLog::TYPE_DOWNLOAD_FILE_ANNOTATED); DownloadInterruptReason result = DOWNLOAD_INTERRUPT_REASON_NONE; - HRESULT hr = ScanAndSaveDownloadedFile(full_path_, source_url_); + std::string braces_guid = "{" + client_guid_ + "}"; + GUID guid = GUID_NULL; + if (base::IsValidGUID(client_guid_)) { + HRESULT hr = CLSIDFromString( + base::UTF8ToUTF16(braces_guid).c_str(), &guid); + if (FAILED(hr)) + guid = GUID_NULL; + } + + HRESULT hr = AVScanFile(full_path_, source_url_.spec(), guid); // If the download file is missing after the call, then treat this as an // interrupted download. diff --git a/content/browser/download/download_file.h b/content/browser/download/download_file.h index a8e18ff..568e7ee 100644 --- a/content/browser/download/download_file.h +++ b/content/browser/download/download_file.h @@ -73,6 +73,11 @@ class CONTENT_EXPORT DownloadFile { // Returns the current (intermediate) state of the hash as a byte string. virtual std::string GetHashState() = 0; + // Set the application GUID to be used to identify the app to the + // system AV function when scanning downloaded files. Should be called + // before RenameAndAnnotate() to take effect. + virtual void SetClientGuid(const std::string& guid) = 0; + // For testing. Must be called on FILE thread. // TODO(rdsmith): Replace use of EnsureNoPendingDownloads() // on the DownloadManager with a test-specific DownloadFileFactory diff --git a/content/browser/download/download_file_impl.cc b/content/browser/download/download_file_impl.cc index bbe317b..67bee81 100644 --- a/content/browser/download/download_file_impl.cc +++ b/content/browser/download/download_file_impl.cc @@ -200,6 +200,10 @@ std::string DownloadFileImpl::GetHashState() { return file_.GetHashState(); } +void DownloadFileImpl::SetClientGuid(const std::string& guid) { + file_.SetClientGuid(guid); +} + void DownloadFileImpl::StreamActive() { base::TimeTicks start(base::TimeTicks::Now()); base::TimeTicks now; diff --git a/content/browser/download/download_file_impl.h b/content/browser/download/download_file_impl.h index 963ae9f..9a50870 100644 --- a/content/browser/download/download_file_impl.h +++ b/content/browser/download/download_file_impl.h @@ -63,6 +63,7 @@ class CONTENT_EXPORT DownloadFileImpl : virtual public DownloadFile { virtual int64 CurrentSpeed() const OVERRIDE; virtual bool GetHash(std::string* hash) OVERRIDE; virtual std::string GetHashState() OVERRIDE; + virtual void SetClientGuid(const std::string& guid) OVERRIDE; protected: // For test class overrides. diff --git a/content/browser/download/download_file_unittest.cc b/content/browser/download/download_file_unittest.cc index ebf501d..867b76f 100644 --- a/content/browser/download/download_file_unittest.cc +++ b/content/browser/download/download_file_unittest.cc @@ -138,6 +138,8 @@ class DownloadFileTest : public testing::Test { net::BoundNetLog(), scoped_ptr<PowerSaveBlocker>().Pass(), observer_factory_.GetWeakPtr())); + download_file_->SetClientGuid( + "12345678-ABCD-1234-DCBA-123456789ABC"); EXPECT_CALL(*input_stream_, Read(_, _)) .WillOnce(Return(ByteStreamReader::STREAM_EMPTY)) diff --git a/content/browser/download/download_manager_impl.cc b/content/browser/download/download_manager_impl.cc index f9241832..ccfb4cc 100644 --- a/content/browser/download/download_manager_impl.cc +++ b/content/browser/download/download_manager_impl.cc @@ -422,6 +422,13 @@ void DownloadManagerImpl::StartDownloadWithId( delegate_->GenerateFileHash(), stream.Pass(), download->GetBoundNetLog(), download->DestinationObserverAsWeakPtr())); + + // Attach the client ID identifying the app to the AV system. + if (download_file.get() && delegate_) { + download_file->SetClientGuid( + delegate_->ApplicationClientIdForFileScanning()); + } + scoped_ptr<DownloadRequestHandleInterface> req_handle( new DownloadRequestHandle(info->request_handle)); download->Start(download_file.Pass(), req_handle.Pass()); diff --git a/content/browser/download/download_manager_impl_unittest.cc b/content/browser/download/download_manager_impl_unittest.cc index a8e18d4..eba2833 100644 --- a/content/browser/download/download_manager_impl_unittest.cc +++ b/content/browser/download/download_manager_impl_unittest.cc @@ -195,6 +195,7 @@ class MockDownloadManagerDelegate : public DownloadManagerDelegate { MOCK_METHOD5(ChooseSavePath, void( WebContents*, const base::FilePath&, const base::FilePath::StringType&, bool, const SavePackagePathPickedCallback&)); + MOCK_CONST_METHOD0(ApplicationClientIdForFileScanning, std::string()); }; MockDownloadManagerDelegate::MockDownloadManagerDelegate() {} @@ -363,7 +364,7 @@ class MockDownloadFileFactory virtual ~MockDownloadFileFactory() {} // Overridden method from DownloadFileFactory - MOCK_METHOD8(MockCreateFile, DownloadFile*( + MOCK_METHOD8(MockCreateFile, MockDownloadFile*( const DownloadSaveInfo&, const base::FilePath&, const GURL&, const GURL&, bool, @@ -593,9 +594,15 @@ TEST_F(DownloadManagerTest, StartDownload) { EXPECT_CALL(GetMockDownloadManagerDelegate(), GetSaveDir(_, _, _, _)); EXPECT_CALL(GetMockDownloadManagerDelegate(), GenerateFileHash()) .WillOnce(Return(true)); + EXPECT_CALL(GetMockDownloadManagerDelegate(), + ApplicationClientIdForFileScanning()) + .WillRepeatedly(Return("client-id")); + MockDownloadFile* mock_file = new MockDownloadFile; + EXPECT_CALL(*mock_file, SetClientGuid("client-id")); EXPECT_CALL(*mock_download_file_factory_.get(), MockCreateFile(Ref(*info->save_info.get()), _, _, _, true, - stream.get(), _, _)); + stream.get(), _, _)) + .WillOnce(Return(mock_file)); download_manager_->StartDownload( info.Pass(), stream.Pass(), DownloadUrlParameters::OnStartedCallback()); diff --git a/content/browser/download/mock_download_file.h b/content/browser/download/mock_download_file.h index 74dc75c..5d4b270 100644 --- a/content/browser/download/mock_download_file.h +++ b/content/browser/download/mock_download_file.h @@ -48,6 +48,7 @@ class MockDownloadFile : virtual public DownloadFile { MOCK_CONST_METHOD0(Id, int()); MOCK_METHOD0(GetDownloadManager, DownloadManager*()); MOCK_CONST_METHOD0(DebugString, std::string()); + MOCK_METHOD1(SetClientGuid, void(const std::string&)); }; } // namespace content diff --git a/content/browser/download/save_file.cc b/content/browser/download/save_file.cc index 80caf13..e8885e4 100644 --- a/content/browser/download/save_file.cc +++ b/content/browser/download/save_file.cc @@ -60,6 +60,8 @@ void SaveFile::Finish() { } void SaveFile::AnnotateWithSourceInformation() { + // TODO(gbillock): If this method is called, it should set the + // file_.SetClientGuid() method first. file_.AnnotateWithSourceInformation(); } |