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