blob: 7d73b2255d543ee9218fe406f1ee02bddcf3a406 [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
Keishi Hattori0e45c022021-11-27 09:25:528#include "base/memory/raw_ptr.h"
Dominique Fauteux-Chapleaud280fd52021-02-03 20:06:009#include "chrome/browser/enterprise/connectors/analysis/analysis_service_settings.h"
Dominique Fauteux-Chapleau5ae64242020-04-17 13:18:2610#include "chrome/browser/enterprise/connectors/common.h"
Roger Tawa542c883df2021-02-03 16:12:5211#include "chrome/browser/enterprise/connectors/file_system/service_settings.h"
Dominique Fauteux-Chapleaud280fd52021-02-03 20:06:0012#include "chrome/browser/enterprise/connectors/reporting/reporting_service_settings.h"
Dominique Fauteux-Chapleau76b366a2020-05-28 17:15:0613#include "chrome/browser/enterprise/connectors/service_provider_config.h"
Dominique Fauteux-Chapleau29775702020-04-30 15:50:3614#include "components/prefs/pref_change_registrar.h"
Dominique Fauteux-Chapleau130242bf2020-12-07 19:07:4815#include "components/prefs/pref_service.h"
Anton Bikineev46bbb972021-05-15 17:53:5316#include "third_party/abseil-cpp/absl/types/optional.h"
Dominique Fauteux-Chapleauc2d0a172020-04-01 20:04:1317#include "url/gurl.h"
18
Dominique Fauteux-Chapleauc2d0a172020-04-01 20:04:1319namespace enterprise_connectors {
20
Dominique Fauteux-Chapleau130242bf2020-12-07 19:07:4821// Manages access to Connector policies for a given profile. This class is
22// responsible for caching the Connector policies, validate them against
23// approved service providers and provide a simple interface to them.
Dominique Fauteux-Chapleauc2d0a172020-04-01 20:04:1324class ConnectorsManager {
25 public:
Roger Tawa445a9972020-05-20 22:44:0226 // Maps used to cache connectors settings.
Dominique Fauteux-Chapleaucb08fe42020-04-23 19:57:4527 using AnalysisConnectorsSettings =
28 std::map<AnalysisConnector, std::vector<AnalysisServiceSettings>>;
Roger Tawa445a9972020-05-20 22:44:0229 using ReportingConnectorsSettings =
30 std::map<ReportingConnector, std::vector<ReportingServiceSettings>>;
Roger Tawa542c883df2021-02-03 16:12:5231 using FileSystemConnectorsSettings =
32 std::map<FileSystemConnector, std::vector<FileSystemServiceSettings>>;
Dominique Fauteux-Chapleaucb08fe42020-04-23 19:57:4533
Dominique Fauteux-Chapleau130242bf2020-12-07 19:07:4834 ConnectorsManager(PrefService* pref_service,
35 ServiceProviderConfig* config,
36 bool observe_prefs = true);
37 ~ConnectorsManager();
Dominique Fauteux-Chapleauc2d0a172020-04-01 20:04:1338
Roger Tawa445a9972020-05-20 22:44:0239 // Validates which settings should be applied to a reporting event
Dominique Fauteux-Chapleauc088fba2020-10-26 20:34:0840 // against cached policies. Cache the policy value the first time this is
41 // called for every different connector.
Anton Bikineev46bbb972021-05-15 17:53:5342 absl::optional<ReportingSettings> GetReportingSettings(
Roger Tawa445a9972020-05-20 22:44:0243 ReportingConnector connector);
44
Dominique Fauteux-Chapleauc2d0a172020-04-01 20:04:1345 // Validates which settings should be applied to an analysis connector event
Dominique Fauteux-Chapleaucb08fe42020-04-23 19:57:4546 // against cached policies. This function will prioritize new connector
47 // policies over legacy ones if they are set.
Anton Bikineev46bbb972021-05-15 17:53:5348 absl::optional<AnalysisSettings> GetAnalysisSettings(
Dominique Fauteux-Chapleauc08c8c962020-05-07 18:46:2649 const GURL& url,
50 AnalysisConnector connector);
51
Roger Tawa542c883df2021-02-03 16:12:5252 // Validates which settings should be applied to a file system connector
Alice Gong57552692021-07-15 20:06:0453 // against cached policies.
54 absl::optional<FileSystemSettings> GetFileSystemGlobalSettings(
55 FileSystemConnector connector);
56 // In addition to method above; also validates specifically for an URL.
Anton Bikineev46bbb972021-05-15 17:53:5357 absl::optional<FileSystemSettings> GetFileSystemSettings(
Roger Tawa542c883df2021-02-03 16:12:5258 const GURL& url,
59 FileSystemConnector connector);
60
Dominique Fauteux-Chapleauc08c8c962020-05-07 18:46:2661 // Checks if the corresponding connector is enabled.
Dominique Fauteux-Chapleauadf0b112020-05-25 13:24:0362 bool IsConnectorEnabled(AnalysisConnector connector) const;
63 bool IsConnectorEnabled(ReportingConnector connector) const;
Roger Tawa542c883df2021-02-03 16:12:5264 bool IsConnectorEnabled(FileSystemConnector connector) const;
Dominique Fauteux-Chapleauc2d0a172020-04-01 20:04:1365
Dominique Fauteux-Chapleauadf0b112020-05-25 13:24:0366 bool DelayUntilVerdict(AnalysisConnector connector);
Anthony Vallee-Dubois86baa7fc42021-06-29 15:38:5567 absl::optional<std::u16string> GetCustomMessage(AnalysisConnector connector,
68 const std::string& tag);
69 absl::optional<GURL> GetLearnMoreUrl(AnalysisConnector connector,
70 const std::string& tag);
Dominique Fauteux-Chapleauccf53092020-04-08 17:15:2871
Anthony Vallee-Dubois53913ec2021-02-22 16:46:4472 std::vector<std::string> GetAnalysisServiceProviderNames(
73 AnalysisConnector connector);
Anthony Vallee-Dubois9a6a0402021-02-24 14:46:1674 std::vector<std::string> GetReportingServiceProviderNames(
75 ReportingConnector connector);
Anthony Vallee-Dubois53913ec2021-02-22 16:46:4476
Dominique Fauteux-Chapleaucb08fe42020-04-23 19:57:4577 // Public testing functions.
78 const AnalysisConnectorsSettings& GetAnalysisConnectorsSettingsForTesting()
79 const;
Roger Tawa445a9972020-05-20 22:44:0280 const ReportingConnectorsSettings& GetReportingConnectorsSettingsForTesting()
81 const;
Roger Tawa542c883df2021-02-03 16:12:5282 const FileSystemConnectorsSettings&
83 GetFileSystemConnectorsSettingsForTesting() const;
Dominique Fauteux-Chapleaucb08fe42020-04-23 19:57:4584
Dominique Fauteux-Chapleauc2d0a172020-04-01 20:04:1385 private:
Dominique Fauteux-Chapleaucb08fe42020-04-23 19:57:4586 // Validates which settings should be applied to an analysis connector event
87 // against connector policies. Cache the policy value the first time this is
88 // called for every different connector.
Anton Bikineev46bbb972021-05-15 17:53:5389 absl::optional<AnalysisSettings> GetAnalysisSettingsFromConnectorPolicy(
Dominique Fauteux-Chapleaucb08fe42020-04-23 19:57:4590 const GURL& url,
Dominique Fauteux-Chapleauc08c8c962020-05-07 18:46:2691 AnalysisConnector connector);
Dominique Fauteux-Chapleaucb08fe42020-04-23 19:57:4592
93 // Read and cache the policy corresponding to |connector|.
Roger Tawa445a9972020-05-20 22:44:0294 void CacheAnalysisConnectorPolicy(AnalysisConnector connector);
95 void CacheReportingConnectorPolicy(ReportingConnector connector);
Roger Tawa542c883df2021-02-03 16:12:5296 void CacheFileSystemConnectorPolicy(FileSystemConnector connector);
Dominique Fauteux-Chapleaucb08fe42020-04-23 19:57:4597
Dominique Fauteux-Chapleau130242bf2020-12-07 19:07:4898 // Sets up |pref_change_registrar_|. Used by the constructor and
99 // SetUpForTesting.
100 void StartObservingPrefs(PrefService* pref_service);
Dominique Fauteux-Chapleau045c37d2020-05-05 12:51:40101 void StartObservingPref(AnalysisConnector connector);
Roger Tawa445a9972020-05-20 22:44:02102 void StartObservingPref(ReportingConnector connector);
Roger Tawa542c883df2021-02-03 16:12:52103 void StartObservingPref(FileSystemConnector connector);
Dominique Fauteux-Chapleau29775702020-04-30 15:50:36104
Dominique Fauteux-Chapleau12381552020-09-21 18:45:55105 // Validates which settings should be applied to an analysis connector event
106 // against connector policies. Cache the policy value the first time this is
107 // called for every different connector.
Anton Bikineev46bbb972021-05-15 17:53:53108 absl::optional<ReportingSettings> GetReportingSettingsFromConnectorPolicy(
Dominique Fauteux-Chapleau12381552020-09-21 18:45:55109 ReportingConnector connector);
110
Alice Gong57552692021-07-15 20:06:04111 // Returns service settings (if there are multiple service providers, only the
112 // first one for now) for |connector|. Cache the policy value the first time
113 // this is called for every different connector.
114 FileSystemServiceSettings* GetFileSystemServiceSettings(
115 FileSystemConnector connector);
116
Dominique Fauteux-Chapleau76b366a2020-05-28 17:15:06117 // Cached values of available service providers. This information validates
118 // the Connector policies have a valid provider.
Keishi Hattori0e45c022021-11-27 09:25:52119 raw_ptr<ServiceProviderConfig> service_provider_config_;
Dominique Fauteux-Chapleau76b366a2020-05-28 17:15:06120
Dominique Fauteux-Chapleaucb08fe42020-04-23 19:57:45121 // Cached values of the connector policies. Updated when a connector is first
122 // used or when a policy is updated.
Roger Tawa445a9972020-05-20 22:44:02123 AnalysisConnectorsSettings analysis_connector_settings_;
124 ReportingConnectorsSettings reporting_connector_settings_;
Roger Tawa542c883df2021-02-03 16:12:52125 FileSystemConnectorsSettings file_system_connector_settings_;
Dominique Fauteux-Chapleau29775702020-04-30 15:50:36126
127 // Used to track changes of connector policies and propagate them in
128 // |connector_settings_|.
129 PrefChangeRegistrar pref_change_registrar_;
Dominique Fauteux-Chapleauc2d0a172020-04-01 20:04:13130};
131
132} // namespace enterprise_connectors
133
134#endif // CHROME_BROWSER_ENTERPRISE_CONNECTORS_CONNECTORS_MANAGER_H_