OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
11 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
12 #include "base/metrics/sparse_histogram.h" | 13 #include "base/metrics/sparse_histogram.h" |
13 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
14 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" | 16 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" |
16 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" | 17 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" |
17 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
18 #include "chrome/browser/policy/cloud/cloud_external_data_manager.h" | 19 #include "chrome/browser/policy/cloud/cloud_external_data_manager.h" |
19 #include "chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h" | 20 #include "chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h" |
20 #include "chrome/browser/policy/cloud/resource_cache.h" | 21 #include "chrome/browser/policy/cloud/resource_cache.h" |
21 #include "chrome/browser/policy/policy_bundle.h" | 22 #include "chrome/browser/policy/policy_bundle.h" |
| 23 #include "chrome/common/chrome_switches.h" |
22 #include "components/policy/core/common/policy_pref_names.h" | 24 #include "components/policy/core/common/policy_pref_names.h" |
23 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
24 #include "net/url_request/url_request_context_getter.h" | 26 #include "net/url_request/url_request_context_getter.h" |
25 | 27 |
26 namespace em = enterprise_management; | 28 namespace em = enterprise_management; |
27 | 29 |
28 namespace policy { | 30 namespace policy { |
29 | 31 |
30 namespace { | 32 namespace { |
31 | 33 |
(...skipping 14 matching lines...) Expand all Loading... |
46 "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2Error"; | 48 "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2Error"; |
47 const char kUMAInitialFetchOAuth2NetworkError[] = | 49 const char kUMAInitialFetchOAuth2NetworkError[] = |
48 "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2NetworkError"; | 50 "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2NetworkError"; |
49 | 51 |
50 } // namespace | 52 } // namespace |
51 | 53 |
52 UserCloudPolicyManagerChromeOS::UserCloudPolicyManagerChromeOS( | 54 UserCloudPolicyManagerChromeOS::UserCloudPolicyManagerChromeOS( |
53 scoped_ptr<CloudPolicyStore> store, | 55 scoped_ptr<CloudPolicyStore> store, |
54 scoped_ptr<CloudExternalDataManager> external_data_manager, | 56 scoped_ptr<CloudExternalDataManager> external_data_manager, |
55 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 57 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
56 scoped_ptr<ResourceCache> resource_cache, | 58 const base::FilePath& resource_cache_dir, |
57 bool wait_for_policy_fetch, | 59 bool wait_for_policy_fetch, |
58 base::TimeDelta initial_policy_fetch_timeout) | 60 base::TimeDelta initial_policy_fetch_timeout) |
59 : CloudPolicyManager( | 61 : CloudPolicyManager( |
60 PolicyNamespaceKey(dm_protocol::kChromeUserPolicyType, std::string()), | 62 PolicyNamespaceKey(dm_protocol::kChromeUserPolicyType, std::string()), |
61 store.get(), | 63 store.get(), |
62 task_runner), | 64 task_runner), |
63 store_(store.Pass()), | 65 store_(store.Pass()), |
64 external_data_manager_(external_data_manager.Pass()), | 66 external_data_manager_(external_data_manager.Pass()), |
| 67 resource_cache_dir_(resource_cache_dir), |
65 wait_for_policy_fetch_(wait_for_policy_fetch), | 68 wait_for_policy_fetch_(wait_for_policy_fetch), |
66 policy_fetch_timeout_(false, false) { | 69 policy_fetch_timeout_(false, false) { |
67 time_init_started_ = base::Time::Now(); | 70 time_init_started_ = base::Time::Now(); |
68 if (wait_for_policy_fetch_) { | 71 if (wait_for_policy_fetch_) { |
69 policy_fetch_timeout_.Start( | 72 policy_fetch_timeout_.Start( |
70 FROM_HERE, | 73 FROM_HERE, |
71 initial_policy_fetch_timeout, | 74 initial_policy_fetch_timeout, |
72 base::Bind(&UserCloudPolicyManagerChromeOS::CancelWaitForPolicyFetch, | 75 base::Bind(&UserCloudPolicyManagerChromeOS::CancelWaitForPolicyFetch, |
73 base::Unretained(this))); | 76 base::Unretained(this))); |
74 } | 77 } |
75 if (resource_cache) { | |
76 // TODO(joaodasilva): Move the backend from the FILE thread to the blocking | |
77 // pool. | |
78 component_policy_service_.reset(new ComponentCloudPolicyService( | |
79 this, | |
80 store_.get(), | |
81 resource_cache.Pass(), | |
82 content::BrowserThread::GetMessageLoopProxyForThread( | |
83 content::BrowserThread::FILE), | |
84 content::BrowserThread::GetMessageLoopProxyForThread( | |
85 content::BrowserThread::IO))); | |
86 } | |
87 } | 78 } |
88 | 79 |
89 UserCloudPolicyManagerChromeOS::~UserCloudPolicyManagerChromeOS() {} | 80 UserCloudPolicyManagerChromeOS::~UserCloudPolicyManagerChromeOS() {} |
90 | 81 |
91 void UserCloudPolicyManagerChromeOS::Connect( | 82 void UserCloudPolicyManagerChromeOS::Connect( |
92 PrefService* local_state, | 83 PrefService* local_state, |
93 DeviceManagementService* device_management_service, | 84 DeviceManagementService* device_management_service, |
94 scoped_refptr<net::URLRequestContextGetter> request_context, | 85 scoped_refptr<net::URLRequestContextGetter> request_context, |
95 UserAffiliation user_affiliation) { | 86 UserAffiliation user_affiliation) { |
96 DCHECK(device_management_service); | 87 DCHECK(device_management_service); |
97 DCHECK(local_state); | 88 DCHECK(local_state); |
98 local_state_ = local_state; | 89 local_state_ = local_state; |
99 scoped_ptr<CloudPolicyClient> cloud_policy_client( | 90 scoped_ptr<CloudPolicyClient> cloud_policy_client( |
100 new CloudPolicyClient(std::string(), std::string(), user_affiliation, | 91 new CloudPolicyClient(std::string(), std::string(), user_affiliation, |
101 NULL, device_management_service)); | 92 NULL, device_management_service)); |
102 core()->Connect(cloud_policy_client.Pass()); | 93 core()->Connect(cloud_policy_client.Pass()); |
103 client()->AddObserver(this); | 94 client()->AddObserver(this); |
104 | 95 |
105 external_data_manager_->Connect(request_context); | 96 external_data_manager_->Connect(request_context); |
106 | 97 |
107 if (component_policy_service_) | 98 CreateComponentCloudPolicyService(request_context); |
108 component_policy_service_->Connect(client(), request_context); | |
109 | 99 |
110 // Determine the next step after the CloudPolicyService initializes. | 100 // Determine the next step after the CloudPolicyService initializes. |
111 if (service()->IsInitializationComplete()) { | 101 if (service()->IsInitializationComplete()) { |
112 OnInitializationCompleted(service()); | 102 OnInitializationCompleted(service()); |
113 } else { | 103 } else { |
114 service()->AddObserver(this); | 104 service()->AddObserver(this); |
115 } | 105 } |
116 } | 106 } |
117 | 107 |
118 void UserCloudPolicyManagerChromeOS::OnAccessTokenAvailable( | 108 void UserCloudPolicyManagerChromeOS::OnAccessTokenAvailable( |
(...skipping 27 matching lines...) Expand all Loading... |
146 return false; | 136 return false; |
147 if (domain == POLICY_DOMAIN_CHROME) | 137 if (domain == POLICY_DOMAIN_CHROME) |
148 return !wait_for_policy_fetch_; | 138 return !wait_for_policy_fetch_; |
149 if (ComponentCloudPolicyService::SupportsDomain(domain) && | 139 if (ComponentCloudPolicyService::SupportsDomain(domain) && |
150 component_policy_service_) { | 140 component_policy_service_) { |
151 return component_policy_service_->is_initialized(); | 141 return component_policy_service_->is_initialized(); |
152 } | 142 } |
153 return true; | 143 return true; |
154 } | 144 } |
155 | 145 |
156 void UserCloudPolicyManagerChromeOS::OnSchemaRegistryUpdated( | |
157 bool has_new_schemas) { | |
158 // Send the new map even if |has_new_schemas| is false, so that policies for | |
159 // components that have been removed can be dropped from the cache. | |
160 if (component_policy_service_) | |
161 component_policy_service_->OnSchemasUpdated(schema_map()); | |
162 } | |
163 | |
164 scoped_ptr<PolicyBundle> UserCloudPolicyManagerChromeOS::CreatePolicyBundle() { | 146 scoped_ptr<PolicyBundle> UserCloudPolicyManagerChromeOS::CreatePolicyBundle() { |
165 scoped_ptr<PolicyBundle> bundle = CloudPolicyManager::CreatePolicyBundle(); | 147 scoped_ptr<PolicyBundle> bundle = CloudPolicyManager::CreatePolicyBundle(); |
166 if (component_policy_service_) | 148 if (component_policy_service_) |
167 bundle->MergeFrom(component_policy_service_->policy()); | 149 bundle->MergeFrom(component_policy_service_->policy()); |
168 return bundle.Pass(); | 150 return bundle.Pass(); |
169 } | 151 } |
170 | 152 |
171 void UserCloudPolicyManagerChromeOS::OnInitializationCompleted( | 153 void UserCloudPolicyManagerChromeOS::OnInitializationCompleted( |
172 CloudPolicyService* cloud_policy_service) { | 154 CloudPolicyService* cloud_policy_service) { |
173 DCHECK_EQ(service(), cloud_policy_service); | 155 DCHECK_EQ(service(), cloud_policy_service); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 | 234 |
253 void UserCloudPolicyManagerChromeOS::OnComponentCloudPolicyRefreshNeeded() { | 235 void UserCloudPolicyManagerChromeOS::OnComponentCloudPolicyRefreshNeeded() { |
254 core()->RefreshSoon(); | 236 core()->RefreshSoon(); |
255 } | 237 } |
256 | 238 |
257 void UserCloudPolicyManagerChromeOS::OnComponentCloudPolicyUpdated() { | 239 void UserCloudPolicyManagerChromeOS::OnComponentCloudPolicyUpdated() { |
258 CheckAndPublishPolicy(); | 240 CheckAndPublishPolicy(); |
259 StartRefreshSchedulerIfReady(); | 241 StartRefreshSchedulerIfReady(); |
260 } | 242 } |
261 | 243 |
| 244 void UserCloudPolicyManagerChromeOS::CreateComponentCloudPolicyService( |
| 245 const scoped_refptr<net::URLRequestContextGetter>& request_context) { |
| 246 // Init() must have been called. |
| 247 DCHECK(schema_registry()); |
| 248 // Called at most once. |
| 249 DCHECK(!component_policy_service_); |
| 250 |
| 251 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 252 switches::kEnableComponentCloudPolicy)) { |
| 253 return; |
| 254 } |
| 255 |
| 256 // TODO(joaodasilva): Move the |backend_task_runner| to the blocking pool. |
| 257 // Currently it's not possible because the ComponentCloudPolicyStore is |
| 258 // NonThreadSafe and doesn't support getting calls from different threads. |
| 259 scoped_refptr<base::SequencedTaskRunner> backend_task_runner = |
| 260 content::BrowserThread::GetMessageLoopProxyForThread( |
| 261 content::BrowserThread::FILE); |
| 262 scoped_ptr<ResourceCache> resource_cache( |
| 263 new ResourceCache(resource_cache_dir_, backend_task_runner)); |
| 264 component_policy_service_.reset(new ComponentCloudPolicyService( |
| 265 this, |
| 266 schema_registry(), |
| 267 store_.get(), |
| 268 resource_cache.Pass(), |
| 269 client(), |
| 270 request_context, |
| 271 backend_task_runner, |
| 272 content::BrowserThread::GetMessageLoopProxyForThread( |
| 273 content::BrowserThread::IO))); |
| 274 } |
| 275 |
262 void UserCloudPolicyManagerChromeOS::FetchPolicyOAuthTokenUsingSigninProfile() { | 276 void UserCloudPolicyManagerChromeOS::FetchPolicyOAuthTokenUsingSigninProfile() { |
263 scoped_refptr<net::URLRequestContextGetter> signin_context; | 277 scoped_refptr<net::URLRequestContextGetter> signin_context; |
264 Profile* signin_profile = chromeos::ProfileHelper::GetSigninProfile(); | 278 Profile* signin_profile = chromeos::ProfileHelper::GetSigninProfile(); |
265 if (signin_profile) | 279 if (signin_profile) |
266 signin_context = signin_profile->GetRequestContext(); | 280 signin_context = signin_profile->GetRequestContext(); |
267 if (!signin_context.get()) { | 281 if (!signin_context.get()) { |
268 LOG(ERROR) << "No signin Profile for policy oauth token fetch!"; | 282 LOG(ERROR) << "No signin Profile for policy oauth token fetch!"; |
269 OnOAuth2PolicyTokenFetched( | 283 OnOAuth2PolicyTokenFetched( |
270 std::string(), GoogleServiceAuthError(GoogleServiceAuthError::NONE)); | 284 std::string(), GoogleServiceAuthError(GoogleServiceAuthError::NONE)); |
271 return; | 285 return; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 // OnComponentCloudPolicyUpdated() once it's ready. | 362 // OnComponentCloudPolicyUpdated() once it's ready. |
349 return; | 363 return; |
350 } | 364 } |
351 | 365 |
352 core()->StartRefreshScheduler(); | 366 core()->StartRefreshScheduler(); |
353 core()->TrackRefreshDelayPref(local_state_, | 367 core()->TrackRefreshDelayPref(local_state_, |
354 policy_prefs::kUserPolicyRefreshRate); | 368 policy_prefs::kUserPolicyRefreshRate); |
355 } | 369 } |
356 | 370 |
357 } // namespace policy | 371 } // namespace policy |
OLD | NEW |