| 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 "components/policy/core/browser/policy_header_io_helper.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/location.h" |
| 9 #include "base/sequenced_task_runner.h" |
| 10 #include "net/url_request/url_request.h" |
| 11 |
| 12 namespace { |
| 13 |
| 14 // The name of the header containing the policy information. |
| 15 const char kChromePolicyHeader[] = "Chrome-Policy-Posture"; |
| 16 |
| 17 } // namespace |
| 18 |
| 19 namespace policy { |
| 20 |
| 21 PolicyHeaderIOHelper::PolicyHeaderIOHelper( |
| 22 const std::string& server_url, |
| 23 const std::string& initial_header_value, |
| 24 const scoped_refptr<base::SequencedTaskRunner>& task_runner) |
| 25 : server_url_(server_url), |
| 26 io_task_runner_(task_runner), |
| 27 policy_header_(initial_header_value) { |
| 28 } |
| 29 |
| 30 PolicyHeaderIOHelper::~PolicyHeaderIOHelper() { |
| 31 } |
| 32 |
| 33 // Sets any necessary policy headers on the passed request. |
| 34 void PolicyHeaderIOHelper::AddPolicyHeaders(net::URLRequest* request) const { |
| 35 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 36 const GURL& url = request->url(); |
| 37 if (!policy_header_.empty() && |
| 38 url.spec().compare(0, server_url_.size(), server_url_) == 0) { |
| 39 request->SetExtraRequestHeaderByName(kChromePolicyHeader, |
| 40 policy_header_, |
| 41 true /* overwrite */); |
| 42 } |
| 43 } |
| 44 |
| 45 void PolicyHeaderIOHelper::UpdateHeader(const std::string& new_header) { |
| 46 // Post a task to the IO thread to modify this. |
| 47 io_task_runner_->PostTask( |
| 48 FROM_HERE, |
| 49 base::Bind(&PolicyHeaderIOHelper::UpdateHeaderOnIOThread, |
| 50 base::Unretained(this), new_header)); |
| 51 } |
| 52 |
| 53 void PolicyHeaderIOHelper::UpdateHeaderOnIOThread( |
| 54 const std::string& new_header) { |
| 55 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 56 policy_header_ = new_header; |
| 57 } |
| 58 |
| 59 } // namespace policy |
| OLD | NEW |