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

Side by Side Diff: chrome/browser/extensions/api/debugger/debugger_api.cc

Issue 2323993004: Remove use of deprecated base::ListValue::Append(Value*) overload in extensions. (Closed)
Patch Set: Less explosions 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Implements the Chrome Extensions Debugger API. 5 // Implements the Chrome Extensions Debugger API.
6 6
7 #include "chrome/browser/extensions/api/debugger/debugger_api.h" 7 #include "chrome/browser/extensions/api/debugger/debugger_api.h"
8 8
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 const char kTargetIdField[] = "id"; 670 const char kTargetIdField[] = "id";
671 const char kTargetTypeField[] = "type"; 671 const char kTargetTypeField[] = "type";
672 const char kTargetTitleField[] = "title"; 672 const char kTargetTitleField[] = "title";
673 const char kTargetAttachedField[] = "attached"; 673 const char kTargetAttachedField[] = "attached";
674 const char kTargetUrlField[] = "url"; 674 const char kTargetUrlField[] = "url";
675 const char kTargetFaviconUrlField[] = "faviconUrl"; 675 const char kTargetFaviconUrlField[] = "faviconUrl";
676 const char kTargetTabIdField[] = "tabId"; 676 const char kTargetTabIdField[] = "tabId";
677 const char kTargetExtensionIdField[] = "extensionId"; 677 const char kTargetExtensionIdField[] = "extensionId";
678 const char kTargetTypeWorker[] = "worker"; 678 const char kTargetTypeWorker[] = "worker";
679 679
680 base::Value* SerializeTarget(scoped_refptr<DevToolsAgentHost> host) { 680 std::unique_ptr<base::Value> SerializeTarget(
681 base::DictionaryValue* dictionary = new base::DictionaryValue(); 681 scoped_refptr<DevToolsAgentHost> host) {
682 std::unique_ptr<base::DictionaryValue> dictionary(
683 new base::DictionaryValue());
682 dictionary->SetString(kTargetIdField, host->GetId()); 684 dictionary->SetString(kTargetIdField, host->GetId());
683 dictionary->SetString(kTargetTitleField, host->GetTitle()); 685 dictionary->SetString(kTargetTitleField, host->GetTitle());
684 dictionary->SetBoolean(kTargetAttachedField, host->IsAttached()); 686 dictionary->SetBoolean(kTargetAttachedField, host->IsAttached());
685 dictionary->SetString(kTargetUrlField, host->GetURL().spec()); 687 dictionary->SetString(kTargetUrlField, host->GetURL().spec());
686 688
687 std::string type = host->GetType(); 689 std::string type = host->GetType();
688 if (type == DevToolsAgentHost::kTypePage) { 690 if (type == DevToolsAgentHost::kTypePage) {
689 int tab_id = 691 int tab_id =
690 extensions::ExtensionTabUtil::GetTabId(host->GetWebContents()); 692 extensions::ExtensionTabUtil::GetTabId(host->GetWebContents());
691 dictionary->SetInteger(kTargetTabIdField, tab_id); 693 dictionary->SetInteger(kTargetTabIdField, tab_id);
692 } else if (type == ChromeDevToolsManagerDelegate::kTypeBackgroundPage) { 694 } else if (type == ChromeDevToolsManagerDelegate::kTypeBackgroundPage) {
693 dictionary->SetString(kTargetExtensionIdField, host->GetURL().host()); 695 dictionary->SetString(kTargetExtensionIdField, host->GetURL().host());
694 } 696 }
695 697
696 if (type == DevToolsAgentHost::kTypeServiceWorker || 698 if (type == DevToolsAgentHost::kTypeServiceWorker ||
697 type == DevToolsAgentHost::kTypeSharedWorker) { 699 type == DevToolsAgentHost::kTypeSharedWorker) {
698 type = kTargetTypeWorker; 700 type = kTargetTypeWorker;
699 } 701 }
700 702
701 dictionary->SetString(kTargetTypeField, type); 703 dictionary->SetString(kTargetTypeField, type);
702 704
703 GURL favicon_url = host->GetFaviconURL(); 705 GURL favicon_url = host->GetFaviconURL();
704 if (favicon_url.is_valid()) 706 if (favicon_url.is_valid())
705 dictionary->SetString(kTargetFaviconUrlField, favicon_url.spec()); 707 dictionary->SetString(kTargetFaviconUrlField, favicon_url.spec());
706 708
707 return dictionary; 709 return std::move(dictionary);
Devlin 2016/09/12 19:12:34 isn't this a pessimising move?
dcheng 2016/09/12 20:26:45 std::move() is required when the return type is di
Devlin 2016/09/14 14:56:52 Ah, interesting. I was wondering why there wasn't
708 } 710 }
709 711
710 } // namespace 712 } // namespace
711 713
712 DebuggerGetTargetsFunction::DebuggerGetTargetsFunction() { 714 DebuggerGetTargetsFunction::DebuggerGetTargetsFunction() {
713 } 715 }
714 716
715 DebuggerGetTargetsFunction::~DebuggerGetTargetsFunction() { 717 DebuggerGetTargetsFunction::~DebuggerGetTargetsFunction() {
716 } 718 }
717 719
718 bool DebuggerGetTargetsFunction::RunAsync() { 720 bool DebuggerGetTargetsFunction::RunAsync() {
719 content::DevToolsAgentHost::List list = DevToolsAgentHost::GetOrCreateAll(); 721 content::DevToolsAgentHost::List list = DevToolsAgentHost::GetOrCreateAll();
720 content::BrowserThread::PostTask( 722 content::BrowserThread::PostTask(
721 content::BrowserThread::UI, 723 content::BrowserThread::UI,
722 FROM_HERE, 724 FROM_HERE,
723 base::Bind(&DebuggerGetTargetsFunction::SendTargetList, this, list)); 725 base::Bind(&DebuggerGetTargetsFunction::SendTargetList, this, list));
724 return true; 726 return true;
725 } 727 }
726 728
727 void DebuggerGetTargetsFunction::SendTargetList( 729 void DebuggerGetTargetsFunction::SendTargetList(
728 const content::DevToolsAgentHost::List& target_list) { 730 const content::DevToolsAgentHost::List& target_list) {
729 std::unique_ptr<base::ListValue> result(new base::ListValue()); 731 std::unique_ptr<base::ListValue> result(new base::ListValue());
730 for (size_t i = 0; i < target_list.size(); ++i) 732 for (size_t i = 0; i < target_list.size(); ++i)
731 result->Append(SerializeTarget(target_list[i])); 733 result->Append(SerializeTarget(target_list[i]));
732 SetResult(std::move(result)); 734 SetResult(std::move(result));
733 SendResponse(true); 735 SendResponse(true);
734 } 736 }
735 737
736 } // namespace extensions 738 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698