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 #include "chrome/browser/policy/cloud/component_cloud_policy_service.h" | 5 #include "chrome/browser/policy/cloud/component_cloud_policy_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 scoped_refptr<net::URLRequestContextGetter> request_context, | 217 scoped_refptr<net::URLRequestContextGetter> request_context, |
218 scoped_refptr<base::SequencedTaskRunner> backend_task_runner, | 218 scoped_refptr<base::SequencedTaskRunner> backend_task_runner, |
219 scoped_refptr<base::SequencedTaskRunner> io_task_runner) | 219 scoped_refptr<base::SequencedTaskRunner> io_task_runner) |
220 : delegate_(delegate), | 220 : delegate_(delegate), |
221 schema_registry_(schema_registry), | 221 schema_registry_(schema_registry), |
222 core_(core), | 222 core_(core), |
223 request_context_(request_context), | 223 request_context_(request_context), |
224 backend_task_runner_(backend_task_runner), | 224 backend_task_runner_(backend_task_runner), |
225 io_task_runner_(io_task_runner), | 225 io_task_runner_(io_task_runner), |
226 current_schema_map_(new SchemaMap), | 226 current_schema_map_(new SchemaMap), |
| 227 started_loading_initial_policy_(false), |
227 loaded_initial_policy_(false), | 228 loaded_initial_policy_(false), |
228 is_registered_for_cloud_policy_(false), | 229 is_registered_for_cloud_policy_(false), |
229 weak_ptr_factory_(this) { | 230 weak_ptr_factory_(this) { |
230 external_policy_data_fetcher_backend_.reset( | 231 external_policy_data_fetcher_backend_.reset( |
231 new ExternalPolicyDataFetcherBackend(io_task_runner_, request_context)); | 232 new ExternalPolicyDataFetcherBackend(io_task_runner_, request_context)); |
232 | 233 |
233 backend_.reset( | 234 backend_.reset( |
234 new Backend(weak_ptr_factory_.GetWeakPtr(), | 235 new Backend(weak_ptr_factory_.GetWeakPtr(), |
235 backend_task_runner_, | 236 backend_task_runner_, |
236 base::MessageLoopProxy::current(), | 237 base::MessageLoopProxy::current(), |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 // CloudPolicyStore instead. | 415 // CloudPolicyStore instead. |
415 } | 416 } |
416 | 417 |
417 void ComponentCloudPolicyService::OnClientError(CloudPolicyClient* client) { | 418 void ComponentCloudPolicyService::OnClientError(CloudPolicyClient* client) { |
418 DCHECK(CalledOnValidThread()); | 419 DCHECK(CalledOnValidThread()); |
419 // Ignored. | 420 // Ignored. |
420 } | 421 } |
421 | 422 |
422 void ComponentCloudPolicyService::InitializeIfReady() { | 423 void ComponentCloudPolicyService::InitializeIfReady() { |
423 DCHECK(CalledOnValidThread()); | 424 DCHECK(CalledOnValidThread()); |
424 if (!schema_registry_->IsReady() || !core_->store()->is_initialized()) | 425 if (started_loading_initial_policy_ || !schema_registry_->IsReady() || |
| 426 !core_->store()->is_initialized()) { |
425 return; | 427 return; |
| 428 } |
426 // The initial list of components is ready. Initialize the backend now, which | 429 // The initial list of components is ready. Initialize the backend now, which |
427 // will call back to OnBackendInitialized. | 430 // will call back to OnBackendInitialized. |
428 backend_task_runner_->PostTask(FROM_HERE, | 431 backend_task_runner_->PostTask(FROM_HERE, |
429 base::Bind(&Backend::Init, | 432 base::Bind(&Backend::Init, |
430 base::Unretained(backend_.get()), | 433 base::Unretained(backend_.get()), |
431 schema_registry_->schema_map())); | 434 schema_registry_->schema_map())); |
| 435 started_loading_initial_policy_ = true; |
432 } | 436 } |
433 | 437 |
434 void ComponentCloudPolicyService::OnBackendInitialized( | 438 void ComponentCloudPolicyService::OnBackendInitialized( |
435 scoped_ptr<PolicyBundle> initial_policy) { | 439 scoped_ptr<PolicyBundle> initial_policy) { |
436 DCHECK(CalledOnValidThread()); | 440 DCHECK(CalledOnValidThread()); |
| 441 DCHECK(!loaded_initial_policy_); |
437 | 442 |
438 loaded_initial_policy_ = true; | 443 loaded_initial_policy_ = true; |
439 | 444 |
440 // We're now ready to serve the initial policy; notify the policy observers. | 445 // We're now ready to serve the initial policy; notify the policy observers. |
441 OnPolicyUpdated(initial_policy.Pass()); | 446 OnPolicyUpdated(initial_policy.Pass()); |
442 | 447 |
443 // Start observing the core and tracking the state of the client. | 448 // Start observing the core and tracking the state of the client. |
444 core_->AddObserver(this); | 449 core_->AddObserver(this); |
445 | 450 |
446 if (core_->client()) { | 451 if (core_->client()) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 } | 497 } |
493 | 498 |
494 void ComponentCloudPolicyService::OnPolicyUpdated( | 499 void ComponentCloudPolicyService::OnPolicyUpdated( |
495 scoped_ptr<PolicyBundle> policy) { | 500 scoped_ptr<PolicyBundle> policy) { |
496 DCHECK(CalledOnValidThread()); | 501 DCHECK(CalledOnValidThread()); |
497 policy_.Swap(policy.get()); | 502 policy_.Swap(policy.get()); |
498 delegate_->OnComponentCloudPolicyUpdated(); | 503 delegate_->OnComponentCloudPolicyUpdated(); |
499 } | 504 } |
500 | 505 |
501 } // namespace policy | 506 } // namespace policy |
OLD | NEW |