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

Side by Side Diff: chrome/browser/devtools/devtools_protocol.cc

Issue 22685003: Visualize status of port forwarding sockets in chrome:inspect Devices tab (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chrome/browser/devtools/devtools_protocol.h" 5 #include "chrome/browser/devtools/devtools_protocol.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 9
10 #include "base/logging.h"
11
10 namespace { 12 namespace {
11 const char kIdParam[] = "id"; 13 const char kIdParam[] = "id";
12 const char kMethodParam[] = "method"; 14 const char kMethodParam[] = "method";
13 const char kParamsParam[] = "params"; 15 const char kParamsParam[] = "params";
16 const char kErrorParam[] = "error";
17 const char kErrorCodeParam[] = "code";
14 } // namespace 18 } // namespace
15 19
16 DevToolsProtocol::Message::~Message() { 20 DevToolsProtocol::Message::~Message() {
17 } 21 }
18 22
19 DevToolsProtocol::Message::Message(const std::string& method, 23 DevToolsProtocol::Message::Message(const std::string& method,
20 base::DictionaryValue* params) 24 base::DictionaryValue* params)
21 : method_(method), 25 : method_(method),
22 params_(params ? params->DeepCopy() : NULL) { 26 params_(params ? params->DeepCopy() : NULL) {
23 } 27 }
(...skipping 21 matching lines...) Expand all
45 } 49 }
46 50
47 DevToolsProtocol::Notification::~Notification() { 51 DevToolsProtocol::Notification::~Notification() {
48 } 52 }
49 53
50 DevToolsProtocol::Notification::Notification(const std::string& method, 54 DevToolsProtocol::Notification::Notification(const std::string& method,
51 base::DictionaryValue* params) 55 base::DictionaryValue* params)
52 : Message(method, params) { 56 : Message(method, params) {
53 } 57 }
54 58
59 DevToolsProtocol::Response::~Response() {
60 }
61
62 DevToolsProtocol::Response::Response(int id, int error_code)
63 : id_(id),
64 error_code_(error_code) {
65 }
66
55 // static 67 // static
56 DevToolsProtocol::Notification* DevToolsProtocol::ParseNotification( 68 DevToolsProtocol::Notification* DevToolsProtocol::ParseNotification(
57 const std::string& json) { 69 const std::string& json) {
58 scoped_ptr<base::Value> value(base::JSONReader::Read(json)); 70 scoped_ptr<base::Value> value(base::JSONReader::Read(json));
59 if (!value || !value->IsType(Value::TYPE_DICTIONARY)) 71 if (!value || !value->IsType(Value::TYPE_DICTIONARY))
60 return NULL; 72 return NULL;
61 73
62 scoped_ptr<base::DictionaryValue> dict( 74 scoped_ptr<base::DictionaryValue> dict(
63 static_cast<base::DictionaryValue*>(value.release())); 75 static_cast<base::DictionaryValue*>(value.release()));
64 76
65 std::string method; 77 std::string method;
66 if (!dict->GetString(kMethodParam, &method)) 78 if (!dict->GetString(kMethodParam, &method))
67 return NULL; 79 return NULL;
68 80
69 base::DictionaryValue* params = NULL; 81 base::DictionaryValue* params = NULL;
70 dict->GetDictionary(kParamsParam, &params); 82 dict->GetDictionary(kParamsParam, &params);
71 return new Notification(method, params); 83 return new Notification(method, params);
72 } 84 }
85
86 DevToolsProtocol::Response* DevToolsProtocol::ParseResponse(
87 const std::string& json) {
88 scoped_ptr<base::Value> value(base::JSONReader::Read(json));
89 if (!value || !value->IsType(Value::TYPE_DICTIONARY))
90 return NULL;
91
92 scoped_ptr<base::DictionaryValue> dict(
93 static_cast<base::DictionaryValue*>(value.release()));
94
95 int id;
96 if (!dict->GetInteger(kIdParam, &id))
97 return NULL;
98
99 int error_code = 0;
100 base::DictionaryValue* error_dict = NULL;
101 if (dict->GetDictionary(kErrorParam, &error_dict))
102 error_dict->GetInteger(kErrorCodeParam, &error_code);
103 return new Response(id, error_code);
104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698