Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: chrome/browser/policy/profile_policy_connector.cc

Issue 7147015: Move user cloud policy to BrowserProcess (was 6979011) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix unit_test include breakage Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <algorithm>
6 #include <string>
7
8 #include "base/command_line.h"
9 #include "base/file_util.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/policy/browser_policy_connector.h"
12 #include "chrome/browser/policy/cloud_policy_subsystem.h"
13 #include "chrome/browser/policy/configuration_policy_pref_store.h"
14 #include "chrome/browser/policy/profile_policy_connector.h"
15 #include "chrome/browser/policy/user_policy_cache.h"
16 #include "chrome/browser/policy/user_policy_identity_strategy.h"
17 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/pref_names.h"
21
22 namespace {
23
24 const FilePath::CharType kPolicyDir[] = FILE_PATH_LITERAL("Device Management");
25 const FilePath::CharType kTokenCacheFile[] = FILE_PATH_LITERAL("Token");
26 const FilePath::CharType kPolicyCacheFile[] = FILE_PATH_LITERAL("Policy");
27
28 const int64 kServiceInitializationStartupDelay = 2000;
29
30 } // namespace
31
32 namespace policy {
33
34 ProfilePolicyConnector::ProfilePolicyConnector(Profile* profile)
35 : profile_(profile) {
36 CommandLine* command_line = CommandLine::ForCurrentProcess();
37 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) {
38 FilePath policy_cache_dir(profile_->GetPath());
39 policy_cache_dir = policy_cache_dir.Append(kPolicyDir);
40
41 identity_strategy_.reset(new UserPolicyIdentityStrategy(
42 profile_,
43 policy_cache_dir.Append(kTokenCacheFile)));
44 cloud_policy_subsystem_.reset(new CloudPolicySubsystem(
45 identity_strategy_.get(),
46 new UserPolicyCache(policy_cache_dir.Append(kPolicyCacheFile))));
47
48 BrowserPolicyConnector* browser_connector =
49 g_browser_process->browser_policy_connector();
50
51 managed_cloud_provider_.reset(new MergingPolicyProvider(
52 browser_connector->GetManagedCloudProvider(),
53 cloud_policy_subsystem_->GetManagedPolicyProvider()));
54 recommended_cloud_provider_.reset(new MergingPolicyProvider(
55 browser_connector->GetRecommendedCloudProvider(),
56 cloud_policy_subsystem_->GetRecommendedPolicyProvider()));
57 }
58 }
59
60 ProfilePolicyConnector::~ProfilePolicyConnector() {
61 managed_cloud_provider_.reset();
62 recommended_cloud_provider_.reset();
63 cloud_policy_subsystem_.reset();
64 identity_strategy_.reset();
65 }
66
67 void ProfilePolicyConnector::ScheduleServiceInitialization(
68 int64 delay_milliseconds) {
69 if (cloud_policy_subsystem_.get())
70 cloud_policy_subsystem_->ScheduleServiceInitialization(delay_milliseconds);
71 }
72
73 void ProfilePolicyConnector::Initialize() {
74 if (identity_strategy_.get())
75 identity_strategy_->LoadTokenCache();
76 if (cloud_policy_subsystem_.get()) {
77 cloud_policy_subsystem_->CompleteInitialization(
78 prefs::kUserPolicyRefreshRate,
79 kServiceInitializationStartupDelay);
80 // Temporarily set the subsystem to listen to profile pref service, since
81 // we cannot yet serve user cloud policy to |local_state| and we don't want
82 // the profile reference in the subsystem.
83 profile_pref_registrar_.Init(profile_->GetPrefs());
84 profile_pref_registrar_.Add(prefs::kUserPolicyRefreshRate,
85 cloud_policy_subsystem_.get());
86 }
87 }
88
89 void ProfilePolicyConnector::Shutdown() {
90 if (cloud_policy_subsystem_.get()) {
91 // Remove the temporary profile observer.
92 profile_pref_registrar_.RemoveAll();
93 cloud_policy_subsystem_->Shutdown();
94 }
95 }
96
97 ConfigurationPolicyProvider*
98 ProfilePolicyConnector::GetManagedCloudProvider() {
99 return managed_cloud_provider_.get();
100 }
101
102 ConfigurationPolicyProvider*
103 ProfilePolicyConnector::GetRecommendedCloudProvider() {
104 return recommended_cloud_provider_.get();
105 }
106
107 MergingPolicyProvider::MergingPolicyProvider(
108 ConfigurationPolicyProvider* browser_policy_provider,
109 ConfigurationPolicyProvider* profile_policy_provider)
110 : ConfigurationPolicyProvider(
111 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList()),
112 browser_policy_provider_(browser_policy_provider),
113 profile_policy_provider_(profile_policy_provider),
114 browser_registrar_(new ConfigurationPolicyObserverRegistrar()),
115 profile_registrar_(new ConfigurationPolicyObserverRegistrar()) {
116 if (browser_policy_provider_)
117 browser_registrar_->Init(browser_policy_provider_, this);
118 if (profile_policy_provider_)
119 profile_registrar_->Init(profile_policy_provider_, this);
120 }
121
122 MergingPolicyProvider::~MergingPolicyProvider() {
123 if (browser_policy_provider_ || profile_policy_provider_) {
124 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
125 observer_list_, OnProviderGoingAway());
126 }
127 }
128
129 bool MergingPolicyProvider::Provide(ConfigurationPolicyStoreInterface* store) {
130 // First, apply the profile policies and observe if interesting policies
131 // have been applied.
132 ObservingPolicyStoreInterface observe(store);
133 bool rv = true;
134 if (profile_policy_provider_)
135 rv = profile_policy_provider_->Provide(&observe);
136
137 // Now apply policies from the browser provider, if they were not applied
138 // by the profile provider.
139 // Currently, these include only the proxy settings.
140 if (browser_policy_provider_) {
141 FilteringPolicyStoreInterface filter(store,
142 !observe.IsProxyPolicyApplied());
143 rv = rv && browser_policy_provider_->Provide(&filter);
144 }
145
146 return rv;
147 }
148
149 void MergingPolicyProvider::AddObserver(
150 ConfigurationPolicyProvider::Observer* observer) {
151 observer_list_.AddObserver(observer);
152 }
153
154 void MergingPolicyProvider::RemoveObserver(
155 ConfigurationPolicyProvider::Observer* observer) {
156 observer_list_.RemoveObserver(observer);
157 }
158
159 void MergingPolicyProvider::OnUpdatePolicy() {
160 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
161 observer_list_, OnUpdatePolicy());
162 }
163
164 void MergingPolicyProvider::OnProviderGoingAway() {
165 if (browser_policy_provider_ || profile_policy_provider_) {
166 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
167 observer_list_, OnProviderGoingAway());
168 browser_registrar_.reset();
169 profile_registrar_.reset();
170 browser_policy_provider_ = NULL;
171 profile_policy_provider_ = NULL;
172 }
173 }
174
175 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/profile_policy_connector.h ('k') | chrome/browser/policy/profile_policy_connector_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698