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

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

Issue 2644033004: [chromedriver] Prevent GetLog from returning more than 100,000 at a time. (Closed)
Patch Set: add comment 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;
133 134
134 bool WebDriverLog::NameToLevel(const std::string& name, Log::Level* out_level) { 135 bool WebDriverLog::NameToLevel(const std::string& name, Log::Level* out_level) {
135 for (size_t i = 0; i < arraysize(kNameToLevel); ++i) { 136 for (size_t i = 0; i < arraysize(kNameToLevel); ++i) {
136 if (name == kNameToLevel[i].name) { 137 if (name == kNameToLevel[i].name) {
137 *out_level = kNameToLevel[i].level; 138 *out_level = kNameToLevel[i].level;
138 return true; 139 return true;
139 } 140 }
140 } 141 }
141 return false; 142 return false;
142 } 143 }
143 144
144 WebDriverLog::WebDriverLog(const std::string& type, Log::Level min_level) 145 WebDriverLog::WebDriverLog(const std::string& type, Log::Level min_level)
145 : type_(type), min_level_(min_level), entries_(new base::ListValue()) { 146 : type_(type), min_level_(min_level), entries_(new base::ListValue()) {
146 } 147 }
147 148
148 WebDriverLog::~WebDriverLog() { 149 WebDriverLog::~WebDriverLog() {
149 VLOG(1) << "Log type '" << type_ << "' lost " 150 VLOG(1) << "Log type '" << type_ << "' lost "
150 << entries_->GetSize() << " entries on destruction"; 151 << entries_->GetSize() << " entries on destruction";
151 } 152 }
152 153
153 std::unique_ptr<base::ListValue> WebDriverLog::GetAndClearEntries() { 154 std::unique_ptr<base::ListValue> WebDriverLog::GetAndClearEntries() {
154 std::unique_ptr<base::ListValue> ret(entries_.release()); 155 std::unique_ptr<base::ListValue> ret(new base::ListValue());
155 entries_.reset(new base::ListValue()); 156 if (entries_->GetSize() <= WebDriverLog::kMaxReturnedEntries) {
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 }
156 return ret; 174 return ret;
157 } 175 }
158 176
159 std::string WebDriverLog::GetFirstErrorMessage() const { 177 std::string WebDriverLog::GetFirstErrorMessage() const {
160 for (base::ListValue::iterator it = entries_->begin(); 178 for (base::ListValue::iterator it = entries_->begin();
161 it != entries_->end(); 179 it != entries_->end();
162 ++it) { 180 ++it) {
163 base::DictionaryValue* log_entry = NULL; 181 base::DictionaryValue* log_entry = NULL;
164 (*it)->GetAsDictionary(&log_entry); 182 (*it)->GetAsDictionary(&log_entry);
165 if (log_entry != NULL) { 183 if (log_entry != NULL) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 logs.push_back(browser_log); 310 logs.push_back(browser_log);
293 // If the level is OFF, don't even bother listening for DevTools events. 311 // If the level is OFF, don't even bother listening for DevTools events.
294 if (browser_log_level != Log::kOff) 312 if (browser_log_level != Log::kOff)
295 devtools_listeners.push_back(new ConsoleLogger(browser_log)); 313 devtools_listeners.push_back(new ConsoleLogger(browser_log));
296 314
297 out_logs->swap(logs); 315 out_logs->swap(logs);
298 out_devtools_listeners->swap(devtools_listeners); 316 out_devtools_listeners->swap(devtools_listeners);
299 out_command_listeners->swap(command_listeners); 317 out_command_listeners->swap(command_listeners);
300 return Status(kOk); 318 return Status(kOk);
301 } 319 }
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