OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/policy/core/common/cloud/policy_header_io_helper.h" | 5 #include "components/policy/core/common/cloud/policy_header_io_helper.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/sequenced_task_runner.h" | 9 #include "base/sequenced_task_runner.h" |
10 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 10 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
11 #include "net/url_request/url_request.h" | 11 #include "net/url_request/url_request.h" |
12 | 12 |
13 namespace policy { | 13 namespace policy { |
14 | 14 |
15 PolicyHeaderIOHelper::PolicyHeaderIOHelper( | 15 PolicyHeaderIOHelper::PolicyHeaderIOHelper( |
16 const std::string& server_url, | 16 const std::string& server_url, |
17 const std::string& initial_header_value, | 17 const std::string& initial_header_value, |
18 const scoped_refptr<base::SequencedTaskRunner>& task_runner) | 18 const scoped_refptr<base::SequencedTaskRunner>& task_runner) |
19 : server_url_(server_url), | 19 : server_url_(server_url), |
20 io_task_runner_(task_runner), | 20 io_task_runner_(task_runner), |
21 policy_header_(initial_header_value) { | 21 policy_header_(initial_header_value) { |
22 } | 22 } |
23 | 23 |
24 PolicyHeaderIOHelper::~PolicyHeaderIOHelper() { | 24 PolicyHeaderIOHelper::~PolicyHeaderIOHelper() { |
25 } | 25 } |
26 | 26 |
27 // Sets any necessary policy headers on the passed request. | 27 // Sets any necessary policy headers on the passed request. |
28 void PolicyHeaderIOHelper::AddPolicyHeaders(const GURL& url, | 28 void PolicyHeaderIOHelper::AddPolicyHeaders(const GURL& url, |
29 net::URLRequest* request) const { | 29 net::URLRequest* request) const { |
30 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 30 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
31 if (!policy_header_.empty() && | 31 if (!policy_header_.empty() && |
32 url.spec().compare(0, server_url_.size(), server_url_) == 0) { | 32 url.spec().compare(0, server_url_.size(), server_url_) == 0) { |
33 request->SetExtraRequestHeaderByName(kChromePolicyHeader, | 33 request->SetExtraRequestHeaderByName(kChromePolicyHeader, |
34 policy_header_, | 34 policy_header_, |
35 true /* overwrite */); | 35 true /* overwrite */); |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 void PolicyHeaderIOHelper::UpdateHeader(const std::string& new_header) { | 39 void PolicyHeaderIOHelper::UpdateHeader(const std::string& new_header) { |
40 // Post a task to the IO thread to modify this. | 40 // Post a task to the IO thread to modify this. |
41 io_task_runner_->PostTask( | 41 io_task_runner_->PostTask( |
42 FROM_HERE, | 42 FROM_HERE, |
43 base::Bind(&PolicyHeaderIOHelper::UpdateHeaderOnIOThread, | 43 base::Bind(&PolicyHeaderIOHelper::UpdateHeaderOnIOThread, |
44 base::Unretained(this), new_header)); | 44 base::Unretained(this), new_header)); |
45 } | 45 } |
46 | 46 |
47 void PolicyHeaderIOHelper::UpdateHeaderOnIOThread( | 47 void PolicyHeaderIOHelper::UpdateHeaderOnIOThread( |
48 const std::string& new_header) { | 48 const std::string& new_header) { |
49 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 49 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
50 policy_header_ = new_header; | 50 policy_header_ = new_header; |
51 } | 51 } |
52 | 52 |
53 void PolicyHeaderIOHelper::SetServerURLForTest(const std::string& server_url) { | 53 void PolicyHeaderIOHelper::SetServerURLForTest(const std::string& server_url) { |
54 io_task_runner_->PostTask( | 54 io_task_runner_->PostTask( |
55 FROM_HERE, | 55 FROM_HERE, |
56 base::Bind(&PolicyHeaderIOHelper::SetServerURLOnIOThread, | 56 base::Bind(&PolicyHeaderIOHelper::SetServerURLOnIOThread, |
57 base::Unretained(this), server_url)); | 57 base::Unretained(this), server_url)); |
58 } | 58 } |
59 | 59 |
60 void PolicyHeaderIOHelper::SetServerURLOnIOThread( | 60 void PolicyHeaderIOHelper::SetServerURLOnIOThread( |
61 const std::string& server_url) { | 61 const std::string& server_url) { |
62 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 62 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
63 server_url_ = server_url; | 63 server_url_ = server_url; |
64 } | 64 } |
65 | 65 |
66 } // namespace policy | 66 } // namespace policy |
OLD | NEW |