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

Side by Side Diff: chrome/test/chromedriver/chrome/log.cc

Issue 2051663003: base::ListValue::Append cleanup: pass unique_ptr instead of the released pointer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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 #include "chrome/test/chromedriver/chrome/log.h" 5 #include "chrome/test/chromedriver/chrome/log.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } else if (value->GetAsList(&list)) { 60 } else if (value->GetAsList(&list)) {
61 std::unique_ptr<base::ListValue> list_copy(new base::ListValue()); 61 std::unique_ptr<base::ListValue> list_copy(new base::ListValue());
62 for (size_t i = 0; i < list->GetSize(); ++i) { 62 for (size_t i = 0; i < list->GetSize(); ++i) {
63 const base::Value* child = NULL; 63 const base::Value* child = NULL;
64 if (!list->Get(i, &child)) 64 if (!list->Get(i, &child))
65 continue; 65 continue;
66 if (list_copy->GetSize() >= kMaxChildren - 1) { 66 if (list_copy->GetSize() >= kMaxChildren - 1) {
67 list_copy->AppendString("..."); 67 list_copy->AppendString("...");
68 break; 68 break;
69 } 69 }
70 list_copy->Append(SmartDeepCopy(child).release()); 70 list_copy->Append(SmartDeepCopy(child));
71 } 71 }
72 return std::move(list_copy); 72 return std::move(list_copy);
73 } else if (value->GetAsString(&data)) { 73 } else if (value->GetAsString(&data)) {
74 TruncateString(&data); 74 TruncateString(&data);
75 return std::unique_ptr<base::Value>(new base::StringValue(data)); 75 return std::unique_ptr<base::Value>(new base::StringValue(data));
76 } 76 }
77 return std::unique_ptr<base::Value>(value->DeepCopy()); 77 return std::unique_ptr<base::Value>(value->DeepCopy());
78 } 78 }
79 79
80 } // namespace 80 } // namespace
(...skipping 25 matching lines...) Expand all
106 std::unique_ptr<base::Value> copy(SmartDeepCopy(&value)); 106 std::unique_ptr<base::Value> copy(SmartDeepCopy(&value));
107 return PrettyPrintValue(*copy); 107 return PrettyPrintValue(*copy);
108 } 108 }
109 109
110 std::string FormatJsonForDisplay(const std::string& json) { 110 std::string FormatJsonForDisplay(const std::string& json) {
111 std::unique_ptr<base::Value> value = base::JSONReader::Read(json); 111 std::unique_ptr<base::Value> value = base::JSONReader::Read(json);
112 if (!value) 112 if (!value)
113 value.reset(new base::StringValue(json)); 113 value.reset(new base::StringValue(json));
114 return FormatValueForDisplay(*value); 114 return FormatValueForDisplay(*value);
115 } 115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698