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_
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/browser_context_keyed_service/browser_context_keyed_base_factory.h"
15 struct DefaultSingletonTraits
;
20 class SequencedTaskRunner
;
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 PKS once the PrefService,
34 // which depends on this class, becomes a PKS too.
35 class ProfilePolicyConnectorFactory
: public BrowserContextKeyedBaseFactory
{
37 // Returns the ProfilePolicyConnectorFactory singleton.
38 static ProfilePolicyConnectorFactory
* GetInstance();
40 // Returns the ProfilePolicyConnector associated with |profile|. This is only
41 // valid before |profile| is shut down.
42 static ProfilePolicyConnector
* GetForProfile(Profile
* profile
);
44 // Creates a new ProfilePolicyConnector for |profile|, which must be managed
45 // by the caller. Subsequent calls to GetForProfile() will return the instance
46 // created, as long as it lives.
47 // If |force_immediate_load| is true then policy is loaded synchronously on
49 static scoped_ptr
<ProfilePolicyConnector
> CreateForProfile(
51 bool force_immediate_load
);
53 // Overrides the |connector| for the given |profile|; use only in tests.
54 // Once this class becomes a proper PKS then it can reuse the testing
55 // methods of BrowserContextKeyedServiceFactory.
56 void SetServiceForTesting(Profile
* profile
,
57 ProfilePolicyConnector
* connector
);
60 friend struct DefaultSingletonTraits
<ProfilePolicyConnectorFactory
>;
62 ProfilePolicyConnectorFactory();
63 virtual ~ProfilePolicyConnectorFactory();
65 ProfilePolicyConnector
* GetForProfileInternal(Profile
* profile
);
67 scoped_ptr
<ProfilePolicyConnector
> CreateForProfileInternal(
69 bool force_immediate_load
);
71 // BrowserContextKeyedBaseFactory:
72 virtual void BrowserContextShutdown(
73 content::BrowserContext
* context
) OVERRIDE
;
74 virtual void BrowserContextDestroyed(
75 content::BrowserContext
* context
) OVERRIDE
;
76 virtual void RegisterProfilePrefs(
77 user_prefs::PrefRegistrySyncable
* registry
) OVERRIDE
;
78 virtual void SetEmptyTestingFactory(
79 content::BrowserContext
* context
) OVERRIDE
;
80 virtual void CreateServiceNow(content::BrowserContext
* context
) OVERRIDE
;
82 typedef std::map
<Profile
*, ProfilePolicyConnector
*> ConnectorMap
;
83 ConnectorMap connectors_
;
85 DISALLOW_COPY_AND_ASSIGN(ProfilePolicyConnectorFactory
);
90 #endif // CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_