Chromium Code Reviews| Index: chrome/test/chromedriver/devtools_events_logger.cc |
| diff --git a/chrome/test/chromedriver/devtools_events_logger.cc b/chrome/test/chromedriver/devtools_events_logger.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cc670dbff5f6905462861c78cecb0be7a12333ab |
| --- /dev/null |
| +++ b/chrome/test/chromedriver/devtools_events_logger.cc |
| @@ -0,0 +1,44 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/test/chromedriver/devtools_events_logger.h" |
| + |
| +#include "base/json/json_writer.h" |
| +#include "chrome/test/chromedriver/chrome/devtools_client.h" |
| +#include "chrome/test/chromedriver/chrome/devtools_client_impl.h" |
| + |
| +DevToolsEventsLogger::DevToolsEventsLogger(Log* log, |
| + const base::ListValue* prefs) |
|
stgao
2017/05/03 20:24:44
style nit: params not aligned.
em
2017/05/04 01:11:22
Done.
|
| + : log_(log), |
| + prefs_(prefs) {} |
| + |
| +inline DevToolsEventsLogger::~DevToolsEventsLogger() {} |
| + |
| +Status DevToolsEventsLogger::OnConnected(DevToolsClient* client) { |
| + for (base::ListValue::const_iterator it = prefs_->begin(); |
| + it != prefs_->end(); |
| + ++it) { |
| + std::string event; |
| + it->GetAsString(&event); |
| + events_.insert(event); |
| + } |
| + return Status(kOk); |
| +} |
| + |
| +Status DevToolsEventsLogger::OnEvent( |
| + DevToolsClient* client, |
| + const std::string& method, |
| + const base::DictionaryValue& params) { |
| + std::unordered_set<std::string>::iterator it = events_.find(method); |
| + if (it != events_.end()) { |
| + base::DictionaryValue log_message_dict; |
| + log_message_dict.SetString("method", method); |
| + log_message_dict.Set("params", params.DeepCopy()); |
| + std::string log_message_json; |
| + base::JSONWriter::Write(log_message_dict, &log_message_json); |
| + |
| + log_->AddEntry(Log::kInfo, log_message_json); |
| + } |
| + return Status(kOk); |
| +} |