Allow tests to provide a TestingFactoryFunction for NULLWhileTesting factories.
[chromium-blink-merge.git] / chrome / browser / policy / profile_policy_connector_factory.h
blob9442b49fb4520cf5922fd0ebac8c29794157161f
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_
8 #include <map>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/keyed_service/content/browser_context_keyed_base_factory.h"
14 template <typename T>
15 struct DefaultSingletonTraits;
17 class Profile;
19 namespace base {
20 class SequencedTaskRunner;
23 namespace content {
24 class BrowserContext;
27 namespace policy {
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 {
36 public:
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
48 // startup.
49 static scoped_ptr<ProfilePolicyConnector> CreateForProfile(
50 Profile* profile,
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);
59 private:
60 friend struct DefaultSingletonTraits<ProfilePolicyConnectorFactory>;
62 ProfilePolicyConnectorFactory();
63 virtual ~ProfilePolicyConnectorFactory();
65 ProfilePolicyConnector* GetForProfileInternal(Profile* profile);
67 scoped_ptr<ProfilePolicyConnector> CreateForProfileInternal(
68 Profile* profile,
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 SetEmptyTestingFactory(
77 content::BrowserContext* context) OVERRIDE;
78 virtual bool HasTestingFactory(content::BrowserContext* context) OVERRIDE;
79 virtual void CreateServiceNow(content::BrowserContext* context) OVERRIDE;
81 typedef std::map<Profile*, ProfilePolicyConnector*> ConnectorMap;
82 ConnectorMap connectors_;
84 DISALLOW_COPY_AND_ASSIGN(ProfilePolicyConnectorFactory);
87 } // namespace policy
89 #endif // CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_