OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_ | 5 #ifndef CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_ |
6 #define CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_ | 6 #define CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_ |
7 | 7 |
| 8 #include <list> |
8 #include <map> | 9 #include <map> |
9 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "components/keyed_service/content/browser_context_keyed_base_factory.h" | 13 #include "components/keyed_service/content/browser_context_keyed_base_factory.h" |
13 | 14 |
14 template <typename T> | 15 template <typename T> |
15 struct DefaultSingletonTraits; | 16 struct DefaultSingletonTraits; |
16 | 17 |
17 class Profile; | 18 class Profile; |
18 | 19 |
19 namespace base { | 20 namespace base { |
20 class SequencedTaskRunner; | 21 class SequencedTaskRunner; |
21 } | 22 } |
22 | 23 |
23 namespace content { | 24 namespace content { |
24 class BrowserContext; | 25 class BrowserContext; |
25 } | 26 } |
26 | 27 |
27 namespace policy { | 28 namespace policy { |
28 | 29 |
| 30 class ConfigurationPolicyProvider; |
29 class ProfilePolicyConnector; | 31 class ProfilePolicyConnector; |
30 | 32 |
31 // Creates ProfilePolicyConnectors for Profiles, which manage the common | 33 // Creates ProfilePolicyConnectors for Profiles, which manage the common |
32 // policy providers and other policy components. | 34 // policy providers and other policy components. |
33 // TODO(joaodasilva): convert this class to a proper PKS once the PrefService, | 35 // TODO(joaodasilva): convert this class to a proper PKS once the PrefService, |
34 // which depends on this class, becomes a PKS too. | 36 // which depends on this class, becomes a PKS too. |
35 class ProfilePolicyConnectorFactory : public BrowserContextKeyedBaseFactory { | 37 class ProfilePolicyConnectorFactory : public BrowserContextKeyedBaseFactory { |
36 public: | 38 public: |
37 // Returns the ProfilePolicyConnectorFactory singleton. | 39 // Returns the ProfilePolicyConnectorFactory singleton. |
38 static ProfilePolicyConnectorFactory* GetInstance(); | 40 static ProfilePolicyConnectorFactory* GetInstance(); |
(...skipping 10 matching lines...) Expand all Loading... |
49 static scoped_ptr<ProfilePolicyConnector> CreateForProfile( | 51 static scoped_ptr<ProfilePolicyConnector> CreateForProfile( |
50 Profile* profile, | 52 Profile* profile, |
51 bool force_immediate_load); | 53 bool force_immediate_load); |
52 | 54 |
53 // Overrides the |connector| for the given |profile|; use only in tests. | 55 // 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 | 56 // Once this class becomes a proper PKS then it can reuse the testing |
55 // methods of BrowserContextKeyedServiceFactory. | 57 // methods of BrowserContextKeyedServiceFactory. |
56 void SetServiceForTesting(Profile* profile, | 58 void SetServiceForTesting(Profile* profile, |
57 ProfilePolicyConnector* connector); | 59 ProfilePolicyConnector* connector); |
58 | 60 |
| 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); |
| 65 |
59 private: | 66 private: |
60 friend struct DefaultSingletonTraits<ProfilePolicyConnectorFactory>; | 67 friend struct DefaultSingletonTraits<ProfilePolicyConnectorFactory>; |
61 | 68 |
62 ProfilePolicyConnectorFactory(); | 69 ProfilePolicyConnectorFactory(); |
63 virtual ~ProfilePolicyConnectorFactory(); | 70 virtual ~ProfilePolicyConnectorFactory(); |
64 | 71 |
65 ProfilePolicyConnector* GetForProfileInternal(Profile* profile); | 72 ProfilePolicyConnector* GetForProfileInternal(Profile* profile); |
66 | 73 |
67 scoped_ptr<ProfilePolicyConnector> CreateForProfileInternal( | 74 scoped_ptr<ProfilePolicyConnector> CreateForProfileInternal( |
68 Profile* profile, | 75 Profile* profile, |
69 bool force_immediate_load); | 76 bool force_immediate_load); |
70 | 77 |
71 // BrowserContextKeyedBaseFactory: | 78 // BrowserContextKeyedBaseFactory: |
72 virtual void BrowserContextShutdown( | 79 virtual void BrowserContextShutdown( |
73 content::BrowserContext* context) OVERRIDE; | 80 content::BrowserContext* context) OVERRIDE; |
74 virtual void BrowserContextDestroyed( | 81 virtual void BrowserContextDestroyed( |
75 content::BrowserContext* context) OVERRIDE; | 82 content::BrowserContext* context) OVERRIDE; |
76 virtual void SetEmptyTestingFactory( | 83 virtual void SetEmptyTestingFactory( |
77 content::BrowserContext* context) OVERRIDE; | 84 content::BrowserContext* context) OVERRIDE; |
78 virtual bool HasTestingFactory(content::BrowserContext* context) OVERRIDE; | 85 virtual bool HasTestingFactory(content::BrowserContext* context) OVERRIDE; |
79 virtual void CreateServiceNow(content::BrowserContext* context) OVERRIDE; | 86 virtual void CreateServiceNow(content::BrowserContext* context) OVERRIDE; |
80 | 87 |
81 typedef std::map<Profile*, ProfilePolicyConnector*> ConnectorMap; | 88 typedef std::map<Profile*, ProfilePolicyConnector*> ConnectorMap; |
82 ConnectorMap connectors_; | 89 ConnectorMap connectors_; |
| 90 std::list<ConfigurationPolicyProvider*> test_providers_; |
83 | 91 |
84 DISALLOW_COPY_AND_ASSIGN(ProfilePolicyConnectorFactory); | 92 DISALLOW_COPY_AND_ASSIGN(ProfilePolicyConnectorFactory); |
85 }; | 93 }; |
86 | 94 |
87 } // namespace policy | 95 } // namespace policy |
88 | 96 |
89 #endif // CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_ | 97 #endif // CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_ |
OLD | NEW |