OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_H_ | 5 #ifndef CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_H_ |
6 #define CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_H_ | 6 #define CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/file_util.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
12 #include "chrome/browser/policy/configuration_policy_provider.h" | 13 #include "chrome/browser/policy/configuration_policy_provider.h" |
13 #include "chrome/browser/profiles/profile_keyed_service.h" | 14 #include "content/common/notification_observer.h" |
| 15 #include "content/common/notification_registrar.h" |
14 | 16 |
15 class Profile; | 17 class TokenService; |
16 | |
17 namespace policy { | 18 namespace policy { |
18 | 19 |
19 class CloudPolicySubsystem; | 20 class CloudPolicySubsystem; |
| 21 class CloudPolicyProvider; |
20 class UserPolicyIdentityStrategy; | 22 class UserPolicyIdentityStrategy; |
21 | 23 |
22 // This class is a container for the profile-specific policy bits located in the | 24 // This class is a container for the profile-specific policy bits located in the |
23 // profile. Since the subsystem owns the policy provider, it's vital that it | 25 // profile. Since the subsystem owns the policy provider, it's vital that it |
24 // gets initialized before the profile's prefs and destroyed after the prefs | 26 // gets initialized before the profile's prefs and destroyed after the prefs |
25 // are gone. | 27 // are gone. |
26 class ProfilePolicyConnector : public ProfileKeyedService { | 28 class ProfilePolicyConnector : public NotificationObserver { |
27 public: | 29 public: |
28 explicit ProfilePolicyConnector(Profile* profile); | 30 static ProfilePolicyConnector* Create(); |
29 ~ProfilePolicyConnector(); | 31 ~ProfilePolicyConnector(); |
30 | 32 |
31 // Initializes the context. Should be called only after the profile's request | 33 // Initializes the CloudPolicySubsystem backend and throws away the old one. |
32 // context is up. | 34 // TODO(sfeuz): Listen to log-out or going-away messages of TokenService and |
33 void Initialize(); | 35 // reset the backend at that point. |
| 36 void Initialize(std::string& user_name, |
| 37 const FilePath& policy_dir, |
| 38 TokenService* token_service); |
34 | 39 |
35 // Shuts the context down. This must be called before the networking | 40 CloudPolicyProvider* GetManagedCloudProvider() const; |
36 // infrastructure in the profile goes away. | 41 CloudPolicyProvider* GetRecommendedCloudProvider() const; |
37 // | |
38 // TODO(jknotten): this will be called by ProfileDependencyManager -- | |
39 // ensure that it is dependent on the right services. See comment | |
40 // in ProfilePolicyConnectorFactory::ProfilePolicyConnectorFactory. | |
41 virtual void Shutdown() OVERRIDE; | |
42 | |
43 ConfigurationPolicyProvider* GetManagedCloudProvider(); | |
44 ConfigurationPolicyProvider* GetRecommendedCloudProvider(); | |
45 | 42 |
46 private: | 43 private: |
47 Profile* profile_; | 44 ProfilePolicyConnector(); |
| 45 |
| 46 // NotificationObserver method overrides: |
| 47 virtual void Observe(NotificationType type, |
| 48 const NotificationSource& source, |
| 49 const NotificationDetails& details); |
| 50 |
| 51 // Registers the provider for notification of successful Gaia logins. |
| 52 NotificationRegistrar registrar_; |
| 53 |
| 54 TokenService* token_service_; |
48 | 55 |
49 scoped_ptr<UserPolicyIdentityStrategy> identity_strategy_; | 56 scoped_ptr<UserPolicyIdentityStrategy> identity_strategy_; |
50 scoped_ptr<CloudPolicySubsystem> cloud_policy_subsystem_; | 57 scoped_ptr<CloudPolicySubsystem> cloud_policy_subsystem_; |
51 | 58 |
52 scoped_ptr<ConfigurationPolicyProvider> managed_cloud_provider_; | 59 scoped_ptr<CloudPolicyProvider> managed_cloud_provider_; |
53 scoped_ptr<ConfigurationPolicyProvider> recommended_cloud_provider_; | 60 scoped_ptr<CloudPolicyProvider> recommended_cloud_provider_; |
54 | 61 |
55 DISALLOW_COPY_AND_ASSIGN(ProfilePolicyConnector); | 62 DISALLOW_COPY_AND_ASSIGN(ProfilePolicyConnector); |
56 }; | 63 }; |
57 | 64 |
58 // A wrapper for the ProfilePolicyConnector's cloud providers. | |
59 // | |
60 // Some well-known policies that are not provided by the | |
61 // |profile_policy_provider_| are instead provided by the | |
62 // |browser_policy_provider_|, thus merging device policies into | |
63 // profile policies. | |
64 // | |
65 // Currently used to pass the device proxy settings into the profile | |
66 // preferences. | |
67 class MergingPolicyProvider: public ConfigurationPolicyProvider, | |
68 public ConfigurationPolicyProvider::Observer { | |
69 public: | |
70 MergingPolicyProvider(ConfigurationPolicyProvider* browser_policy_provider, | |
71 ConfigurationPolicyProvider* profile_policy_provider); | |
72 virtual ~MergingPolicyProvider(); | |
73 | |
74 // ConfigurationPolicyProvider methods: | |
75 virtual bool Provide(ConfigurationPolicyStoreInterface* store) OVERRIDE; | |
76 virtual void AddObserver( | |
77 ConfigurationPolicyProvider::Observer* observer) OVERRIDE; | |
78 virtual void RemoveObserver( | |
79 ConfigurationPolicyProvider::Observer* observer) OVERRIDE; | |
80 | |
81 // ConfigurationPolicyProvider::Observer methods: | |
82 virtual void OnUpdatePolicy() OVERRIDE; | |
83 virtual void OnProviderGoingAway() OVERRIDE; | |
84 | |
85 private: | |
86 ConfigurationPolicyProvider* browser_policy_provider_; | |
87 ConfigurationPolicyProvider* profile_policy_provider_; | |
88 scoped_ptr<ConfigurationPolicyObserverRegistrar> browser_registrar_; | |
89 scoped_ptr<ConfigurationPolicyObserverRegistrar> profile_registrar_; | |
90 ObserverList<ConfigurationPolicyProvider::Observer, true> observer_list_; | |
91 | |
92 DISALLOW_COPY_AND_ASSIGN(MergingPolicyProvider); | |
93 }; | |
94 | |
95 | |
96 } // namespace policy | 65 } // namespace policy |
97 | 66 |
98 #endif // CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_H_ | 67 #endif // CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_H_ |
OLD | NEW |