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

Unified Diff: components/policy/core/browser/policy_header_io_helper.h

Issue 99433004: Add a header when fetching pages under the DMServer URL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added unit tests and fixed up from weekend component refactoring. 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 side-by-side diff with in-line comments
Download patch
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..12a5daad371545d82108860d36bfc4d7044b1e16
--- /dev/null
+++ b/components/policy/core/browser/policy_header_io_helper.h
@@ -0,0 +1,61 @@
+// 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);
+ ~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. Should only be called on the UI
+ // thread. If |new_header| is the empty string, no header will be added to
+ // outgoing requests.
+ void UpdateHeaderFromUI(const std::string& new_header);
+
+ private:
+ // API invoked on the I/O thread to update the header.
+ void UpdateHeaderOnIO(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_

Powered by Google App Engine
This is Rietveld 408576698