Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: components/policy/core/browser/policy_header_io_helper.cc

Issue 99433004: Add a header when fetching pages under the DMServer URL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Whitespace fix. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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) {
Joao da Silva 2013/12/09 14:46:21 I guess this works for our purposes. I wonder if t
Andrew T Wilson (Slow) 2013/12/10 07:15:56 I don't think we care - I'm OK with requiring spec
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698