1 // Copyright (c) 2013 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_POLICY_PROFILE_POLICY_CONNECTOR_H_ 6 #define CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/weak_ptr.h" 13 #include "components/browser_context_keyed_service/browser_context_keyed_service.h" 14 15 #if defined(OS_CHROMEOS) 16 #include "chromeos/dbus/dbus_method_call_status.h" 17 #endif 18 19 class Profile; 20 21 namespace base { 22 class SequencedTaskRunner; 23 } 24 25 namespace policy { 26 27 class ConfigurationPolicyProvider; 28 class ManagedModePolicyProvider; 29 class PolicyService; 30 31 // A BrowserContextKeyedService that creates and manages the per-Profile policy 32 // components. 33 class ProfilePolicyConnector : public BrowserContextKeyedService { 34 public: 35 explicit ProfilePolicyConnector(Profile* profile); 36 virtual ~ProfilePolicyConnector(); 37 38 // If |force_immediate_load| then disk caches will be loaded synchronously. 39 void Init(bool force_immediate_load, 40 base::SequencedTaskRunner* sequenced_task_runner); 41 42 void InitForTesting(scoped_ptr<PolicyService> service); 43 44 // BrowserContextKeyedService: 45 virtual void Shutdown() OVERRIDE; 46 47 // This is never NULL. 48 PolicyService* policy_service() const { return policy_service_.get(); } 49 50 #if defined(ENABLE_MANAGED_USERS) && defined(ENABLE_CONFIGURATION_POLICY) 51 ManagedModePolicyProvider* managed_mode_policy_provider() const { 52 return managed_mode_policy_provider_.get(); 53 } 54 #endif 55 56 // Returns true if |profile()| has used certificates installed via policy 57 // to establish a secure connection before. This means that it may have 58 // cached content from an untrusted source. 59 bool UsedPolicyCertificates(); 60 61 private: 62 #if defined(ENABLE_CONFIGURATION_POLICY) 63 64 #if defined(OS_CHROMEOS) 65 void InitializeDeviceLocalAccountPolicyProvider(const std::string& username); 66 67 // Callback for CryptohomeClient::GetSanitizedUsername() that initializes the 68 // NetworkConfigurationUpdater after receiving the hashed username. 69 void InitializeNetworkConfigurationUpdater( 70 bool is_managed, 71 chromeos::DBusMethodCallStatus status, 72 const std::string& hashed_username); 73 #endif 74 75 Profile* profile_; 76 77 #if defined(OS_CHROMEOS) 78 // Some of the user policy configuration affects browser global state, and 79 // can only come from one Profile. |is_primary_user_| is true if this 80 // connector belongs to the first signed-in Profile, and in that case that 81 // Profile's policy is the one that affects global policy settings in 82 // local state. 83 bool is_primary_user_; 84 85 scoped_ptr<ConfigurationPolicyProvider> special_user_policy_provider_; 86 #endif 87 88 #if defined(ENABLE_MANAGED_USERS) && defined(ENABLE_CONFIGURATION_POLICY) 89 scoped_ptr<ManagedModePolicyProvider> managed_mode_policy_provider_; 90 #endif 91 92 base::WeakPtrFactory<ProfilePolicyConnector> weak_ptr_factory_; 93 #endif // ENABLE_CONFIGURATION_POLICY 94 95 scoped_ptr<PolicyService> policy_service_; 96 97 DISALLOW_COPY_AND_ASSIGN(ProfilePolicyConnector); 98 }; 99 100 } // namespace policy 101 102 #endif // CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_H_ 103