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 #ifndef COMPONENTS_POLICY_CORE_BROWSER_POLICY_HEADER_IO_HELPER_H_ | |
| 6 #define COMPONENTS_POLICY_CORE_BROWSER_POLICY_HEADER_IO_HELPER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/sequenced_task_runner.h" | |
| 13 #include "components/policy/policy_export.h" | |
| 14 | |
| 15 namespace net { | |
| 16 class URLRequest; | |
| 17 } | |
| 18 | |
| 19 namespace policy { | |
| 20 | |
| 21 // Helper class that lives on the I/O thread and adds policy headers to | |
| 22 // outgoing requests. Instances of this class are created by | |
| 23 // PolicyHeaderService on the UI thread, and that class is responsible for | |
| 24 // notifying this class via UpdateHeaderFromUI() when the header changes. | |
| 25 // Ownership is transferred to ProfileIOData, and this object is run and | |
| 26 // destroyed on the I/O thread. | |
| 27 class POLICY_EXPORT PolicyHeaderIOHelper { | |
| 28 public: | |
| 29 PolicyHeaderIOHelper(const std::string& server_url, | |
| 30 const std::string& initial_header_value, | |
| 31 scoped_refptr<base::SequencedTaskRunner> task_runner); | |
|
willchan no longer on Chromium
2013/12/10 23:27:09
const reference to eliminate the extra copy for th
Andrew T Wilson (Slow)
2013/12/10 23:53:06
OK, I didn't think the cost of creating the scoped
willchan no longer on Chromium
2013/12/10 23:55:20
Just one of those death by a thousand cut things.
| |
| 32 ~PolicyHeaderIOHelper(); | |
| 33 | |
| 34 // Sets any necessary policy headers on the passed request. Should be invoked | |
| 35 // only from the I/O thread. | |
| 36 void AddPolicyHeaders(net::URLRequest* request) const; | |
| 37 | |
| 38 // API invoked when the header changes. Can be called from any thread - calls | |
| 39 // are marshalled via the TaskRunner to run on the appropriate thread. | |
| 40 // If |new_header| is the empty string, no header will be added to | |
| 41 // outgoing requests. | |
| 42 void UpdateHeader(const std::string& new_header); | |
| 43 | |
| 44 private: | |
| 45 // API invoked via the TaskRunner to update the header. | |
| 46 void UpdateHeaderOnTaskRunner(const std::string& new_header); | |
| 47 | |
| 48 // The URL we should add policy headers to. | |
| 49 std::string server_url_; | |
| 50 | |
| 51 // The task runner assocated with the thread that runs this object. | |
| 52 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
| 53 | |
| 54 // The current policy header value. | |
| 55 std::string policy_header_; | |
| 56 | |
| 57 base::WeakPtrFactory<PolicyHeaderIOHelper> weak_factory_; | |
| 58 DISALLOW_COPY_AND_ASSIGN(PolicyHeaderIOHelper); | |
| 59 }; | |
| 60 | |
| 61 } // namespace policy | |
| 62 | |
| 63 #endif // COMPONENTS_POLICY_CORE_BROWSER_POLICY_HEADER_IO_HELPER_H_ | |
| OLD | NEW |