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.
5 #ifndef CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_
6 #define CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "components/keyed_service/content/browser_context_keyed_base_factory.h"
16 struct DefaultSingletonTraits;
21 class SequencedTaskRunner;
30 class ConfigurationPolicyProvider;
31 class ProfilePolicyConnector;
33 // Creates ProfilePolicyConnectors for Profiles, which manage the common
34 // policy providers and other policy components.
35 // TODO(joaodasilva): convert this class to a proper PKS once the PrefService,
36 // which depends on this class, becomes a PKS too.
37 class ProfilePolicyConnectorFactory : public BrowserContextKeyedBaseFactory {
39 // Returns the ProfilePolicyConnectorFactory singleton.
40 static ProfilePolicyConnectorFactory* GetInstance();
42 // Returns the ProfilePolicyConnector associated with |profile|. This is only
43 // valid before |profile| is shut down.
44 static ProfilePolicyConnector* GetForProfile(Profile* profile);
46 // Creates a new ProfilePolicyConnector for |profile|, which must be managed
47 // by the caller. Subsequent calls to GetForProfile() will return the instance
48 // created, as long as it lives.
49 // If |force_immediate_load| is true then policy is loaded synchronously on
51 static scoped_ptr<ProfilePolicyConnector> CreateForProfile(
53 bool force_immediate_load);
55 // Overrides the |connector| for the given |profile|; use only in tests.
56 // Once this class becomes a proper PKS then it can reuse the testing
57 // methods of BrowserContextKeyedServiceFactory.
58 void SetServiceForTesting(Profile* profile,
59 ProfilePolicyConnector* connector);
61 // The next Profile to call CreateForProfile() will get a PolicyService
62 // with |provider| as its sole policy provider. This can be called multiple
63 // times to override the policy providers for more than 1 Profile.
64 void PushProviderForTesting(ConfigurationPolicyProvider* provider);
67 friend struct DefaultSingletonTraits<ProfilePolicyConnectorFactory>;
69 ProfilePolicyConnectorFactory();
70 virtual ~ProfilePolicyConnectorFactory();
72 ProfilePolicyConnector* GetForProfileInternal(Profile* profile);
74 scoped_ptr<ProfilePolicyConnector> CreateForProfileInternal(
76 bool force_immediate_load);
78 // BrowserContextKeyedBaseFactory:
79 virtual void BrowserContextShutdown(
80 content::BrowserContext* context) OVERRIDE;
81 virtual void BrowserContextDestroyed(
82 content::BrowserContext* context) OVERRIDE;
83 virtual void SetEmptyTestingFactory(
84 content::BrowserContext* context) OVERRIDE;
85 virtual bool HasTestingFactory(content::BrowserContext* context) OVERRIDE;
86 virtual void CreateServiceNow(content::BrowserContext* context) OVERRIDE;
88 typedef std::map<Profile*, ProfilePolicyConnector*> ConnectorMap;
89 ConnectorMap connectors_;
90 std::list<ConfigurationPolicyProvider*> test_providers_;
92 DISALLOW_COPY_AND_ASSIGN(ProfilePolicyConnectorFactory);
97 #endif // CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_