OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 #include "headless/public/util/in_memory_protocol_handler.h" |
| 6 |
| 7 #include "headless/public/util/in_memory_request_job.h" |
| 8 |
| 9 namespace headless { |
| 10 |
| 11 InMemoryProtocolHandler::InMemoryProtocolHandler() {} |
| 12 InMemoryProtocolHandler::~InMemoryProtocolHandler() {} |
| 13 |
| 14 net::URLRequestJob* InMemoryProtocolHandler::MaybeCreateJob( |
| 15 net::URLRequest* request, |
| 16 net::NetworkDelegate* network_delegate) const { |
| 17 return new InMemoryRequestJob(request, network_delegate, |
| 18 GetResponse(request->url().GetContent())); |
| 19 } |
| 20 |
| 21 void InMemoryProtocolHandler::InsertResponse(const std::string& request_path, |
| 22 const Response& response) { |
| 23 // GURL::GetContent excludes the scheme and : but includes the // prefix. As a |
| 24 // convenience we add it here. |
| 25 response_map_["//" + request_path] = response; |
| 26 } |
| 27 |
| 28 const InMemoryProtocolHandler::Response* InMemoryProtocolHandler::GetResponse( |
| 29 const std::string& request_path) const { |
| 30 std::map<std::string, Response>::const_iterator find_it = |
| 31 response_map_.find(request_path); |
| 32 if (find_it == response_map_.end()) |
| 33 return nullptr; |
| 34 return &find_it->second; |
| 35 } |
| 36 |
| 37 } // namespace headless |
OLD | NEW |