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

Side by Side Diff: net/websockets/websocket_net_log_params.cc

Issue 10548028: NetLogEventParameter to Callback refactoring 8. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix bad paste Created 8 years, 6 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/websockets/websocket_net_log_params.h" 5 #include "net/websockets/websocket_net_log_params.h"
6 6
7 #include "base/stringprintf.h"
8 #include "base/values.h"
9
7 namespace net { 10 namespace net {
8 11
9 NetLogWebSocketHandshakeParameter::NetLogWebSocketHandshakeParameter( 12 Value* NetLogWebSocketHandshakeCallback(const std::string* headers,
10 const std::string& headers) 13 NetLog::LogLevel /* log_level */) {
11 : headers_(headers) {
12 }
13
14 Value* NetLogWebSocketHandshakeParameter::ToValue() const {
15 DictionaryValue* dict = new DictionaryValue(); 14 DictionaryValue* dict = new DictionaryValue();
16 ListValue* headers = new ListValue(); 15 ListValue* header_list = new ListValue();
17 16
18 size_t last = 0; 17 size_t last = 0;
19 size_t headers_size = headers_.size(); 18 size_t headers_size = headers->size();
20 size_t pos = 0; 19 size_t pos = 0;
21 while (pos <= headers_size) { 20 while (pos <= headers_size) {
22 if (pos == headers_size || 21 if (pos == headers_size ||
23 (headers_[pos] == '\r' && 22 ((*headers)[pos] == '\r' &&
24 pos + 1 < headers_size && headers_[pos + 1] == '\n')) { 23 pos + 1 < headers_size && (*headers)[pos + 1] == '\n')) {
25 std::string entry = headers_.substr(last, pos - last); 24 std::string entry = headers->substr(last, pos - last);
26 pos += 2; 25 pos += 2;
27 last = pos; 26 last = pos;
28 27
29 headers->Append(new StringValue(entry)); 28 header_list->Append(new StringValue(entry));
30 29
31 if (entry.empty()) { 30 if (entry.empty()) {
32 // Dump WebSocket key3. 31 // Dump WebSocket key3.
33 std::string key; 32 std::string key;
34 for (; pos < headers_size; ++pos) { 33 for (; pos < headers_size; ++pos) {
35 key += base::StringPrintf("\\x%02x", headers_[pos] & 0xff); 34 key += base::StringPrintf("\\x%02x", (*headers)[pos] & 0xff);
36 } 35 }
37 headers->Append(new StringValue(key)); 36 header_list->Append(new StringValue(key));
38 break; 37 break;
39 } 38 }
40 } else { 39 } else {
41 ++pos; 40 ++pos;
42 } 41 }
43 } 42 }
44 43
45 dict->Set("headers", headers); 44 dict->Set("headers", header_list);
46 return dict; 45 return dict;
47 } 46 }
48 47
49 NetLogWebSocketHandshakeParameter::~NetLogWebSocketHandshakeParameter() {}
50
51 } // namespace net 48 } // namespace net
OLDNEW
« no previous file with comments | « net/websockets/websocket_net_log_params.h ('k') | net/websockets/websocket_net_log_params_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698