Chromium Code Reviews| 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::UpdateHeader(const std::string& new_header) { | |
| 47 // Post a task to the IO thread to modify this. | |
| 48 task_runner_->PostTask( | |
| 49 FROM_HERE, | |
| 50 base::Bind(&PolicyHeaderIOHelper::UpdateHeaderOnTaskRunner, | |
|
willchan no longer on Chromium
2013/12/10 23:32:14
Suggestions:
s/task_runner_/io_task_runner_/
s/Upd
Andrew T Wilson (Slow)
2013/12/10 23:53:06
Done. This was my original intent, but I got pushb
| |
| 51 weak_factory_.GetWeakPtr(), new_header)); | |
| 52 } | |
| 53 | |
| 54 void PolicyHeaderIOHelper::UpdateHeaderOnTaskRunner( | |
| 55 const std::string& new_header) { | |
| 56 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | |
| 57 policy_header_ = new_header; | |
| 58 } | |
| 59 | |
| 60 } // namespace policy | |
| OLD | NEW |