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

Side by Side Diff: content/browser/devtools/protocol/devtools_protocol_handler_generator.py

Issue 2285933003: Remove more usage of the base::ListValue::Append(Value*) overload. (Closed)
Patch Set: rebase Created 4 years, 3 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
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import sys 6 import sys
7 import string 7 import string
8 import json 8 import json
9 9
10 blink_protocol_path = sys.argv[1] 10 blink_protocol_path = sys.argv[1]
11 output_cc_path = sys.argv[2] 11 output_cc_path = sys.argv[2]
12 output_h_path = sys.argv[3] 12 output_h_path = sys.argv[3]
13 13
14 header = """\ 14 header = """\
15 // Copyright 2014 The Chromium Authors. All rights reserved. 15 // Copyright 2014 The Chromium Authors. All rights reserved.
16 // Use of this source code is governed by a BSD-style license that can be 16 // Use of this source code is governed by a BSD-style license that can be
17 // found in the LICENSE file. 17 // found in the LICENSE file.
18 18
19 // THIS FILE IS AUTOGENERATED. DO NOT EDIT. 19 // THIS FILE IS AUTOGENERATED. DO NOT EDIT.
20 // Generated by 20 // Generated by
21 // content/public/browser/devtools_protocol_handler_generator.py from 21 // content/browser/devtools/protocol/devtools_protocol_handler_generator.py
22 // gen/blink/core/inspector/protocol.json and 22 // from gen/blink/core/inspector/protocol.json
23 """ 23 """
24 24
25 template_h = string.Template(header + """\ 25 template_h = string.Template(header + """\
26 26
27 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_DISPATCHER_H_ 27 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_DISPATCHER_H_
28 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_DISPATCHER_H_ 28 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_DISPATCHER_H_
29 29
30 #include <memory>
30 #include <utility> 31 #include <utility>
31 32
32 #include "base/memory/ptr_util.h" 33 #include "base/memory/ptr_util.h"
33 #include "content/browser/devtools/protocol/devtools_protocol_client.h" 34 #include "content/browser/devtools/protocol/devtools_protocol_client.h"
34 35
35 namespace content { 36 namespace content {
36 37
37 class DevToolsProtocolDispatcher; 38 class DevToolsProtocolDispatcher;
38 39
39 namespace devtools { 40 namespace devtools {
40 41
41 extern const char kProtocolVersion[]; 42 extern const char kProtocolVersion[];
42 43
43 bool IsSupportedProtocolVersion(const std::string& version); 44 bool IsSupportedProtocolVersion(const std::string& version);
44 45
45 template<typename T> 46 template<typename T>
46 base::Value* CreateValue(const T& param) { 47 std::unique_ptr<base::Value> CreateValue(const T& param) {
47 return new base::FundamentalValue(param); 48 return base::MakeUnique<base::FundamentalValue>(param);
49 }
50
51 template<typename T>
52 std::unique_ptr<base::Value> CreateValue(std::unique_ptr<T>& param) {
53 return std::move(param);
48 } 54 }
49 55
50 template<class T> 56 template<class T>
51 base::Value* CreateValue(std::unique_ptr<T>& param) { 57 std::unique_ptr<base::Value> CreateValue(const scoped_refptr<T>& param) {
52 return param.release(); 58 return param->ToValue();
53 }
54
55 template<class T>
56 base::Value* CreateValue(scoped_refptr<T> param) {
57 return param->ToValue().release();
58 } 59 }
59 60
60 template<typename T> 61 template<typename T>
61 base::Value* CreateValue(const std::vector<T> param) { 62 std::unique_ptr<base::Value> CreateValue(const std::vector<T>& param) {
62 base::ListValue* result = new base::ListValue(); 63 std::unique_ptr<base::ListValue> result(new base::ListValue());
63 for (auto& item : param) { 64 for (auto& item : param) {
64 result->Append(CreateValue(item)); 65 result->Append(CreateValue(item));
65 } 66 }
66 return result; 67 return std::move(result);
67 } 68 }
68 69
69 template<> 70 template<>
70 base::Value* CreateValue(const std::string& param); 71 std::unique_ptr<base::Value> CreateValue(const std::string& param);
71 72
72 ${types}\ 73 ${types}\
73 74
74 } // namespace devtools 75 } // namespace devtools
75 76
76 class DevToolsProtocolDispatcher { 77 class DevToolsProtocolDispatcher {
77 public: 78 public:
78 using CommandHandler = 79 using CommandHandler =
79 base::Callback<bool(DevToolsCommandId, 80 base::Callback<bool(DevToolsCommandId,
80 std::unique_ptr<base::DictionaryValue>)>; 81 std::unique_ptr<base::DictionaryValue>)>;
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 bool IsSupportedProtocolVersion(const std::string& version) { 278 bool IsSupportedProtocolVersion(const std::string& version) {
278 std::vector<base::StringPiece> tokens = base::SplitStringPiece( 279 std::vector<base::StringPiece> tokens = base::SplitStringPiece(
279 version, ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); 280 version, ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
280 int major, minor; 281 int major, minor;
281 return tokens.size() == 2 && 282 return tokens.size() == 2 &&
282 base::StringToInt(tokens[0], &major) && major == ${major} && 283 base::StringToInt(tokens[0], &major) && major == ${major} &&
283 base::StringToInt(tokens[1], &minor) && minor <= ${minor}; 284 base::StringToInt(tokens[1], &minor) && minor <= ${minor};
284 } 285 }
285 286
286 template<> 287 template<>
287 base::Value* CreateValue(const std::string& param) { 288 std::unique_ptr<base::Value> CreateValue(const std::string& param) {
288 return new base::StringValue(param); 289 return base::MakeUnique<base::StringValue>(param);
289 } 290 }
290 291
291 ${types}\ 292 ${types}\
292 293
293 } // namespace devtools 294 } // namespace devtools
294 295
295 } // namespace content 296 } // namespace content
296 """) 297 """)
297 298
298 tmpl_include = string.Template("""\ 299 tmpl_include = string.Template("""\
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 output_h_file.close() 796 output_h_file.close()
796 797
797 output_cc_file.write(template_cc.substitute({}, 798 output_cc_file.write(template_cc.substitute({},
798 major = blink_protocol["version"]["major"], 799 major = blink_protocol["version"]["major"],
799 minor = blink_protocol["version"]["minor"], 800 minor = blink_protocol["version"]["minor"],
800 includes = "".join(sorted(includes)), 801 includes = "".join(sorted(includes)),
801 fields_init = ",\n ".join(fields_init), 802 fields_init = ",\n ".join(fields_init),
802 methods = "\n".join(handler_method_impls), 803 methods = "\n".join(handler_method_impls),
803 types = "\n".join(type_impls))) 804 types = "\n".join(type_impls)))
804 output_cc_file.close() 805 output_cc_file.close()
OLDNEW
« no previous file with comments | « content/browser/accessibility/accessibility_ui.cc ('k') | content/browser/gpu/gpu_internals_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698