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

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

Issue 2655503002: Revert of [chromedriver] Prevent GetLog from returning more than 100,000 at a time. (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « chrome/test/chromedriver/logging.h ('k') | chrome/test/chromedriver/logging_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/logging.h" 5 #include "chrome/test/chromedriver/logging.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <stdio.h> 9 #include <stdio.h>
10 10
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 session_log->AddEntry(level, message); 123 session_log->AddEntry(level, message);
124 124
125 return true; 125 return true;
126 } 126 }
127 127
128 } // namespace 128 } // namespace
129 129
130 const char WebDriverLog::kBrowserType[] = "browser"; 130 const char WebDriverLog::kBrowserType[] = "browser";
131 const char WebDriverLog::kDriverType[] = "driver"; 131 const char WebDriverLog::kDriverType[] = "driver";
132 const char WebDriverLog::kPerformanceType[] = "performance"; 132 const char WebDriverLog::kPerformanceType[] = "performance";
133 const size_t WebDriverLog::kMaxReturnedEntries = 100000;
134 133
135 bool WebDriverLog::NameToLevel(const std::string& name, Log::Level* out_level) { 134 bool WebDriverLog::NameToLevel(const std::string& name, Log::Level* out_level) {
136 for (size_t i = 0; i < arraysize(kNameToLevel); ++i) { 135 for (size_t i = 0; i < arraysize(kNameToLevel); ++i) {
137 if (name == kNameToLevel[i].name) { 136 if (name == kNameToLevel[i].name) {
138 *out_level = kNameToLevel[i].level; 137 *out_level = kNameToLevel[i].level;
139 return true; 138 return true;
140 } 139 }
141 } 140 }
142 return false; 141 return false;
143 } 142 }
144 143
145 WebDriverLog::WebDriverLog(const std::string& type, Log::Level min_level) 144 WebDriverLog::WebDriverLog(const std::string& type, Log::Level min_level)
146 : type_(type), min_level_(min_level), entries_(new base::ListValue()) { 145 : type_(type), min_level_(min_level), entries_(new base::ListValue()) {
147 } 146 }
148 147
149 WebDriverLog::~WebDriverLog() { 148 WebDriverLog::~WebDriverLog() {
150 VLOG(1) << "Log type '" << type_ << "' lost " 149 VLOG(1) << "Log type '" << type_ << "' lost "
151 << entries_->GetSize() << " entries on destruction"; 150 << entries_->GetSize() << " entries on destruction";
152 } 151 }
153 152
154 std::unique_ptr<base::ListValue> WebDriverLog::GetAndClearEntries() { 153 std::unique_ptr<base::ListValue> WebDriverLog::GetAndClearEntries() {
155 std::unique_ptr<base::ListValue> ret(new base::ListValue()); 154 std::unique_ptr<base::ListValue> ret(entries_.release());
156 if (entries_->GetSize() <= WebDriverLog::kMaxReturnedEntries) { 155 entries_.reset(new base::ListValue());
157 std::swap(entries_, ret);
158 } else {
159 // net::HttpServer has a maximum buffer size of 100MB. If there are too many
160 // log entries, we'll fail to send them all back in one go. So we only
161 // return |kMaxReturnedEntries| entries at a time.
162 // TODO(crbug.com/681892): Add streaming support to net::HttpServer, so that
163 // we don't have to worry about its buffer size.
164 for (size_t i = 0; i < kMaxReturnedEntries; i++) {
165 // base::ListValue doesn't provide a method to split lists in constant
166 // time, so construct a new list for the return value. This should be
167 // revisited if users run into performance problems with large traces.
168 std::unique_ptr<base::Value> entry;
169 if (!entries_->Remove(0, &entry))
170 break;
171 ret->Append(std::move(entry));
172 }
173 }
174 return ret; 156 return ret;
175 } 157 }
176 158
177 std::string WebDriverLog::GetFirstErrorMessage() const { 159 std::string WebDriverLog::GetFirstErrorMessage() const {
178 for (base::ListValue::iterator it = entries_->begin(); 160 for (base::ListValue::iterator it = entries_->begin();
179 it != entries_->end(); 161 it != entries_->end();
180 ++it) { 162 ++it) {
181 base::DictionaryValue* log_entry = NULL; 163 base::DictionaryValue* log_entry = NULL;
182 (*it)->GetAsDictionary(&log_entry); 164 (*it)->GetAsDictionary(&log_entry);
183 if (log_entry != NULL) { 165 if (log_entry != NULL) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 logs.push_back(browser_log); 292 logs.push_back(browser_log);
311 // If the level is OFF, don't even bother listening for DevTools events. 293 // If the level is OFF, don't even bother listening for DevTools events.
312 if (browser_log_level != Log::kOff) 294 if (browser_log_level != Log::kOff)
313 devtools_listeners.push_back(new ConsoleLogger(browser_log)); 295 devtools_listeners.push_back(new ConsoleLogger(browser_log));
314 296
315 out_logs->swap(logs); 297 out_logs->swap(logs);
316 out_devtools_listeners->swap(devtools_listeners); 298 out_devtools_listeners->swap(devtools_listeners);
317 out_command_listeners->swap(command_listeners); 299 out_command_listeners->swap(command_listeners);
318 return Status(kOk); 300 return Status(kOk);
319 } 301 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/logging.h ('k') | chrome/test/chromedriver/logging_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698