Index: headless/public/util/in_memory_protocol_handler.h |
diff --git a/headless/public/util/in_memory_protocol_handler.h b/headless/public/util/in_memory_protocol_handler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1d69d46a9b24d47e99799d8ecb3e9ff63944adf2 |
--- /dev/null |
+++ b/headless/public/util/in_memory_protocol_handler.h |
@@ -0,0 +1,46 @@ |
+// Copyright 2016 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 HEADLESS_PUBLIC_UTIL_IN_MEMORY_PROTOCOL_HANDLER_H_ |
+#define HEADLESS_PUBLIC_UTIL_IN_MEMORY_PROTOCOL_HANDLER_H_ |
+ |
+#include <map> |
+ |
+#include "net/url_request/url_request_job_factory.h" |
+ |
+namespace headless { |
+ |
+class InMemoryProtocolHandler |
+ : public net::URLRequestJobFactory::ProtocolHandler { |
+ public: |
+ InMemoryProtocolHandler(); |
+ ~InMemoryProtocolHandler() override; |
+ |
+ net::URLRequestJob* MaybeCreateJob( |
+ net::URLRequest* request, |
+ net::NetworkDelegate* network_delegate) const override; |
+ |
+ struct Response { |
+ Response() {} |
+ Response(const std::string& data, const std::string& mime_type) |
+ : data(data), mime_type(mime_type) {} |
+ |
+ std::string data; |
+ std::string mime_type; |
+ }; |
+ |
+ void InsertResponse(const std::string& request_path, |
+ const Response& response); |
+ |
+ private: |
+ const Response* GetResponse(const std::string& request_path) const; |
+ |
+ std::map<std::string, Response> response_map_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(InMemoryProtocolHandler); |
+}; |
+ |
+} // namespace headless |
+ |
+#endif // HEADLESS_PUBLIC_UTIL_IN_MEMORY_PROTOCOL_HANDLER_H_ |