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

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

Issue 1874893002: Convert //content/browser from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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]
(...skipping 13 matching lines...) Expand all
24 // content/browser/devtools/browser_protocol.json 24 // content/browser/devtools/browser_protocol.json
25 """ 25 """
26 26
27 template_h = string.Template(header + """\ 27 template_h = string.Template(header + """\
28 28
29 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_DISPATCHER_H_ 29 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_DISPATCHER_H_
30 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_DISPATCHER_H_ 30 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_DISPATCHER_H_
31 31
32 #include <utility> 32 #include <utility>
33 33
34 #include "base/memory/ptr_util.h"
34 #include "content/browser/devtools/protocol/devtools_protocol_client.h" 35 #include "content/browser/devtools/protocol/devtools_protocol_client.h"
35 36
36 namespace content { 37 namespace content {
37 38
38 class DevToolsProtocolDispatcher; 39 class DevToolsProtocolDispatcher;
39 40
40 namespace devtools { 41 namespace devtools {
41 42
42 extern const char kProtocolVersion[]; 43 extern const char kProtocolVersion[];
43 44
44 bool IsSupportedProtocolVersion(const std::string& version); 45 bool IsSupportedProtocolVersion(const std::string& version);
45 46
46 template<typename T> 47 template<typename T>
47 base::Value* CreateValue(const T& param) { 48 base::Value* CreateValue(const T& param) {
48 return new base::FundamentalValue(param); 49 return new base::FundamentalValue(param);
49 } 50 }
50 51
51 template<class T> 52 template<class T>
52 base::Value* CreateValue(scoped_ptr<T>& param) { 53 base::Value* CreateValue(std::unique_ptr<T>& param) {
53 return param.release(); 54 return param.release();
54 } 55 }
55 56
56 template<class T> 57 template<class T>
57 base::Value* CreateValue(scoped_refptr<T> param) { 58 base::Value* CreateValue(scoped_refptr<T> param) {
58 return param->ToValue().release(); 59 return param->ToValue().release();
59 } 60 }
60 61
61 template<typename T> 62 template<typename T>
62 base::Value* CreateValue(const std::vector<T> param) { 63 base::Value* CreateValue(const std::vector<T> param) {
63 base::ListValue* result = new base::ListValue(); 64 base::ListValue* result = new base::ListValue();
64 for (auto& item : param) { 65 for (auto& item : param) {
65 result->Append(CreateValue(item)); 66 result->Append(CreateValue(item));
66 } 67 }
67 return result; 68 return result;
68 } 69 }
69 70
70 template<> 71 template<>
71 base::Value* CreateValue(const std::string& param); 72 base::Value* CreateValue(const std::string& param);
72 73
73 ${types}\ 74 ${types}\
74 75
75 } // namespace devtools 76 } // namespace devtools
76 77
77 class DevToolsProtocolDispatcher { 78 class DevToolsProtocolDispatcher {
78 public: 79 public:
79 using CommandHandler = 80 using CommandHandler =
80 base::Callback<bool(DevToolsCommandId, 81 base::Callback<bool(DevToolsCommandId,
81 scoped_ptr<base::DictionaryValue>)>; 82 std::unique_ptr<base::DictionaryValue>)>;
82 83
83 explicit DevToolsProtocolDispatcher(DevToolsProtocolDelegate* notifier); 84 explicit DevToolsProtocolDispatcher(DevToolsProtocolDelegate* notifier);
84 ~DevToolsProtocolDispatcher(); 85 ~DevToolsProtocolDispatcher();
85 86
86 CommandHandler FindCommandHandler(const std::string& method); 87 CommandHandler FindCommandHandler(const std::string& method);
87 88
88 ${setters}\ 89 ${setters}\
89 90
90 private: 91 private:
91 using Response = DevToolsProtocolClient::Response; 92 using Response = DevToolsProtocolClient::Response;
(...skipping 28 matching lines...) Expand all
120 kAllSet = 0, 121 kAllSet = 0,
121 ${fields_enum}\ 122 ${fields_enum}\
122 }; 123 };
123 124
124 ${methods}\ 125 ${methods}\
125 126
126 static scoped_refptr<${declared_name}Builder<kNoneSet>> Create() { 127 static scoped_refptr<${declared_name}Builder<kNoneSet>> Create() {
127 return new ${declared_name}Builder<kNoneSet>(); 128 return new ${declared_name}Builder<kNoneSet>();
128 } 129 }
129 130
130 scoped_ptr<base::DictionaryValue> ToValue() { 131 std::unique_ptr<base::DictionaryValue> ToValue() {
131 static_assert(MASK == kAllSet, "required properties missing"); 132 static_assert(MASK == kAllSet, "required properties missing");
132 return make_scoped_ptr(dict_->DeepCopy()); 133 return base::WrapUnique(dict_->DeepCopy());
133 } 134 }
134 135
135 private: 136 private:
136 friend struct ${declared_name}Builder<0>; 137 friend struct ${declared_name}Builder<0>;
137 friend class base::RefCounted<${declared_name}Builder<MASK>>; 138 friend class base::RefCounted<${declared_name}Builder<MASK>>;
138 ~${declared_name}Builder() {} 139 ~${declared_name}Builder() {}
139 140
140 ${declared_name}Builder() : dict_(new base::DictionaryValue()) { 141 ${declared_name}Builder() : dict_(new base::DictionaryValue()) {
141 } 142 }
142 143
143 template<class T> T* ThisAs() { 144 template<class T> T* ThisAs() {
144 static_assert(sizeof(*this) == sizeof(T), "cannot cast"); 145 static_assert(sizeof(*this) == sizeof(T), "cannot cast");
145 return reinterpret_cast<T*>(this); 146 return reinterpret_cast<T*>(this);
146 } 147 }
147 148
148 scoped_ptr<base::DictionaryValue> dict_; 149 std::unique_ptr<base::DictionaryValue> dict_;
149 }; 150 };
150 151
151 typedef ${declared_name}Builder<0> ${declared_name}; 152 typedef ${declared_name}Builder<0> ${declared_name};
152 153
153 } // namespace ${domain} 154 } // namespace ${domain}
154 """) 155 """)
155 156
156 tmpl_builder_setter_req = string.Template("""\ 157 tmpl_builder_setter_req = string.Template("""\
157 scoped_refptr<${declared_name}Builder<MASK & ~k${Param}>> 158 scoped_refptr<${declared_name}Builder<MASK & ~k${Param}>>
158 set_${param}(${pass_type} ${param}) { 159 set_${param}(${pass_type} ${param}) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 """) 231 """)
231 232
232 tmpl_setter = string.Template("""\ 233 tmpl_setter = string.Template("""\
233 void Set${Domain}Handler( 234 void Set${Domain}Handler(
234 devtools::${domain}::${Domain}Handler* ${domain}_handler); 235 devtools::${domain}::${Domain}Handler* ${domain}_handler);
235 """) 236 """)
236 237
237 tmpl_callback = string.Template("""\ 238 tmpl_callback = string.Template("""\
238 bool On${Domain}${Command}( 239 bool On${Domain}${Command}(
239 DevToolsCommandId command_id, 240 DevToolsCommandId command_id,
240 scoped_ptr<base::DictionaryValue> params); 241 std::unique_ptr<base::DictionaryValue> params);
241 """) 242 """)
242 243
243 tmpl_field = string.Template("""\ 244 tmpl_field = string.Template("""\
244 devtools::${domain}::${Domain}Handler* ${domain}_handler_; 245 devtools::${domain}::${Domain}Handler* ${domain}_handler_;
245 """) 246 """)
246 247
247 template_cc = string.Template(header + """\ 248 template_cc = string.Template(header + """\
248 249
249 #include "base/bind.h" 250 #include "base/bind.h"
250 #include "base/strings/string_number_conversions.h" 251 #include "base/strings/string_number_conversions.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 """) 313 """)
313 314
314 tmpl_register = string.Template("""\ 315 tmpl_register = string.Template("""\
315 command_handlers_["${Domain}.${command}"] = 316 command_handlers_["${Domain}.${command}"] =
316 base::Bind( 317 base::Bind(
317 &DevToolsProtocolDispatcher::On${TargetDomain}${Command}, 318 &DevToolsProtocolDispatcher::On${TargetDomain}${Command},
318 base::Unretained(this)); 319 base::Unretained(this));
319 """) 320 """)
320 321
321 tmpl_init_client = string.Template("""\ 322 tmpl_init_client = string.Template("""\
322 ${domain}_handler_->SetClient(make_scoped_ptr( 323 ${domain}_handler_->SetClient(base::WrapUnique(
323 new devtools::${domain}::Client(notifier_))); 324 new devtools::${domain}::Client(notifier_)));
324 """) 325 """)
325 326
326 tmpl_callback_impl = string.Template("""\ 327 tmpl_callback_impl = string.Template("""\
327 bool DevToolsProtocolDispatcher::On${Domain}${Command}( 328 bool DevToolsProtocolDispatcher::On${Domain}${Command}(
328 DevToolsCommandId command_id, 329 DevToolsCommandId command_id,
329 scoped_ptr<base::DictionaryValue> params) { 330 std::unique_ptr<base::DictionaryValue> params) {
330 ${prep}\ 331 ${prep}\
331 Response response = ${domain}_handler_->${Command}(${args}); 332 Response response = ${domain}_handler_->${Command}(${args});
332 scoped_ptr<base::DictionaryValue> protocol_response; 333 std::unique_ptr<base::DictionaryValue> protocol_response;
333 if (client_.SendError(command_id, response)) 334 if (client_.SendError(command_id, response))
334 return true; 335 return true;
335 if (response.IsFallThrough()) 336 if (response.IsFallThrough())
336 return false; 337 return false;
337 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); 338 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue());
338 ${wrap}\ 339 ${wrap}\
339 client_.SendSuccess(command_id, std::move(result)); 340 client_.SendSuccess(command_id, std::move(result));
340 return true; 341 return true;
341 } 342 }
342 """) 343 """)
343 344
344 tmpl_wrap = string.Template("""\ 345 tmpl_wrap = string.Template("""\
345 result->Set("${proto_param}", devtools::CreateValue(out_${param})); 346 result->Set("${proto_param}", devtools::CreateValue(out_${param}));
346 """) 347 """)
347 348
348 tmpl_callback_async_impl = string.Template("""\ 349 tmpl_callback_async_impl = string.Template("""\
349 bool DevToolsProtocolDispatcher::On${Domain}${Command}( 350 bool DevToolsProtocolDispatcher::On${Domain}${Command}(
350 DevToolsCommandId command_id, 351 DevToolsCommandId command_id,
351 scoped_ptr<base::DictionaryValue> params) { 352 std::unique_ptr<base::DictionaryValue> params) {
352 ${prep}\ 353 ${prep}\
353 Response response = ${domain}_handler_->${Command}(${args}); 354 Response response = ${domain}_handler_->${Command}(${args});
354 if (client_.SendError(command_id, response)) 355 if (client_.SendError(command_id, response))
355 return true; 356 return true;
356 return !response.IsFallThrough(); 357 return !response.IsFallThrough();
357 } 358 }
358 """) 359 """)
359 360
360 tmpl_prep_req = string.Template("""\ 361 tmpl_prep_req = string.Template("""\
361 ${raw_type} in_${param}${init}; 362 ${raw_type} in_${param}${init};
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 """) 396 """)
396 397
397 tmpl_arg_name = string.Template("in_${param}") 398 tmpl_arg_name = string.Template("in_${param}")
398 399
399 tmpl_arg_req = string.Template("${param_pass}") 400 tmpl_arg_req = string.Template("${param_pass}")
400 401
401 tmpl_arg_opt = string.Template( 402 tmpl_arg_opt = string.Template(
402 "${param}_found ? ${param_pass} : nullptr") 403 "${param}_found ? ${param_pass} : nullptr")
403 404
404 tmpl_object_pass = string.Template( 405 tmpl_object_pass = string.Template(
405 "make_scoped_ptr<base::DictionaryValue>(${name}->DeepCopy())") 406 "base::WrapUnique<base::DictionaryValue>(${name}->DeepCopy())")
406 407
407 tmpl_client_impl = string.Template("""\ 408 tmpl_client_impl = string.Template("""\
408 namespace ${domain} { 409 namespace ${domain} {
409 410
410 Client::Client(DevToolsProtocolDelegate* notifier) 411 Client::Client(DevToolsProtocolDelegate* notifier)
411 : DevToolsProtocolClient(notifier) { 412 : DevToolsProtocolClient(notifier) {
412 } 413 }
413 414
414 Client::~Client() { 415 Client::~Client() {
415 } 416 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 mapping["prep_req"] = tmpl_prep_req_list.substitute(mapping, 559 mapping["prep_req"] = tmpl_prep_req_list.substitute(mapping,
559 item_type = items_map["storage_type"], 560 item_type = items_map["storage_type"],
560 item_init = items_map["init"], 561 item_init = items_map["init"],
561 item_raw_type = items_map["raw_type"], 562 item_raw_type = items_map["raw_type"],
562 item_pass = items_map["pass_template"].substitute(name="item", opt=""), 563 item_pass = items_map["pass_template"].substitute(name="item", opt=""),
563 ItemType = items_map["Type"]) 564 ItemType = items_map["Type"])
564 mapping["arg_out"] = "&out_%s" % mapping["param"] 565 mapping["arg_out"] = "&out_%s" % mapping["param"]
565 566
566 def ResolveObject(json, mapping): 567 def ResolveObject(json, mapping):
567 mapping["Type"] = "Dictionary" 568 mapping["Type"] = "Dictionary"
568 mapping["storage_type"] = "scoped_ptr<base::DictionaryValue>" 569 mapping["storage_type"] = "std::unique_ptr<base::DictionaryValue>"
569 mapping["raw_type"] = "base::DictionaryValue*" 570 mapping["raw_type"] = "base::DictionaryValue*"
570 mapping["pass_template"] = tmpl_object_pass 571 mapping["pass_template"] = tmpl_object_pass
571 mapping["init"] = " = nullptr" 572 mapping["init"] = " = nullptr"
572 if "properties" in json: 573 if "properties" in json:
573 if not "declared_name" in mapping: 574 if not "declared_name" in mapping:
574 mapping["declared_name"] = ("%s%s" % 575 mapping["declared_name"] = ("%s%s" %
575 (mapping["Command"], Capitalize(mapping["proto_param"]))) 576 (mapping["Command"], Capitalize(mapping["proto_param"])))
576 mapping["param_type"] = ("scoped_refptr<%s>" % 577 mapping["param_type"] = ("scoped_refptr<%s>" %
577 tmpl_typename.substitute(mapping)) 578 tmpl_typename.substitute(mapping))
578 DeclareStruct(json["properties"], mapping) 579 DeclareStruct(json["properties"], mapping)
579 else: 580 else:
580 mapping["param_type"] = ("scoped_refptr<%s>" % 581 mapping["param_type"] = ("scoped_refptr<%s>" %
581 tmpl_typename.substitute(mapping)) 582 tmpl_typename.substitute(mapping))
582 mapping["pass_type"] = mapping["param_type"] 583 mapping["pass_type"] = mapping["param_type"]
583 mapping["arg_out"] = "&out_%s" % mapping["param"] 584 mapping["arg_out"] = "&out_%s" % mapping["param"]
584 else: 585 else:
585 mapping["param_type"] = "base::DictionaryValue" 586 mapping["param_type"] = "base::DictionaryValue"
586 mapping["pass_type"] = "scoped_ptr<base::DictionaryValue>" 587 mapping["pass_type"] = "std::unique_ptr<base::DictionaryValue>"
587 mapping["arg_out"] = "out_%s.get()" % mapping["param"] 588 mapping["arg_out"] = "out_%s.get()" % mapping["param"]
588 mapping["prep_req"] = tmpl_prep_req.substitute(mapping) 589 mapping["prep_req"] = tmpl_prep_req.substitute(mapping)
589 590
590 def ResolvePrimitive(json, mapping): 591 def ResolvePrimitive(json, mapping):
591 jsonrpc_type = json["type"] 592 jsonrpc_type = json["type"]
592 if jsonrpc_type == "boolean": 593 if jsonrpc_type == "boolean":
593 mapping["param_type"] = "bool" 594 mapping["param_type"] = "bool"
594 mapping["Type"] = "Boolean" 595 mapping["Type"] = "Boolean"
595 mapping["init"] = " = false" 596 mapping["init"] = " = false"
596 elif jsonrpc_type == "integer": 597 elif jsonrpc_type == "integer":
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 output_h_file.close() 798 output_h_file.close()
798 799
799 output_cc_file.write(template_cc.substitute({}, 800 output_cc_file.write(template_cc.substitute({},
800 major = blink_protocol["version"]["major"], 801 major = blink_protocol["version"]["major"],
801 minor = blink_protocol["version"]["minor"], 802 minor = blink_protocol["version"]["minor"],
802 includes = "".join(sorted(includes)), 803 includes = "".join(sorted(includes)),
803 fields_init = ",\n ".join(fields_init), 804 fields_init = ",\n ".join(fields_init),
804 methods = "\n".join(handler_method_impls), 805 methods = "\n".join(handler_method_impls),
805 types = "\n".join(type_impls))) 806 types = "\n".join(type_impls)))
806 output_cc_file.close() 807 output_cc_file.close()
OLDNEW
« no previous file with comments | « content/browser/devtools/protocol/devtools_protocol_client.cc ('k') | content/browser/devtools/protocol/emulation_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698