blob: 73a130818721455065042d6ff819298a8137e1f4 [file] [log] [blame]
Dominique Fauteux-Chapleauc2d0a172020-04-01 20:04:131// 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-Chapleau8cf113f12020-04-08 18:14:0312namespace base {
13template <typename T>
14struct DefaultSingletonTraits;
15}
16
Dominique Fauteux-Chapleauc2d0a172020-04-01 20:04:1317namespace enterprise_connectors {
18
19// Enums representing each connector to be used as arguments so the manager can
20// read the appropriate policies/settings.
21enum class AnalysisConnector {
22 FILE_DOWNLOADED,
23 FILE_ATTACHED,
24 BULK_DATA_ENTRY,
25};
26
27enum 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.
33enum 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.
41class 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-Chapleau8cf113f12020-04-08 18:14:0374 static ConnectorsManager* GetInstance();
Dominique Fauteux-Chapleauc2d0a172020-04-01 20:04:1375
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-Chapleauccf53092020-04-08 17:15:2882 // 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-Chapleauc2d0a172020-04-01 20:04:1391 private:
Dominique Fauteux-Chapleau8cf113f12020-04-08 18:14:0392 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-Chapleauccf53092020-04-08 17:15:2899 // Private legacy functions.
Dominique Fauteux-Chapleauc2d0a172020-04-01 20:04:13100 // 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-Chapleauc2d0a172020-04-01 20:04:13113 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_