| 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 scoped_refptr<base::SequencedTaskRunner> task_runner) |
| 25 : server_url_(server_url), |
| 26 task_runner_(task_runner), |
| 27 policy_header_(initial_header_value), |
| 28 weak_factory_(this) { |
| 29 } |
| 30 |
| 31 PolicyHeaderIOHelper::~PolicyHeaderIOHelper() { |
| 32 } |
| 33 |
| 34 // Sets any necessary policy headers on the passed request. |
| 35 void PolicyHeaderIOHelper::AddPolicyHeaders(net::URLRequest* request) const { |
| 36 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 37 const GURL& url = request->url(); |
| 38 if (!policy_header_.empty() && |
| 39 url.spec().compare(0, server_url_.size(), server_url_) == 0) { |
| 40 request->SetExtraRequestHeaderByName(kChromePolicyHeader, |
| 41 policy_header_, |
| 42 true /* overwrite */); |
| 43 } |
| 44 } |
| 45 |
| 46 void PolicyHeaderIOHelper::UpdateHeaderFromUI(const std::string& new_header) { |
| 47 // Post a task to the IO thread to modify this. |
| 48 task_runner_->PostTask(FROM_HERE, |
| 49 base::Bind(&PolicyHeaderIOHelper::UpdateHeaderOnIO, |
| 50 weak_factory_.GetWeakPtr(), new_header)); |
| 51 } |
| 52 |
| 53 void PolicyHeaderIOHelper::UpdateHeaderOnIO(const std::string& new_header) { |
| 54 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 55 policy_header_ = new_header; |
| 56 } |
| 57 |
| 58 } // namespace policy |
| OLD | NEW |