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

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

Issue 6979011: Move user cloud policy to BrowserProcess. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments by mnissler. Created 9 years, 6 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_->Initialize(prefs::kUserPolicyRefreshRate,
78 kServiceInitializationStartupDelay);
79 // Temporarily set the subsystem to listen to profile pref service, since
80 // we cannot yet serve user cloud policy to |local_state| and we don't want
81 // the profile reference in the subsystem.
82 profile_pref_registrar_.Init(profile_->GetPrefs());
83 profile_pref_registrar_.Add(prefs::kUserPolicyRefreshRate,
84 cloud_policy_subsystem_.get());
85 }
86 }
87
88 void ProfilePolicyConnector::Shutdown() {
89 if (cloud_policy_subsystem_.get()) {
90 // Remove the temporary profile observer.
91 profile_pref_registrar_.RemoveAll();
92 cloud_policy_subsystem_->Shutdown();
93 }
94 }
95
96 ConfigurationPolicyProvider*
97 ProfilePolicyConnector::GetManagedCloudProvider() {
98 return managed_cloud_provider_.get();
99 }
100
101 ConfigurationPolicyProvider*
102 ProfilePolicyConnector::GetRecommendedCloudProvider() {
103 return recommended_cloud_provider_.get();
104 }
105
106 MergingPolicyProvider::MergingPolicyProvider(
107 ConfigurationPolicyProvider* browser_policy_provider,
108 ConfigurationPolicyProvider* profile_policy_provider)
109 : ConfigurationPolicyProvider(
110 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList()),
111 browser_policy_provider_(browser_policy_provider),
112 profile_policy_provider_(profile_policy_provider),
113 browser_registrar_(new ConfigurationPolicyObserverRegistrar()),
114 profile_registrar_(new ConfigurationPolicyObserverRegistrar()) {
115 if (browser_policy_provider_)
116 browser_registrar_->Init(browser_policy_provider_, this);
117 if (profile_policy_provider_)
118 profile_registrar_->Init(profile_policy_provider_, this);
119 }
120
121 MergingPolicyProvider::~MergingPolicyProvider() {
122 if (browser_policy_provider_ || profile_policy_provider_) {
123 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
124 observer_list_, OnProviderGoingAway());
125 }
126 }
127
128 bool MergingPolicyProvider::Provide(ConfigurationPolicyStoreInterface* store) {
129 // First, apply the profile policies and observe if interesting policies
130 // have been applied.
131 ObservingPolicyStoreInterface observe(store);
132 bool rv = true;
133 if (profile_policy_provider_)
134 rv = profile_policy_provider_->Provide(&observe);
135
136 // Now apply policies from the browser provider, if they were not applied
137 // by the profile provider.
138 // Currently, these include only the proxy settings.
139 if (browser_policy_provider_) {
140 FilteringPolicyStoreInterface filter(store,
141 !observe.IsProxyPolicyApplied());
142 rv = rv && browser_policy_provider_->Provide(&filter);
143 }
144
145 return rv;
146 }
147
148 void MergingPolicyProvider::AddObserver(
149 ConfigurationPolicyProvider::Observer* observer) {
150 observer_list_.AddObserver(observer);
151 }
152
153 void MergingPolicyProvider::RemoveObserver(
154 ConfigurationPolicyProvider::Observer* observer) {
155 observer_list_.RemoveObserver(observer);
156 }
157
158 void MergingPolicyProvider::OnUpdatePolicy() {
159 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
160 observer_list_, OnUpdatePolicy());
161 }
162
163 void MergingPolicyProvider::OnProviderGoingAway() {
164 if (browser_policy_provider_ || profile_policy_provider_) {
165 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
166 observer_list_, OnProviderGoingAway());
167 browser_registrar_.reset();
168 profile_registrar_.reset();
169 browser_policy_provider_ = NULL;
170 profile_policy_provider_ = NULL;
171 }
172 }
173
174 } // 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