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 <map> | 8 #include <map> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "components/browser_context_keyed_service/browser_context_keyed_base_fa
ctory.h" | 13 #include "components/browser_context_keyed_service/browser_context_keyed_base_fa
ctory.h" |
14 | 14 |
15 class Profile; | 15 class Profile; |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 class SequencedTaskRunner; | 18 class SequencedTaskRunner; |
19 } | 19 } |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 class BrowserContext; | 22 class BrowserContext; |
23 } | 23 } |
24 | 24 |
25 namespace policy { | 25 namespace policy { |
26 | 26 |
| 27 class CloudPolicyManager; |
27 class ProfilePolicyConnector; | 28 class ProfilePolicyConnector; |
28 | 29 |
29 // Creates ProfilePolicyConnectors for Profiles, which manage the common | 30 // Creates ProfilePolicyConnectors for Profiles, which manage the common |
30 // policy providers and other policy components. | 31 // policy providers and other policy components. |
31 // TODO(joaodasilva): convert this class to a proper PKS once the PrefService, | 32 // TODO(joaodasilva): convert this class to a proper PKS once the PrefService, |
32 // which depends on this class, becomes a PKS too. | 33 // which depends on this class, becomes a PKS too. |
33 class ProfilePolicyConnectorFactory : public BrowserContextKeyedBaseFactory { | 34 class ProfilePolicyConnectorFactory : public BrowserContextKeyedBaseFactory { |
34 public: | 35 public: |
35 // Returns the ProfilePolicyConnectorFactory singleton. | 36 // Returns the ProfilePolicyConnectorFactory singleton. |
36 static ProfilePolicyConnectorFactory* GetInstance(); | 37 static ProfilePolicyConnectorFactory* GetInstance(); |
37 | 38 |
38 // Returns the ProfilePolicyConnector associated with |profile|. This is only | 39 // Returns the ProfilePolicyConnector associated with |profile|. This is only |
39 // valid before |profile| is shut down. | 40 // valid before |profile| is shut down. |
40 static ProfilePolicyConnector* GetForProfile(Profile* profile); | 41 static ProfilePolicyConnector* GetForProfile(Profile* profile); |
41 | 42 |
42 // Creates a new ProfilePolicyConnector for |profile|, which must be managed | 43 // Creates a new ProfilePolicyConnector for |profile|, which must be managed |
43 // by the caller. Subsequent calls to GetForProfile() will return the instance | 44 // by the caller. Subsequent calls to GetForProfile() will return the instance |
44 // created, as long as it lives. | 45 // created, as long as it lives. |
45 // If |force_immediate_load| is true then policy is loaded synchronously on | 46 // If |force_immediate_load| is true then policy is loaded synchronously on |
46 // startup. | 47 // startup. |
47 static scoped_ptr<ProfilePolicyConnector> CreateForProfile( | 48 static scoped_ptr<ProfilePolicyConnector> CreateForProfile( |
48 Profile* profile, | 49 Profile* profile, |
49 bool force_immediate_load, | 50 bool force_immediate_load, |
| 51 CloudPolicyManager* user_cloud_policy_manager, |
50 base::SequencedTaskRunner* sequenced_task_runner); | 52 base::SequencedTaskRunner* sequenced_task_runner); |
51 | 53 |
52 // Overrides the |connector| for the given |profile|; use only in tests. | 54 // Overrides the |connector| for the given |profile|; use only in tests. |
53 // Once this class becomes a proper PKS then it can reuse the testing | 55 // Once this class becomes a proper PKS then it can reuse the testing |
54 // methods of BrowserContextKeyedServiceFactory. | 56 // methods of BrowserContextKeyedServiceFactory. |
55 void SetServiceForTesting(Profile* profile, | 57 void SetServiceForTesting(Profile* profile, |
56 ProfilePolicyConnector* connector); | 58 ProfilePolicyConnector* connector); |
57 | 59 |
58 private: | 60 private: |
59 friend struct DefaultSingletonTraits<ProfilePolicyConnectorFactory>; | 61 friend struct DefaultSingletonTraits<ProfilePolicyConnectorFactory>; |
60 | 62 |
61 ProfilePolicyConnectorFactory(); | 63 ProfilePolicyConnectorFactory(); |
62 virtual ~ProfilePolicyConnectorFactory(); | 64 virtual ~ProfilePolicyConnectorFactory(); |
63 | 65 |
64 ProfilePolicyConnector* GetForProfileInternal(Profile* profile); | 66 ProfilePolicyConnector* GetForProfileInternal(Profile* profile); |
65 | 67 |
66 scoped_ptr<ProfilePolicyConnector> CreateForProfileInternal( | 68 scoped_ptr<ProfilePolicyConnector> CreateForProfileInternal( |
67 Profile* profile, | 69 Profile* profile, |
68 bool force_immediate_load, | 70 bool force_immediate_load, |
| 71 CloudPolicyManager* user_cloud_policy_manager, |
69 base::SequencedTaskRunner* sequenced_task_runner); | 72 base::SequencedTaskRunner* sequenced_task_runner); |
70 | 73 |
71 // BrowserContextKeyedBaseFactory: | 74 // BrowserContextKeyedBaseFactory: |
72 virtual void BrowserContextShutdown( | 75 virtual void BrowserContextShutdown( |
73 content::BrowserContext* context) OVERRIDE; | 76 content::BrowserContext* context) OVERRIDE; |
74 virtual void BrowserContextDestroyed( | 77 virtual void BrowserContextDestroyed( |
75 content::BrowserContext* context) OVERRIDE; | 78 content::BrowserContext* context) OVERRIDE; |
76 virtual void RegisterProfilePrefs( | 79 virtual void RegisterProfilePrefs( |
77 user_prefs::PrefRegistrySyncable* registry) OVERRIDE; | 80 user_prefs::PrefRegistrySyncable* registry) OVERRIDE; |
78 virtual void SetEmptyTestingFactory( | 81 virtual void SetEmptyTestingFactory( |
79 content::BrowserContext* context) OVERRIDE; | 82 content::BrowserContext* context) OVERRIDE; |
80 virtual void CreateServiceNow(content::BrowserContext* context) OVERRIDE; | 83 virtual void CreateServiceNow(content::BrowserContext* context) OVERRIDE; |
81 | 84 |
82 typedef std::map<Profile*, ProfilePolicyConnector*> ConnectorMap; | 85 typedef std::map<Profile*, ProfilePolicyConnector*> ConnectorMap; |
83 ConnectorMap connectors_; | 86 ConnectorMap connectors_; |
84 | 87 |
85 DISALLOW_COPY_AND_ASSIGN(ProfilePolicyConnectorFactory); | 88 DISALLOW_COPY_AND_ASSIGN(ProfilePolicyConnectorFactory); |
86 }; | 89 }; |
87 | 90 |
88 } // namespace policy | 91 } // namespace policy |
89 | 92 |
90 #endif // CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_ | 93 #endif // CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_ |
OLD | NEW |