Dominique Fauteux-Chapleau | c2d0a17 | 2020-04-01 20:04:13 | [diff] [blame^] | 1 | // Copyright 2020 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_BROWSER_ENTERPRISE_CONNECTORS_CONNECTORS_MANAGER_H_ |
| 6 | #define CHROME_BROWSER_ENTERPRISE_CONNECTORS_CONNECTORS_MANAGER_H_ |
| 7 | |
| 8 | #include "base/callback_forward.h" |
| 9 | #include "base/optional.h" |
| 10 | #include "url/gurl.h" |
| 11 | |
| 12 | namespace enterprise_connectors { |
| 13 | |
| 14 | // Enums representing each connector to be used as arguments so the manager can |
| 15 | // read the appropriate policies/settings. |
| 16 | enum class AnalysisConnector { |
| 17 | FILE_DOWNLOADED, |
| 18 | FILE_ATTACHED, |
| 19 | BULK_DATA_ENTRY, |
| 20 | }; |
| 21 | |
| 22 | enum class ReportingConnector { |
| 23 | SECURITY_EVENT, |
| 24 | }; |
| 25 | |
| 26 | // Enum representing if an analysis should block further interactions with the |
| 27 | // browser until its verdict is obtained. |
| 28 | enum class BlockUntilVerdict { |
| 29 | NO_BLOCK = 0, |
| 30 | BLOCK = 1, |
| 31 | }; |
| 32 | |
| 33 | // Manages access to Connector policies. This class is responsible for caching |
| 34 | // the Connector policies, validate them against approved service providers and |
| 35 | // provide a simple interface to them. |
| 36 | class ConnectorsManager { |
| 37 | public: |
| 38 | // Structs representing settings to be used for an analysis or a report. These |
| 39 | // settings should only be kept and considered valid for the specific |
| 40 | // analysis/report they were obtained for. |
| 41 | struct AnalysisSettings { |
| 42 | AnalysisSettings(); |
| 43 | AnalysisSettings(AnalysisSettings&&); |
| 44 | AnalysisSettings& operator=(AnalysisSettings&&); |
| 45 | ~AnalysisSettings(); |
| 46 | |
| 47 | GURL analysis_url; |
| 48 | std::set<std::string> tags; |
| 49 | BlockUntilVerdict block_until_verdict; |
| 50 | bool block_password_protected_files; |
| 51 | bool block_large_files; |
| 52 | bool block_unsupported_file_types; |
| 53 | }; |
| 54 | |
| 55 | struct ReportingSettings { |
| 56 | ReportingSettings(); |
| 57 | ReportingSettings(ReportingSettings&&); |
| 58 | ReportingSettings& operator=(ReportingSettings&&); |
| 59 | ~ReportingSettings(); |
| 60 | |
| 61 | std::vector<GURL> reporting_urls; |
| 62 | }; |
| 63 | |
| 64 | // Callback used to retrieve AnalysisSettings objects from the manager |
| 65 | // asynchronously. base::nullopt means no analysis should take place. |
| 66 | using AnalysisSettingsCallback = |
| 67 | base::OnceCallback<void(base::Optional<AnalysisSettings>)>; |
| 68 | |
| 69 | ConnectorsManager(); |
| 70 | ~ConnectorsManager(); |
| 71 | |
| 72 | // Validates which settings should be applied to an analysis connector event |
| 73 | // against cached policies. |
| 74 | void GetAnalysisSettings(const GURL& url, |
| 75 | AnalysisConnector connector, |
| 76 | AnalysisSettingsCallback callback); |
| 77 | |
| 78 | private: |
| 79 | // Legacy functions. |
| 80 | // These functions are used to interact with legacy policies and should stay |
| 81 | // private. They should be removed once legacy policies are deprecated. |
| 82 | |
| 83 | // Returns analysis settings based on legacy policies. |
| 84 | base::Optional<AnalysisSettings> GetAnalysisSettingsFromLegacyPolicies( |
| 85 | const GURL& url, |
| 86 | AnalysisConnector connector) const; |
| 87 | |
| 88 | BlockUntilVerdict LegacyBlockUntilVerdict(bool upload) const; |
| 89 | bool LegacyBlockPasswordProtectedFiles(bool upload) const; |
| 90 | bool LegacyBlockLargeFiles(bool upload) const; |
| 91 | bool LegacyBlockUnsupportedFileTypes(bool upload) const; |
| 92 | |
| 93 | bool MatchURLAgainstLegacyDlpPolicies(const GURL& url, bool upload) const; |
| 94 | bool MatchURLAgainstLegacyMalwarePolicies(const GURL& url, bool upload) const; |
| 95 | std::set<std::string> MatchURLAgainstLegacyPolicies(const GURL& url, |
| 96 | bool upload) const; |
| 97 | }; |
| 98 | |
| 99 | } // namespace enterprise_connectors |
| 100 | |
| 101 | #endif // CHROME_BROWSER_ENTERPRISE_CONNECTORS_CONNECTORS_MANAGER_H_ |