1 // Copyright 2014 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 COMPONENTS_POLICY_CORE_BROWSER_BROWSER_POLICY_CONNECTOR_H_ 6 #define COMPONENTS_POLICY_CORE_BROWSER_BROWSER_POLICY_CONNECTOR_H_ 7 8 #include <stdint.h> 9 10 #include <memory> 11 #include <string> 12 13 #include "base/macros.h" 14 #include "base/memory/ref_counted.h" 15 #include "components/policy/core/browser/browser_policy_connector_base.h" 16 #include "components/policy/policy_export.h" 17 18 class PrefRegistrySimple; 19 class PrefService; 20 21 namespace network { 22 class SharedURLLoaderFactory; 23 } 24 25 namespace policy { 26 27 class DeviceManagementService; 28 class PolicyStatisticsCollector; 29 30 // The BrowserPolicyConnector keeps some shared components of the policy system. 31 // This is a basic implementation that gets extended by platform-specific 32 // subclasses. 33 class POLICY_EXPORT BrowserPolicyConnector : public BrowserPolicyConnectorBase { 34 public: 35 ~BrowserPolicyConnector() override; 36 37 // Finalizes the initialization of the connector. This call can be skipped on 38 // tests that don't require the full policy system running. 39 virtual void Init( 40 PrefService* local_state, 41 scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) = 0; 42 43 // Checks whether this device is under any kind of enterprise management. 44 virtual bool IsEnterpriseManaged() const = 0; 45 46 // Checks whether there are any machine-level policies configured. 47 virtual bool HasMachineLevelPolicies() = 0; 48 49 // Cleans up the connector before it can be safely deleted. 50 void Shutdown() override; 51 52 // Schedules initialization of the cloud policy backend services, if the 53 // services are already constructed. 54 void ScheduleServiceInitialization(int64_t delay_milliseconds); 55 device_management_service()56 DeviceManagementService* device_management_service() { 57 return device_management_service_.get(); 58 } 59 60 // Returns the URL for the device management service endpoint. 61 std::string GetDeviceManagementUrl() const; 62 63 // Returns the URL for the realtime reporting service endpoint. 64 std::string GetRealtimeReportingUrl() const; 65 66 // Returns the URL for the encrypted reporting service endpoint. 67 std::string GetEncryptedReportingUrl() const; 68 69 // Check whether a user is known to be non-enterprise. Domains such as 70 // gmail.com and googlemail.com are known to not be managed. Also returns 71 // false if the username is empty. 72 static bool IsNonEnterpriseUser(const std::string& username); 73 74 // Allows to register domain for tests that is recognized as non-enterprise. 75 // Note that |domain| basically needs to live until this method is invoked 76 // with a nullptr. 77 static void SetNonEnterpriseDomainForTesting(const char* domain); 78 79 // Registers refresh rate prefs. 80 static void RegisterPrefs(PrefRegistrySimple* registry); 81 82 // Returns true if the command line switch of policy can be used. 83 virtual bool IsCommandLineSwitchSupported() const = 0; 84 85 protected: 86 // Builds an uninitialized BrowserPolicyConnector. 87 // Init() should be called to create and start the policy components. 88 explicit BrowserPolicyConnector( 89 const HandlerListFactory& handler_list_factory); 90 91 // Helper for the public Init() that must be called by subclasses. 92 void InitInternal( 93 PrefService* local_state, 94 std::unique_ptr<DeviceManagementService> device_management_service); 95 96 // Returns true if the given |provider| has any registered policies. 97 bool ProviderHasPolicies(const ConfigurationPolicyProvider* provider) const; 98 99 private: 100 std::unique_ptr<PolicyStatisticsCollector> policy_statistics_collector_; 101 102 std::unique_ptr<DeviceManagementService> device_management_service_; 103 104 DISALLOW_COPY_AND_ASSIGN(BrowserPolicyConnector); 105 }; 106 107 } // namespace policy 108 109 #endif // COMPONENTS_POLICY_CORE_BROWSER_BROWSER_POLICY_CONNECTOR_H_ 110