OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 "chrome/browser/google_apis/test_server/http_connection.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/basictypes.h" | |
10 #include "chrome/browser/google_apis/test_server/http_request.h" | |
11 #include "chrome/browser/google_apis/test_server/http_response.h" | |
12 | |
13 namespace drive { | |
14 namespace test_server { | |
15 | |
16 HttpConnection::HttpConnection(net::StreamListenSocket* socket, | |
17 const HandleRequestCallback& callback) | |
18 : socket_(socket), | |
19 callback_(callback) { | |
20 } | |
21 | |
22 HttpConnection::~HttpConnection() { | |
23 } | |
24 | |
25 void HttpConnection::SendResponse(scoped_ptr<HttpResponse> response) const { | |
26 const std::string response_string = response->ToResponseString(); | |
27 socket_->Send(response_string.c_str(), response_string.length()); | |
28 } | |
29 | |
30 void HttpConnection::ReceiveData(const base::StringPiece& data) { | |
31 request_parser_.ProcessChunk(data); | |
32 if (request_parser_.ParseRequest() == HttpRequestParser::ACCEPTED) { | |
33 callback_.Run(this, request_parser_.GetRequest().Pass()); | |
34 } | |
35 } | |
36 | |
37 } // namespace test_server | |
38 } // namespace drive | |
OLD | NEW |