| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/safe_browsing/incident_reporting/last_download_finder.h
" | 5 #include "chrome/browser/safe_browsing/incident_reporting/last_download_finder.h
" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <functional> | 11 #include <functional> |
| 12 #include <utility> | 12 #include <utility> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
| 22 #include "chrome/browser/history/history_service_factory.h" | 22 #include "chrome/browser/history/history_service_factory.h" |
| 23 #include "chrome/browser/profiles/profile_manager.h" | 23 #include "chrome/browser/profiles/profile_manager.h" |
| 24 #include "chrome/browser/safe_browsing/incident_reporting/incident_reporting_ser
vice.h" | 24 #include "chrome/browser/safe_browsing/incident_reporting/incident_reporting_ser
vice.h" |
| 25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 26 #include "chrome/common/safe_browsing/csd.pb.h" | 26 #include "chrome/common/safe_browsing/csd.pb.h" |
| 27 #include "chrome/common/safe_browsing/download_protection_util.h" | 27 #include "chrome/common/safe_browsing/download_protection_util.h" |
| 28 #include "chrome/common/safe_browsing/file_type_policies.h" |
| 28 #include "components/history/core/browser/download_constants.h" | 29 #include "components/history/core/browser/download_constants.h" |
| 29 #include "components/history/core/browser/history_service.h" | 30 #include "components/history/core/browser/history_service.h" |
| 30 #include "components/prefs/pref_service.h" | 31 #include "components/prefs/pref_service.h" |
| 31 #include "content/public/browser/notification_details.h" | 32 #include "content/public/browser/notification_details.h" |
| 32 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
| 33 #include "content/public/browser/notification_source.h" | 34 #include "content/public/browser/notification_source.h" |
| 34 #include "crypto/sha2.h" | 35 #include "crypto/sha2.h" |
| 35 | 36 |
| 36 namespace safe_browsing { | 37 namespace safe_browsing { |
| 37 | 38 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // The default return value of download_protection_util::GetDownloadType is | 85 // The default return value of download_protection_util::GetDownloadType is |
| 85 // ClientDownloadRequest::WIN_EXECUTABLE. | 86 // ClientDownloadRequest::WIN_EXECUTABLE. |
| 86 return download_type == ClientDownloadRequest::WIN_EXECUTABLE; | 87 return download_type == ClientDownloadRequest::WIN_EXECUTABLE; |
| 87 } | 88 } |
| 88 | 89 |
| 89 // Returns true if a download represented by a DownloadRow is a binary file for | 90 // Returns true if a download represented by a DownloadRow is a binary file for |
| 90 // the current OS. | 91 // the current OS. |
| 91 bool IsBinaryDownload(const history::DownloadRow& row) { | 92 bool IsBinaryDownload(const history::DownloadRow& row) { |
| 92 // TODO(grt): Peek into archives to see if they contain binaries; | 93 // TODO(grt): Peek into archives to see if they contain binaries; |
| 93 // http://crbug.com/386915. | 94 // http://crbug.com/386915. |
| 94 return (download_protection_util::IsSupportedBinaryFile(row.target_path) && | 95 FileTypePolicies* policies = FileTypePolicies::GetInstance(); |
| 95 !download_protection_util::IsArchiveFile(row.target_path) && | 96 return (policies->IsCheckedBinaryFile(row.target_path) && |
| 97 !policies->IsArchiveFile(row.target_path) && |
| 96 IsBinaryDownloadForCurrentOS( | 98 IsBinaryDownloadForCurrentOS( |
| 97 download_protection_util::GetDownloadType(row.target_path))); | 99 download_protection_util::GetDownloadType(row.target_path))); |
| 98 } | 100 } |
| 99 | 101 |
| 100 // Returns true if a download represented by a DownloadRow is not a binary file. | 102 // Returns true if a download represented by a DownloadRow is not a binary file. |
| 101 bool IsNonBinaryDownload(const history::DownloadRow& row) { | 103 bool IsNonBinaryDownload(const history::DownloadRow& row) { |
| 102 return !download_protection_util::IsSupportedBinaryFile(row.target_path); | 104 return !FileTypePolicies::GetInstance()->IsCheckedBinaryFile( |
| 105 row.target_path); |
| 103 } | 106 } |
| 104 | 107 |
| 105 // Returns true if a download represented by a DownloadDetails is binary file | 108 // Returns true if a download represented by a DownloadDetails is binary file |
| 106 // for the current OS. | 109 // for the current OS. |
| 107 bool IsBinaryDownload(const ClientIncidentReport_DownloadDetails& details) { | 110 bool IsBinaryDownload(const ClientIncidentReport_DownloadDetails& details) { |
| 108 // DownloadDetails are only generated for binary downloads. | 111 // DownloadDetails are only generated for binary downloads. |
| 109 return IsBinaryDownloadForCurrentOS(details.download().download_type()); | 112 return IsBinaryDownloadForCurrentOS(details.download().download_type()); |
| 110 } | 113 } |
| 111 | 114 |
| 112 // Returns true if a download represented by a DownloadRow has been opened. | 115 // Returns true if a download represented by a DownloadRow has been opened. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 if (download.opened) | 209 if (download.opened) |
| 207 details->set_open_time_msec(download.end_time.ToJavaTime()); | 210 details->set_open_time_msec(download.end_time.ToJavaTime()); |
| 208 } | 211 } |
| 209 | 212 |
| 210 // Populates the |details| protobuf with information pertaining to the | 213 // Populates the |details| protobuf with information pertaining to the |
| 211 // (non-binary) |download|. | 214 // (non-binary) |download|. |
| 212 void PopulateNonBinaryDetailsFromRow( | 215 void PopulateNonBinaryDetailsFromRow( |
| 213 const history::DownloadRow& download, | 216 const history::DownloadRow& download, |
| 214 ClientIncidentReport_NonBinaryDownloadDetails* details) { | 217 ClientIncidentReport_NonBinaryDownloadDetails* details) { |
| 215 details->set_file_type( | 218 details->set_file_type( |
| 216 base::FilePath( | 219 base::FilePath(FileTypePolicies::GetFileExtension(download.target_path)) |
| 217 download_protection_util::GetFileExtension(download.target_path)) | |
| 218 .AsUTF8Unsafe()); | 220 .AsUTF8Unsafe()); |
| 219 details->set_length(download.received_bytes); | 221 details->set_length(download.received_bytes); |
| 220 if (download.url_chain.back().has_host()) | 222 if (download.url_chain.back().has_host()) |
| 221 details->set_host(download.url_chain.back().host()); | 223 details->set_host(download.url_chain.back().host()); |
| 222 details->set_url_spec_sha256( | 224 details->set_url_spec_sha256( |
| 223 crypto::SHA256HashString(download.url_chain.back().spec())); | 225 crypto::SHA256HashString(download.url_chain.back().spec())); |
| 224 } | 226 } |
| 225 | 227 |
| 226 } // namespace | 228 } // namespace |
| 227 | 229 |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 } | 441 } |
| 440 } | 442 } |
| 441 } | 443 } |
| 442 | 444 |
| 443 void LastDownloadFinder::HistoryServiceBeingDeleted( | 445 void LastDownloadFinder::HistoryServiceBeingDeleted( |
| 444 history::HistoryService* history_service) { | 446 history::HistoryService* history_service) { |
| 445 history_service_observer_.Remove(history_service); | 447 history_service_observer_.Remove(history_service); |
| 446 } | 448 } |
| 447 | 449 |
| 448 } // namespace safe_browsing | 450 } // namespace safe_browsing |
| OLD | NEW |