| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/policy/cloud/policy_header_service.h" |
| 6 |
| 7 #include "components/policy/core/browser/policy_header_io_helper.h" |
| 8 #include "components/policy/core/common/cloud/cloud_policy_store.h" |
| 9 |
| 10 namespace policy { |
| 11 |
| 12 PolicyHeaderService::PolicyHeaderService(const std::string& server_url, |
| 13 CloudPolicyStore* user_policy_store, |
| 14 CloudPolicyStore* device_policy_store) |
| 15 : server_url_(server_url), |
| 16 user_policy_store_(user_policy_store), |
| 17 device_policy_store_(device_policy_store) { |
| 18 user_policy_store_->AddObserver(this); |
| 19 if (device_policy_store_) |
| 20 device_policy_store_->AddObserver(this); |
| 21 } |
| 22 |
| 23 PolicyHeaderService::~PolicyHeaderService() { |
| 24 user_policy_store_->RemoveObserver(this); |
| 25 if (device_policy_store_) |
| 26 device_policy_store_->RemoveObserver(this); |
| 27 } |
| 28 |
| 29 scoped_ptr<PolicyHeaderIOHelper> |
| 30 PolicyHeaderService::CreatePolicyHeaderIOHelper( |
| 31 scoped_refptr<base::SequencedTaskRunner> task_runner) { |
| 32 std::string initial_header_value = CreateHeaderValue(); |
| 33 scoped_ptr<PolicyHeaderIOHelper> helper = make_scoped_ptr( |
| 34 new PolicyHeaderIOHelper(server_url_, initial_header_value, task_runner)); |
| 35 helpers_.push_back(helper.get()); |
| 36 return helper.Pass(); |
| 37 } |
| 38 |
| 39 std::string PolicyHeaderService::CreateHeaderValue() { |
| 40 // TODO(atwilson): Extract policy information and generate correct header. |
| 41 return ""; |
| 42 } |
| 43 |
| 44 void PolicyHeaderService::OnStoreLoaded(CloudPolicyStore* store) { |
| 45 // If we have a PolicyHeaderIOHelper, notify it of the new header value. |
| 46 if (!helpers_.empty()) { |
| 47 std::string new_header = CreateHeaderValue(); |
| 48 for (std::vector<PolicyHeaderIOHelper*>::const_iterator it = |
| 49 helpers_.begin(); it != helpers_.end(); ++it) { |
| 50 (*it)->UpdateHeader(new_header); |
| 51 } |
| 52 } |
| 53 } |
| 54 |
| 55 void PolicyHeaderService::OnStoreError(CloudPolicyStore* store) { |
| 56 // Do nothing on errors. |
| 57 } |
| 58 |
| 59 } // namespace policy |
| OLD | NEW |