OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/ftp/ftp_ctrl_response_buffer.h" | 5 #include "net/ftp/ftp_ctrl_response_buffer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 line_buf_.clear(); | 72 line_buf_.clear(); |
73 } | 73 } |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 return OK; | 77 return OK; |
78 } | 78 } |
79 | 79 |
80 namespace { | 80 namespace { |
81 | 81 |
82 base::Value* NetLogFtpCtrlResponseCallback(const FtpCtrlResponse* response, | 82 scoped_ptr<base::Value> NetLogFtpCtrlResponseCallback( |
83 NetLogCaptureMode capture_mode) { | 83 const FtpCtrlResponse* response, |
84 base::ListValue* lines = new base::ListValue(); | 84 NetLogCaptureMode capture_mode) { |
| 85 scoped_ptr<base::ListValue> lines(new base::ListValue()); |
85 lines->AppendStrings(response->lines); | 86 lines->AppendStrings(response->lines); |
86 | 87 |
87 base::DictionaryValue* dict = new base::DictionaryValue(); | 88 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
88 dict->SetInteger("status_code", response->status_code); | 89 dict->SetInteger("status_code", response->status_code); |
89 dict->Set("lines", lines); | 90 dict->Set("lines", lines.Pass()); |
90 return dict; | 91 return dict.Pass(); |
91 } | 92 } |
92 | 93 |
93 } // namespace | 94 } // namespace |
94 | 95 |
95 FtpCtrlResponse FtpCtrlResponseBuffer::PopResponse() { | 96 FtpCtrlResponse FtpCtrlResponseBuffer::PopResponse() { |
96 FtpCtrlResponse result = responses_.front(); | 97 FtpCtrlResponse result = responses_.front(); |
97 responses_.pop(); | 98 responses_.pop(); |
98 | 99 |
99 net_log_.AddEvent(NetLog::TYPE_FTP_CONTROL_RESPONSE, | 100 net_log_.AddEvent(NetLog::TYPE_FTP_CONTROL_RESPONSE, |
100 base::Bind(&NetLogFtpCtrlResponseCallback, &result)); | 101 base::Bind(NetLogFtpCtrlResponseCallback, &result)); |
101 | 102 |
102 return result; | 103 return result; |
103 } | 104 } |
104 | 105 |
105 FtpCtrlResponseBuffer::ParsedLine::ParsedLine() | 106 FtpCtrlResponseBuffer::ParsedLine::ParsedLine() |
106 : has_status_code(false), | 107 : has_status_code(false), |
107 is_multiline(false), | 108 is_multiline(false), |
108 is_complete(false), | 109 is_complete(false), |
109 status_code(FtpCtrlResponse::kInvalidStatusCode) { | 110 status_code(FtpCtrlResponse::kInvalidStatusCode) { |
110 } | 111 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 for (size_t i = 0; i < buffer_.length(); i++) { | 144 for (size_t i = 0; i < buffer_.length(); i++) { |
144 if (i >= 1 && buffer_[i - 1] == '\r' && buffer_[i] == '\n') { | 145 if (i >= 1 && buffer_[i - 1] == '\r' && buffer_[i] == '\n') { |
145 lines_.push(ParseLine(buffer_.substr(cut_pos, i - cut_pos - 1))); | 146 lines_.push(ParseLine(buffer_.substr(cut_pos, i - cut_pos - 1))); |
146 cut_pos = i + 1; | 147 cut_pos = i + 1; |
147 } | 148 } |
148 } | 149 } |
149 buffer_.erase(0, cut_pos); | 150 buffer_.erase(0, cut_pos); |
150 } | 151 } |
151 | 152 |
152 } // namespace net | 153 } // namespace net |
OLD | NEW |