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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/chromedriver/logging.cc
diff --git a/chrome/test/chromedriver/logging.cc b/chrome/test/chromedriver/logging.cc
index afd73754ca19963be1f6f74e75d15fdb070a88a6..a561275696cdab5107ce99e82ad6cf42bb41d339 100644
--- a/chrome/test/chromedriver/logging.cc
+++ b/chrome/test/chromedriver/logging.cc
@@ -130,6 +130,7 @@ bool HandleLogMessage(int severity,
const char WebDriverLog::kBrowserType[] = "browser";
const char WebDriverLog::kDriverType[] = "driver";
const char WebDriverLog::kPerformanceType[] = "performance";
+const size_t WebDriverLog::kMaxReturnedEntries = 100000;
bool WebDriverLog::NameToLevel(const std::string& name, Log::Level* out_level) {
for (size_t i = 0; i < arraysize(kNameToLevel); ++i) {
@@ -151,8 +152,25 @@ WebDriverLog::~WebDriverLog() {
}
std::unique_ptr<base::ListValue> WebDriverLog::GetAndClearEntries() {
- std::unique_ptr<base::ListValue> ret(entries_.release());
- entries_.reset(new base::ListValue());
+ std::unique_ptr<base::ListValue> ret(new base::ListValue());
+ if (entries_->GetSize() <= WebDriverLog::kMaxReturnedEntries) {
+ std::swap(entries_, ret);
+ } else {
+ // net::HttpServer has a maximum buffer size of 100MB. If there are too many
+ // log entries, we'll fail to send them all back in one go. So we only
+ // return |kMaxReturnedEntries| entries at a time.
+ // TODO(crbug.com/681892): Add streaming support to net::HttpServer, so that
+ // we don't have to worry about its buffer size.
+ for (size_t i = 0; i < kMaxReturnedEntries; i++) {
+ // base::ListValue doesn't provide a method to split lists in constant
+ // time, so construct a new list for the return value. This should be
+ // revisited if users run into performance problems with large traces.
+ std::unique_ptr<base::Value> entry;
+ if (!entries_->Remove(0, &entry))
+ break;
+ ret->Append(std::move(entry));
+ }
+ }
return ret;
}
« 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