| 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/policy/cloud_policy_manager.h" | 5 #include "chrome/browser/policy/cloud_policy_manager.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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/browser/policy/cloud_policy_refresh_scheduler.h" | 10 #include "chrome/browser/policy/cloud_policy_refresh_scheduler.h" |
| 11 #include "chrome/browser/policy/cloud_policy_service.h" | 11 #include "chrome/browser/policy/cloud_policy_service.h" |
| 12 #include "chrome/browser/policy/policy_bundle.h" | 12 #include "chrome/browser/policy/policy_bundle.h" |
| 13 #include "chrome/browser/policy/policy_map.h" | 13 #include "chrome/browser/policy/policy_map.h" |
| 14 | 14 |
| 15 namespace policy { | 15 namespace policy { |
| 16 | 16 |
| 17 CloudPolicyManager::CloudPolicyManager(scoped_ptr<CloudPolicyStore> store) | 17 CloudPolicyManager::CloudPolicyManager(CloudPolicyStore* store) |
| 18 : store_(store.Pass()), | 18 : store_(store), |
| 19 waiting_for_policy_refresh_(false) { | 19 waiting_for_policy_refresh_(false) { |
| 20 store_->AddObserver(this); | 20 store_->AddObserver(this); |
| 21 | 21 |
| 22 // If the underlying store is already initialized, publish the loaded | 22 // If the underlying store is already initialized, publish the loaded |
| 23 // policy. Otherwise, request a load now. | 23 // policy. Otherwise, request a load now. |
| 24 if (store_->is_initialized()) | 24 if (store_->is_initialized()) |
| 25 CheckAndPublishPolicy(); | 25 CheckAndPublishPolicy(); |
| 26 else | 26 else |
| 27 store_->Load(); | 27 store_->Load(); |
| 28 } | 28 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 44 waiting_for_policy_refresh_ = true; | 44 waiting_for_policy_refresh_ = true; |
| 45 service_->RefreshPolicy( | 45 service_->RefreshPolicy( |
| 46 base::Bind(&CloudPolicyManager::OnRefreshComplete, | 46 base::Bind(&CloudPolicyManager::OnRefreshComplete, |
| 47 base::Unretained(this))); | 47 base::Unretained(this))); |
| 48 } else { | 48 } else { |
| 49 OnRefreshComplete(); | 49 OnRefreshComplete(); |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 void CloudPolicyManager::OnStoreLoaded(CloudPolicyStore* store) { | 53 void CloudPolicyManager::OnStoreLoaded(CloudPolicyStore* store) { |
| 54 DCHECK_EQ(store_.get(), store); | 54 DCHECK_EQ(store_, store); |
| 55 CheckAndPublishPolicy(); | 55 CheckAndPublishPolicy(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void CloudPolicyManager::OnStoreError(CloudPolicyStore* store) { | 58 void CloudPolicyManager::OnStoreError(CloudPolicyStore* store) { |
| 59 DCHECK_EQ(store_.get(), store); | 59 DCHECK_EQ(store_, store); |
| 60 // No action required, the old policy is still valid. | 60 // No action required, the old policy is still valid. |
| 61 } | 61 } |
| 62 | 62 |
| 63 void CloudPolicyManager::InitializeService( | 63 void CloudPolicyManager::InitializeService( |
| 64 scoped_ptr<CloudPolicyClient> client) { | 64 scoped_ptr<CloudPolicyClient> client) { |
| 65 CHECK(!client_.get()); | 65 CHECK(!client_.get()); |
| 66 CHECK(client.get()); | 66 CHECK(client.get()); |
| 67 client_ = client.Pass(); | 67 client_ = client.Pass(); |
| 68 service_.reset(new CloudPolicyService(client_.get(), store_.get())); | 68 service_.reset(new CloudPolicyService(client_.get(), store_)); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void CloudPolicyManager::ShutdownService() { | 71 void CloudPolicyManager::ShutdownService() { |
| 72 refresh_scheduler_.reset(); | 72 refresh_scheduler_.reset(); |
| 73 service_.reset(); | 73 service_.reset(); |
| 74 client_.reset(); | 74 client_.reset(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void CloudPolicyManager::StartRefreshScheduler( | 77 void CloudPolicyManager::StartRefreshScheduler( |
| 78 PrefService* local_state, | 78 PrefService* local_state, |
| 79 const std::string& refresh_rate_pref) { | 79 const std::string& refresh_rate_pref) { |
| 80 if (!refresh_scheduler_.get()) { | 80 if (!refresh_scheduler_.get()) { |
| 81 refresh_scheduler_.reset( | 81 refresh_scheduler_.reset( |
| 82 new CloudPolicyRefreshScheduler( | 82 new CloudPolicyRefreshScheduler( |
| 83 client_.get(), store_.get(), local_state, refresh_rate_pref, | 83 client_.get(), store_, local_state, refresh_rate_pref, |
| 84 MessageLoop::current()->message_loop_proxy())); | 84 MessageLoop::current()->message_loop_proxy())); |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 | 87 |
| 88 void CloudPolicyManager::CheckAndPublishPolicy() { | 88 void CloudPolicyManager::CheckAndPublishPolicy() { |
| 89 if (IsInitializationComplete() && !waiting_for_policy_refresh_) { | 89 if (IsInitializationComplete() && !waiting_for_policy_refresh_) { |
| 90 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); | 90 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); |
| 91 bundle->Get(POLICY_DOMAIN_CHROME, std::string()).CopyFrom( | 91 bundle->Get(POLICY_DOMAIN_CHROME, std::string()).CopyFrom( |
| 92 store_->policy_map()); | 92 store_->policy_map()); |
| 93 UpdatePolicy(bundle.Pass()); | 93 UpdatePolicy(bundle.Pass()); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 void CloudPolicyManager::OnRefreshComplete() { | 97 void CloudPolicyManager::OnRefreshComplete() { |
| 98 waiting_for_policy_refresh_ = false; | 98 waiting_for_policy_refresh_ = false; |
| 99 CheckAndPublishPolicy(); | 99 CheckAndPublishPolicy(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 } // namespace policy | 102 } // namespace policy |
| OLD | NEW |