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

Side by Side Diff: chrome/common/safe_browsing/file_type_policies.h

Issue 1909653002: FileTypePolicies class to load types from proto. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changes per jialiul, and set upstream CL Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « chrome/chrome_tests_unit.gypi ('k') | chrome/common/safe_browsing/file_type_policies.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_COMMON_SAFE_BROWSING_FILE_TYPE_POLICIES_H_
6 #define CHROME_COMMON_SAFE_BROWSING_FILE_TYPE_POLICIES_H_
7
8 #include <map>
9 #include <memory>
10
11 #include "base/files/file_path.h"
12 #include "base/gtest_prod_util.h"
13 #include "chrome/common/safe_browsing/download_file_types.pb.h"
14
15 namespace safe_browsing {
16
17 // This holds a list of file types (aka file extensions) that we know about,
18 // with policies related to how Safe Browsing and the download UI should treat
19 // them.
20 //
21 // The data to populate it is read from a ResourceBundle and then also
22 // fetched periodically from Google to get the most up-to-date policies.
23 //
24 // It should be setup and accessed on IO thread.
25
26 // TODO(nparker): Replace the following methods' contents with calls to
27 // g_browser_process->safe_browsing_service()->file_type_policies()->***.
28 //
29 // bool IsSupportedBinaryFile(const base::FilePath& file);
30 // bool IsArchiveFile(const base::FilePath& file);
31 // ClientDownloadRequest::DownloadType GetDownloadType(
32 // const base::FilePath& file);
33 // int GetSBClientDownloadTypeValueForUMA(const base::FilePath& file);
34 // bool IsAllowedToOpenAutomatically(const base::FilePath& path);
35 // DownloadDangerLevel GetFileDangerLevel(const base::FilePath& path);
36
37 class FileTypePolicies {
38 public:
39 // Creator must call one of Populate* before calling other methods.
40 FileTypePolicies();
41 virtual ~FileTypePolicies();
42
43 // Read data from the main ResourceBundle. This updates the internal list
44 // only if the data passes integrity checks. This is normally called once
45 // after construction.
46 void PopulateFromResourceBundle();
47
48 // Update the internal list from a binary proto fetched from the network.
49 // Same integrity checks apply. This can be called multiple times with new
50 // protos.
51 void PopulateFromDynamicUpdate(const std::string& binary_pb);
52
53 // Accessors
54 const DownloadFileType& PolicyForFile(const base::FilePath& file);
55 const DownloadFileType::PlatformSettings& SettingsForFile(
56 const base::FilePath& file);
57 int64_t UmaValueForFile(const base::FilePath& file);
58 bool IsFileAnArchive(const base::FilePath& file);
59 float SampledPingProbability() const;
60
61 protected:
62 // Used in metrics, do not reorder.
63 enum class UpdateResult {
64 SUCCESS = 1,
65 FAILED_EMPTY = 2,
66 FAILED_PROTO_PARSE = 3,
67 FAILED_DELTA_CHECK = 4,
68 FAILED_VERSION_CHECK = 5,
69 FAILED_DEFAULT_SETTING_SET = 6,
70 FAILED_WRONG_SETTINGS_COUNT = 7,
71 };
72
73 // Read data from an serialized protobuf and update the internal list
74 // only if it passes integrity checks.
75 virtual UpdateResult PopulateFromBinaryPb(const std::string& binary_pb);
76
77 // Fetch the blob from the main resource bundle.
78 virtual void ReadResourceBundle(std::string* binary_pb);
79
80 // Record the result of an update attempt.
81 virtual void RecordUpdateMetrics(UpdateResult result,
82 const std::string& src_name);
83
84 // Return the ASCII lowercase extension w/o leading dot, or empty.
85 static std::string CanonicalizedExtension(const base::FilePath& file);
86
87 private:
88 // The latest config we've committed. Starts out null.
89 std::unique_ptr<DownloadFileTypeConfig> config_;
90
91 // This references entries in config_.
92 std::map<std::string, const DownloadFileType*> file_type_by_ext_;
93
94 // Type used if we can't load from disk.
95 DownloadFileType last_resort_default_;
96
97 FRIEND_TEST_ALL_PREFIXES(FileTypePoliciesTest, UnpackResourceBundle);
98 FRIEND_TEST_ALL_PREFIXES(FileTypePoliciesTest, BadProto);
99 FRIEND_TEST_ALL_PREFIXES(FileTypePoliciesTest, BadUpdateFromExisting);
100 };
101
102 } // namespace safe_browsing
103
104 #endif // CHROME_COMMON_SAFE_BROWSING_FILE_TYPE_POLICIES_H_
OLDNEW
« no previous file with comments | « chrome/chrome_tests_unit.gypi ('k') | chrome/common/safe_browsing/file_type_policies.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698