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"
17 struct DefaultSingletonTraits
;
19 class SequencedTaskRunner
;
28 class ConfigurationPolicyProvider
;
29 class ProfilePolicyConnector
;
31 // Creates ProfilePolicyConnectors for Profiles, which manage the common
32 // policy providers and other policy components.
33 // TODO(joaodasilva): convert this class to a proper BCKS once the PrefService,
34 // which depends on this class, becomes a BCKS too.
35 class ProfilePolicyConnectorFactory
: public BrowserContextKeyedBaseFactory
{
37 // Returns the ProfilePolicyConnectorFactory singleton.
38 static ProfilePolicyConnectorFactory
* GetInstance();
40 // Returns the ProfilePolicyConnector associated with |context|. This is only
41 // valid before |context| is shut down.
42 static ProfilePolicyConnector
* GetForBrowserContext(
43 content::BrowserContext
* context
);
45 // Creates a new ProfilePolicyConnector for |context|, which must be managed
46 // by the caller. Subsequent calls to GetForBrowserContext() will return the
47 // instance created, as long as it lives.
48 // If |force_immediate_load| is true then policy is loaded synchronously on
50 static scoped_ptr
<ProfilePolicyConnector
> CreateForBrowserContext(
51 content::BrowserContext
* context
,
52 bool force_immediate_load
);
54 // Overrides the |connector| for the given |context|; use only in tests.
55 // Once this class becomes a proper BCKS then it can reuse the testing
56 // methods of BrowserContextKeyedServiceFactory.
57 void SetServiceForTesting(content::BrowserContext
* context
,
58 ProfilePolicyConnector
* connector
);
60 // The next Profile to call CreateForBrowserContext() will get a PolicyService
61 // with |provider| as its sole policy provider. This can be called multiple
62 // times to override the policy providers for more than 1 Profile.
63 void PushProviderForTesting(ConfigurationPolicyProvider
* provider
);
66 friend struct base::DefaultSingletonTraits
<ProfilePolicyConnectorFactory
>;
68 ProfilePolicyConnectorFactory();
69 ~ProfilePolicyConnectorFactory() override
;
71 ProfilePolicyConnector
* GetForBrowserContextInternal(
72 content::BrowserContext
* context
);
74 scoped_ptr
<ProfilePolicyConnector
> CreateForBrowserContextInternal(
75 content::BrowserContext
* context
,
76 bool force_immediate_load
);
78 // BrowserContextKeyedBaseFactory:
79 void BrowserContextShutdown(content::BrowserContext
* context
) override
;
80 void BrowserContextDestroyed(content::BrowserContext
* context
) override
;
81 void SetEmptyTestingFactory(content::BrowserContext
* context
) override
;
82 bool HasTestingFactory(content::BrowserContext
* context
) override
;
83 void CreateServiceNow(content::BrowserContext
* context
) override
;
85 typedef std::map
<content::BrowserContext
*, ProfilePolicyConnector
*>
87 ConnectorMap connectors_
;
88 std::list
<ConfigurationPolicyProvider
*> test_providers_
;
90 DISALLOW_COPY_AND_ASSIGN(ProfilePolicyConnectorFactory
);
95 #endif // CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_