Chromium Code Reviews| Index: components/policy/core/browser/policy_header_io_helper.h |
| diff --git a/components/policy/core/browser/policy_header_io_helper.h b/components/policy/core/browser/policy_header_io_helper.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fa1f7b145dee0b6d1c84aa055404865674cce3f0 |
| --- /dev/null |
| +++ b/components/policy/core/browser/policy_header_io_helper.h |
| @@ -0,0 +1,63 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_POLICY_CORE_BROWSER_POLICY_HEADER_IO_HELPER_H_ |
| +#define COMPONENTS_POLICY_CORE_BROWSER_POLICY_HEADER_IO_HELPER_H_ |
| + |
| +#include <string> |
| + |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/sequenced_task_runner.h" |
| +#include "components/policy/policy_export.h" |
| + |
| +namespace net { |
| +class URLRequest; |
| +} |
| + |
| +namespace policy { |
| + |
| +// Helper class that lives on the I/O thread and adds policy headers to |
| +// outgoing requests. Instances of this class are created by |
| +// PolicyHeaderService on the UI thread, and that class is responsible for |
| +// notifying this class via UpdateHeaderFromUI() when the header changes. |
| +// Ownership is transferred to ProfileIOData, and this object is run and |
| +// destroyed on the I/O thread. |
| +class POLICY_EXPORT PolicyHeaderIOHelper { |
| + public: |
| + PolicyHeaderIOHelper(const std::string& server_url, |
| + const std::string& initial_header_value, |
| + 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.
|
| + ~PolicyHeaderIOHelper(); |
| + |
| + // Sets any necessary policy headers on the passed request. Should be invoked |
| + // only from the I/O thread. |
| + void AddPolicyHeaders(net::URLRequest* request) const; |
| + |
| + // API invoked when the header changes. Can be called from any thread - calls |
| + // are marshalled via the TaskRunner to run on the appropriate thread. |
| + // If |new_header| is the empty string, no header will be added to |
| + // outgoing requests. |
| + void UpdateHeader(const std::string& new_header); |
| + |
| + private: |
| + // API invoked via the TaskRunner to update the header. |
| + void UpdateHeaderOnTaskRunner(const std::string& new_header); |
| + |
| + // The URL we should add policy headers to. |
| + std::string server_url_; |
| + |
| + // The task runner assocated with the thread that runs this object. |
| + scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| + |
| + // The current policy header value. |
| + std::string policy_header_; |
| + |
| + base::WeakPtrFactory<PolicyHeaderIOHelper> weak_factory_; |
| + DISALLOW_COPY_AND_ASSIGN(PolicyHeaderIOHelper); |
| +}; |
| + |
| +} // namespace policy |
| + |
| +#endif // COMPONENTS_POLICY_CORE_BROWSER_POLICY_HEADER_IO_HELPER_H_ |