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

Side by Side Diff: net/test/spawned_test_server/local_test_server.cc

Issue 2539363004: Make base::Value::TYPE a scoped enum. (Closed)
Patch Set: Rebase Created 4 years 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "net/test/spawned_test_server/local_test_server.h" 5 #include "net/test/spawned_test_server/local_test_server.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/threading/thread_restrictions.h" 12 #include "base/threading/thread_restrictions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "net/base/host_port_pair.h" 14 #include "net/base/host_port_pair.h"
15 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
16 #include "net/test/python_utils.h" 16 #include "net/test/python_utils.h"
17 #include "url/gurl.h" 17 #include "url/gurl.h"
18 18
19 namespace net { 19 namespace net {
20 20
21 namespace { 21 namespace {
22 22
23 bool AppendArgumentFromJSONValue(const std::string& key, 23 bool AppendArgumentFromJSONValue(const std::string& key,
24 const base::Value& value_node, 24 const base::Value& value_node,
25 base::CommandLine* command_line) { 25 base::CommandLine* command_line) {
26 std::string argument_name = "--" + key; 26 std::string argument_name = "--" + key;
27 switch (value_node.GetType()) { 27 switch (value_node.GetType()) {
28 case base::Value::TYPE_NULL: 28 case base::Value::Type::NONE:
29 command_line->AppendArg(argument_name); 29 command_line->AppendArg(argument_name);
30 break; 30 break;
31 case base::Value::TYPE_INTEGER: { 31 case base::Value::Type::INTEGER: {
32 int value; 32 int value;
33 bool result = value_node.GetAsInteger(&value); 33 bool result = value_node.GetAsInteger(&value);
34 DCHECK(result); 34 DCHECK(result);
35 command_line->AppendArg(argument_name + "=" + base::IntToString(value)); 35 command_line->AppendArg(argument_name + "=" + base::IntToString(value));
36 break; 36 break;
37 } 37 }
38 case base::Value::TYPE_STRING: { 38 case base::Value::Type::STRING: {
39 std::string value; 39 std::string value;
40 bool result = value_node.GetAsString(&value); 40 bool result = value_node.GetAsString(&value);
41 if (!result || value.empty()) 41 if (!result || value.empty())
42 return false; 42 return false;
43 command_line->AppendArg(argument_name + "=" + value); 43 command_line->AppendArg(argument_name + "=" + value);
44 break; 44 break;
45 } 45 }
46 case base::Value::TYPE_BOOLEAN: 46 case base::Value::Type::BOOLEAN:
47 case base::Value::TYPE_DOUBLE: 47 case base::Value::Type::DOUBLE:
48 case base::Value::TYPE_LIST: 48 case base::Value::Type::LIST:
49 case base::Value::TYPE_DICTIONARY: 49 case base::Value::Type::DICTIONARY:
50 case base::Value::TYPE_BINARY: 50 case base::Value::Type::BINARY:
51 default: 51 default:
52 NOTREACHED() << "improper json type"; 52 NOTREACHED() << "improper json type";
53 return false; 53 return false;
54 } 54 }
55 return true; 55 return true;
56 } 56 }
57 57
58 } // namespace 58 } // namespace
59 59
60 LocalTestServer::LocalTestServer(Type type, 60 LocalTestServer::LocalTestServer(Type type,
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 if (!GenerateArguments(&arguments_dict)) 200 if (!GenerateArguments(&arguments_dict))
201 return false; 201 return false;
202 202
203 // Serialize the argument dictionary into CommandLine. 203 // Serialize the argument dictionary into CommandLine.
204 for (base::DictionaryValue::Iterator it(arguments_dict); !it.IsAtEnd(); 204 for (base::DictionaryValue::Iterator it(arguments_dict); !it.IsAtEnd();
205 it.Advance()) { 205 it.Advance()) {
206 const base::Value& value = it.value(); 206 const base::Value& value = it.value();
207 const std::string& key = it.key(); 207 const std::string& key = it.key();
208 208
209 // Add arguments from a list. 209 // Add arguments from a list.
210 if (value.IsType(base::Value::TYPE_LIST)) { 210 if (value.IsType(base::Value::Type::LIST)) {
211 const base::ListValue* list = NULL; 211 const base::ListValue* list = NULL;
212 if (!value.GetAsList(&list) || !list || list->empty()) 212 if (!value.GetAsList(&list) || !list || list->empty())
213 return false; 213 return false;
214 for (base::ListValue::const_iterator list_it = list->begin(); 214 for (base::ListValue::const_iterator list_it = list->begin();
215 list_it != list->end(); ++list_it) { 215 list_it != list->end(); ++list_it) {
216 if (!AppendArgumentFromJSONValue(key, *(*list_it), command_line)) 216 if (!AppendArgumentFromJSONValue(key, *(*list_it), command_line))
217 return false; 217 return false;
218 } 218 }
219 } else if (!AppendArgumentFromJSONValue(key, value, command_line)) { 219 } else if (!AppendArgumentFromJSONValue(key, value, command_line)) {
220 return false; 220 return false;
(...skipping 25 matching lines...) Expand all
246 break; 246 break;
247 default: 247 default:
248 NOTREACHED(); 248 NOTREACHED();
249 return false; 249 return false;
250 } 250 }
251 251
252 return true; 252 return true;
253 } 253 }
254 254
255 } // namespace net 255 } // namespace net
OLDNEW
« no previous file with comments | « net/test/spawned_test_server/base_test_server.cc ('k') | net/test/spawned_test_server/spawner_communicator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698