summaryrefslogtreecommitdiff
path: root/chromium/components/net_log
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-05-09 14:22:11 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2016-05-09 15:11:45 +0000
commit2ddb2d3e14eef3de7dbd0cef553d669b9ac2361c (patch)
treee75f511546c5fd1a173e87c1f9fb11d7ac8d1af3 /chromium/components/net_log
parenta4f3d46271c57e8155ba912df46a05559d14726e (diff)
downloadqtwebengine-chromium-2ddb2d3e14eef3de7dbd0cef553d669b9ac2361c.tar.gz
BASELINE: Update Chromium to 51.0.2704.41
Also adds in all smaller components by reversing logic for exclusion. Change-Id: Ibf90b506e7da088ea2f65dcf23f2b0992c504422 Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Diffstat (limited to 'chromium/components/net_log')
-rw-r--r--chromium/components/net_log/BUILD.gn34
-rw-r--r--chromium/components/net_log/DEPS5
-rw-r--r--chromium/components/net_log/OWNERS10
-rw-r--r--chromium/components/net_log/chrome_net_log.cc111
-rw-r--r--chromium/components/net_log/chrome_net_log.h61
-rw-r--r--chromium/components/net_log/net_export_ui_constants.cc22
-rw-r--r--chromium/components/net_log/net_export_ui_constants.h27
-rw-r--r--chromium/components/net_log/net_log_temp_file.cc232
-rw-r--r--chromium/components/net_log/net_log_temp_file.h174
-rw-r--r--chromium/components/net_log/net_log_temp_file_unittest.cc393
-rw-r--r--chromium/components/net_log/resources/net_export.css36
-rw-r--r--chromium/components/net_log/resources/net_export.html90
-rw-r--r--chromium/components/net_log/resources/net_export.js124
13 files changed, 1319 insertions, 0 deletions
diff --git a/chromium/components/net_log/BUILD.gn b/chromium/components/net_log/BUILD.gn
new file mode 100644
index 00000000000..8bdc1617c29
--- /dev/null
+++ b/chromium/components/net_log/BUILD.gn
@@ -0,0 +1,34 @@
+# Copyright 2015 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.
+
+source_set("net_log") {
+ sources = [
+ "chrome_net_log.cc",
+ "chrome_net_log.h",
+ "net_export_ui_constants.cc",
+ "net_export_ui_constants.h",
+ "net_log_temp_file.cc",
+ "net_log_temp_file.h",
+ ]
+
+ deps = [
+ "//base",
+ "//components/data_reduction_proxy/core/common",
+ "//components/version_info",
+ "//net",
+ ]
+}
+
+source_set("unit_tests") {
+ testonly = true
+ sources = [
+ "net_log_temp_file_unittest.cc",
+ ]
+ deps = [
+ ":net_log",
+ "//base",
+ "//net",
+ "//testing/gtest",
+ ]
+}
diff --git a/chromium/components/net_log/DEPS b/chromium/components/net_log/DEPS
new file mode 100644
index 00000000000..efca3dd5b18
--- /dev/null
+++ b/chromium/components/net_log/DEPS
@@ -0,0 +1,5 @@
+include_rules = [
+ "+components/data_reduction_proxy/core/common",
+ "+components/version_info",
+ "+net",
+]
diff --git a/chromium/components/net_log/OWNERS b/chromium/components/net_log/OWNERS
new file mode 100644
index 00000000000..a7b5af5b8a7
--- /dev/null
+++ b/chromium/components/net_log/OWNERS
@@ -0,0 +1,10 @@
+agl@chromium.org
+battre@chromium.org
+cbentzel@chromium.org
+eroman@chromium.org
+mattm@chromium.org
+mef@chromium.org
+mmenke@chromium.org
+rdsmith@chromium.org
+rsleevi@chromium.org
+rtenneti@chromium.org
diff --git a/chromium/components/net_log/chrome_net_log.cc b/chromium/components/net_log/chrome_net_log.cc
new file mode 100644
index 00000000000..f17908f82ca
--- /dev/null
+++ b/chromium/components/net_log/chrome_net_log.cc
@@ -0,0 +1,111 @@
+// Copyright (c) 2012 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 "components/net_log/chrome_net_log.h"
+
+#include <stdio.h>
+#include <utility>
+
+#include "base/command_line.h"
+#include "base/files/scoped_file.h"
+#include "base/logging.h"
+#include "base/strings/stringprintf.h"
+#include "base/sys_info.h"
+#include "base/values.h"
+#include "build/build_config.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h"
+#include "components/net_log/net_log_temp_file.h"
+#include "components/net_log/net_log_temp_file.h"
+#include "components/version_info/version_info.h"
+#include "net/log/net_log_util.h"
+#include "net/log/trace_net_log_observer.h"
+#include "net/log/write_to_file_net_log_observer.h"
+
+namespace net_log {
+
+ChromeNetLog::ChromeNetLog(
+ const base::FilePath& log_file,
+ net::NetLogCaptureMode log_file_mode,
+ const base::CommandLine::StringType& command_line_string,
+ const std::string& channel_string)
+ : net_log_temp_file_(
+ new NetLogTempFile(this, command_line_string, channel_string)) {
+ if (!log_file.empty()) {
+ // Much like logging.h, bypass threading restrictions by using fopen
+ // directly. Have to write on a thread that's shutdown to handle events on
+ // shutdown properly, and posting events to another thread as they occur
+ // would result in an unbounded buffer size, so not much can be gained by
+ // doing this on another thread. It's only used when debugging Chrome, so
+ // performance is not a big concern.
+ base::ScopedFILE file;
+#if defined(OS_WIN)
+ file.reset(_wfopen(log_file.value().c_str(), L"w"));
+#elif defined(OS_POSIX)
+ file.reset(fopen(log_file.value().c_str(), "w"));
+#endif
+
+ if (!file) {
+ LOG(ERROR) << "Could not open file " << log_file.value()
+ << " for net logging";
+ } else {
+ scoped_ptr<base::Value> constants(
+ GetConstants(command_line_string, channel_string));
+ write_to_file_observer_.reset(new net::WriteToFileNetLogObserver());
+
+ write_to_file_observer_->set_capture_mode(log_file_mode);
+
+ write_to_file_observer_->StartObserving(this, std::move(file),
+ constants.get(), nullptr);
+ }
+ }
+
+ trace_net_log_observer_.reset(new net::TraceNetLogObserver());
+ trace_net_log_observer_->WatchForTraceStart(this);
+}
+
+ChromeNetLog::~ChromeNetLog() {
+ net_log_temp_file_.reset();
+ // Remove the observers we own before we're destroyed.
+ if (write_to_file_observer_)
+ write_to_file_observer_->StopObserving(nullptr);
+ if (trace_net_log_observer_)
+ trace_net_log_observer_->StopWatchForTraceStart();
+}
+
+// static
+base::Value* ChromeNetLog::GetConstants(
+ const base::CommandLine::StringType& command_line_string,
+ const std::string& channel_string) {
+ scoped_ptr<base::DictionaryValue> constants_dict = net::GetNetConstants();
+ DCHECK(constants_dict);
+
+ // Add a dictionary with the version of the client and its command line
+ // arguments.
+ {
+ base::DictionaryValue* dict = new base::DictionaryValue();
+
+ // We have everything we need to send the right values.
+ dict->SetString("name", version_info::GetProductName());
+ dict->SetString("version", version_info::GetVersionNumber());
+ dict->SetString("cl", version_info::GetLastChange());
+ dict->SetString("version_mod", channel_string);
+ dict->SetString("official", version_info::IsOfficialBuild() ? "official"
+ : "unofficial");
+ std::string os_type = base::StringPrintf(
+ "%s: %s (%s)", base::SysInfo::OperatingSystemName().c_str(),
+ base::SysInfo::OperatingSystemVersion().c_str(),
+ base::SysInfo::OperatingSystemArchitecture().c_str());
+ dict->SetString("os_type", os_type);
+ dict->SetString("command_line", command_line_string);
+
+ constants_dict->Set("clientInfo", dict);
+
+ data_reduction_proxy::DataReductionProxyEventStore::AddConstants(
+ constants_dict.get());
+ }
+
+ return constants_dict.release();
+}
+
+} // namespace net_log
diff --git a/chromium/components/net_log/chrome_net_log.h b/chromium/components/net_log/chrome_net_log.h
new file mode 100644
index 00000000000..eae245d45e4
--- /dev/null
+++ b/chromium/components/net_log/chrome_net_log.h
@@ -0,0 +1,61 @@
+// Copyright (c) 2012 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.
+
+#ifndef COMPONENTS_NET_LOG_CHROME_NET_LOG_H_
+#define COMPONENTS_NET_LOG_CHROME_NET_LOG_H_
+
+#include <string>
+
+#include "base/command_line.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "net/log/net_log.h"
+
+namespace base {
+class FilePath;
+class Value;
+}
+
+namespace net {
+class WriteToFileNetLogObserver;
+class TraceNetLogObserver;
+}
+
+namespace net_log {
+
+class NetLogTempFile;
+
+// ChromeNetLog is an implementation of NetLog that adds file loggers
+// as its observers.
+class ChromeNetLog : public net::NetLog {
+ public:
+ // The log is saved to |log_file|.
+ // |log_file_mode| is the mode used to log in |log_file|.
+ // If |log_file| is empty, only a temporary log is created, and
+ // |log_file_mode| is not used.
+ ChromeNetLog(const base::FilePath& log_file,
+ net::NetLogCaptureMode log_file_mode,
+ const base::CommandLine::StringType& command_line_string,
+ const std::string& channel_string);
+ ~ChromeNetLog() override;
+
+ NetLogTempFile* net_log_temp_file() { return net_log_temp_file_.get(); }
+
+ // Returns a Value containing constants needed to load a log file.
+ // Safe to call on any thread. Caller takes ownership of the returned Value.
+ static base::Value* GetConstants(
+ const base::CommandLine::StringType& command_line_string,
+ const std::string& channel_string);
+
+ private:
+ scoped_ptr<net::WriteToFileNetLogObserver> write_to_file_observer_;
+ scoped_ptr<NetLogTempFile> net_log_temp_file_;
+ scoped_ptr<net::TraceNetLogObserver> trace_net_log_observer_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChromeNetLog);
+};
+
+} // namespace net_log
+
+#endif // COMPONENTS_NET_LOG_CHROME_NET_LOG_H_
diff --git a/chromium/components/net_log/net_export_ui_constants.cc b/chromium/components/net_log/net_export_ui_constants.cc
new file mode 100644
index 00000000000..3c79f518eb4
--- /dev/null
+++ b/chromium/components/net_log/net_export_ui_constants.cc
@@ -0,0 +1,22 @@
+// Copyright 2015 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 "components/net_log/net_export_ui_constants.h"
+
+namespace net_log {
+
+// Resource paths.
+const char kNetExportUIJS[] = "net_export.js";
+
+// Message handlers.
+const char kGetExportNetLogInfoHandler[] = "getExportNetLogInfo";
+const char kSendNetLogHandler[] = "sendNetLog";
+const char kStartNetLogHandler[] = "startNetLog";
+const char kStopNetLogHandler[] = "stopNetLog";
+
+// Other values.
+const char kOnExportNetLogInfoChanged[] =
+ "NetExportView.getInstance().onExportNetLogInfoChanged";
+
+} // namespace net_log
diff --git a/chromium/components/net_log/net_export_ui_constants.h b/chromium/components/net_log/net_export_ui_constants.h
new file mode 100644
index 00000000000..f1b3da3bea5
--- /dev/null
+++ b/chromium/components/net_log/net_export_ui_constants.h
@@ -0,0 +1,27 @@
+// Copyright 2015 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.
+
+#ifndef COMPONENTS_NET_LOG_NET_EXPORT_UI_CONSTANTS_H_
+#define COMPONENTS_NET_LOG_NET_EXPORT_UI_CONSTANTS_H_
+
+namespace net_log {
+
+// Resource paths.
+// Must match the resource file names.
+extern const char kNetExportUIJS[];
+
+// Message handlers.
+// Must match the constants used in the resource files.
+extern const char kGetExportNetLogInfoHandler[];
+extern const char kSendNetLogHandler[];
+extern const char kStartNetLogHandler[];
+extern const char kStopNetLogHandler[];
+
+// Other values.
+// Must match the constants used in the resource files.
+extern const char kOnExportNetLogInfoChanged[];
+
+} // namespace net_log
+
+#endif // COMPONENTS_NET_LOG_NET_EXPORT_UI_CONSTANTS_H_
diff --git a/chromium/components/net_log/net_log_temp_file.cc b/chromium/components/net_log/net_log_temp_file.cc
new file mode 100644
index 00000000000..d4643addd0f
--- /dev/null
+++ b/chromium/components/net_log/net_log_temp_file.cc
@@ -0,0 +1,232 @@
+// Copyright (c) 2013 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 "components/net_log/net_log_temp_file.h"
+
+#include <utility>
+
+#include "base/files/file_path.h"
+#include "base/files/file_util.h"
+#include "base/files/scoped_file.h"
+#include "base/values.h"
+#include "build/build_config.h"
+#include "components/net_log/chrome_net_log.h"
+#include "net/log/write_to_file_net_log_observer.h"
+
+namespace net_log {
+
+// Path of logs relative to base::GetTempDir(). Must be kept in sync
+// with chrome/android/java/res/xml/file_paths.xml
+base::FilePath::CharType kLogRelativePath[] =
+ FILE_PATH_LITERAL("net-export/chrome-net-export-log.json");
+
+// Old path used by net-export. Used to delete old files.
+// TODO(mmenke): Should remove at some point. Added in M46.
+base::FilePath::CharType kOldLogRelativePath[] =
+ FILE_PATH_LITERAL("chrome-net-export-log.json");
+
+NetLogTempFile::~NetLogTempFile() {
+ if (write_to_file_observer_)
+ write_to_file_observer_->StopObserving(nullptr);
+}
+
+void NetLogTempFile::ProcessCommand(Command command) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (!EnsureInit())
+ return;
+
+ switch (command) {
+ case DO_START_LOG_BYTES:
+ StartNetLog(LOG_TYPE_LOG_BYTES);
+ break;
+ case DO_START:
+ StartNetLog(LOG_TYPE_NORMAL);
+ break;
+ case DO_START_STRIP_PRIVATE_DATA:
+ StartNetLog(LOG_TYPE_STRIP_PRIVATE_DATA);
+ break;
+ case DO_STOP:
+ StopNetLog();
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+}
+
+bool NetLogTempFile::GetFilePath(base::FilePath* path) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (log_type_ == LOG_TYPE_NONE || state_ == STATE_LOGGING)
+ return false;
+
+ if (!NetExportLogExists())
+ return false;
+
+ DCHECK(!log_path_.empty());
+#if defined(OS_POSIX)
+ // Users, group and others can read, write and traverse.
+ int mode = base::FILE_PERMISSION_MASK;
+ base::SetPosixFilePermissions(log_path_, mode);
+#endif // defined(OS_POSIX)
+
+ *path = log_path_;
+ return true;
+}
+
+base::DictionaryValue* NetLogTempFile::GetState() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ base::DictionaryValue* dict = new base::DictionaryValue;
+
+ EnsureInit();
+
+#ifndef NDEBUG
+ dict->SetString("file", log_path_.LossyDisplayName());
+#endif // NDEBUG
+
+ switch (state_) {
+ case STATE_NOT_LOGGING:
+ dict->SetString("state", "NOT_LOGGING");
+ break;
+ case STATE_LOGGING:
+ dict->SetString("state", "LOGGING");
+ break;
+ case STATE_UNINITIALIZED:
+ dict->SetString("state", "UNINITIALIZED");
+ break;
+ }
+
+ switch (log_type_) {
+ case LOG_TYPE_NONE:
+ dict->SetString("logType", "NONE");
+ break;
+ case LOG_TYPE_UNKNOWN:
+ dict->SetString("logType", "UNKNOWN");
+ break;
+ case LOG_TYPE_LOG_BYTES:
+ dict->SetString("logType", "LOG_BYTES");
+ break;
+ case LOG_TYPE_NORMAL:
+ dict->SetString("logType", "NORMAL");
+ break;
+ case LOG_TYPE_STRIP_PRIVATE_DATA:
+ dict->SetString("logType", "STRIP_PRIVATE_DATA");
+ break;
+ }
+
+ return dict;
+}
+
+NetLogTempFile::NetLogTempFile(
+ ChromeNetLog* chrome_net_log,
+ const base::CommandLine::StringType& command_line_string,
+ const std::string& channel_string)
+ : state_(STATE_UNINITIALIZED),
+ log_type_(LOG_TYPE_NONE),
+ chrome_net_log_(chrome_net_log),
+ command_line_string_(command_line_string),
+ channel_string_(channel_string) {
+ // NetLogTempFile can be created on one thread and used on another.
+ thread_checker_.DetachFromThread();
+}
+
+bool NetLogTempFile::GetNetExportLogBaseDirectory(base::FilePath* path) const {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ return base::GetTempDir(path);
+}
+
+net::NetLogCaptureMode NetLogTempFile::GetCaptureModeForLogType(
+ LogType log_type) {
+ switch (log_type) {
+ case LOG_TYPE_LOG_BYTES:
+ return net::NetLogCaptureMode::IncludeSocketBytes();
+ case LOG_TYPE_NORMAL:
+ return net::NetLogCaptureMode::IncludeCookiesAndCredentials();
+ case LOG_TYPE_STRIP_PRIVATE_DATA:
+ return net::NetLogCaptureMode::Default();
+ case LOG_TYPE_NONE:
+ case LOG_TYPE_UNKNOWN:
+ NOTREACHED();
+ }
+ return net::NetLogCaptureMode::Default();
+}
+
+bool NetLogTempFile::EnsureInit() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (state_ != STATE_UNINITIALIZED)
+ return true;
+
+ if (!SetUpNetExportLogPath())
+ return false;
+
+ state_ = STATE_NOT_LOGGING;
+ if (NetExportLogExists())
+ log_type_ = LOG_TYPE_UNKNOWN;
+ else
+ log_type_ = LOG_TYPE_NONE;
+
+ return true;
+}
+
+void NetLogTempFile::StartNetLog(LogType log_type) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (state_ == STATE_LOGGING)
+ return;
+
+ DCHECK_NE(STATE_UNINITIALIZED, state_);
+ DCHECK(!log_path_.empty());
+
+ // Try to make sure we can create the file.
+ // TODO(rtenneti): Find a better for doing the following. Surface some error
+ // to the user if we couldn't create the file.
+ base::ScopedFILE file(base::OpenFile(log_path_, "w"));
+ if (!file)
+ return;
+
+ log_type_ = log_type;
+ state_ = STATE_LOGGING;
+
+ scoped_ptr<base::Value> constants(
+ ChromeNetLog::GetConstants(command_line_string_, channel_string_));
+ write_to_file_observer_.reset(new net::WriteToFileNetLogObserver());
+ write_to_file_observer_->set_capture_mode(GetCaptureModeForLogType(log_type));
+ write_to_file_observer_->StartObserving(chrome_net_log_, std::move(file),
+ constants.get(), nullptr);
+}
+
+void NetLogTempFile::StopNetLog() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (state_ != STATE_LOGGING)
+ return;
+
+ write_to_file_observer_->StopObserving(nullptr);
+ write_to_file_observer_.reset();
+ state_ = STATE_NOT_LOGGING;
+}
+
+bool NetLogTempFile::SetUpNetExportLogPath() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ base::FilePath temp_dir;
+ if (!GetNetExportLogBaseDirectory(&temp_dir))
+ return false;
+
+ // Delete log file at old location, if present.
+ DeleteFile(temp_dir.Append(kOldLogRelativePath), false);
+
+ base::FilePath log_path = temp_dir.Append(kLogRelativePath);
+
+ if (!base::CreateDirectoryAndGetError(log_path.DirName(), nullptr)) {
+ return false;
+ }
+
+ log_path_ = log_path;
+ return true;
+}
+
+bool NetLogTempFile::NetExportLogExists() const {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(!log_path_.empty());
+ return base::PathExists(log_path_);
+}
+
+} // namespace net_log
diff --git a/chromium/components/net_log/net_log_temp_file.h b/chromium/components/net_log/net_log_temp_file.h
new file mode 100644
index 00000000000..48522fa1eae
--- /dev/null
+++ b/chromium/components/net_log/net_log_temp_file.h
@@ -0,0 +1,174 @@
+// Copyright (c) 2013 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.
+
+#ifndef COMPONENTS_NET_LOG_NET_LOG_TEMP_FILE_H_
+#define COMPONENTS_NET_LOG_NET_LOG_TEMP_FILE_H_
+
+#include <string>
+
+#include "base/command_line.h"
+#include "base/files/file_path.h"
+#include "base/gtest_prod_util.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/threading/thread_checker.h"
+#include "net/log/net_log.h"
+
+namespace base {
+class DictionaryValue;
+}
+
+namespace net {
+class WriteToFileNetLogObserver;
+}
+
+namespace net_log {
+
+class ChromeNetLog;
+
+// NetLogTempFile logs all the NetLog entries into a temporary file
+// "chrome-net-export-log.json" created in base::GetTempDir() directory.
+//
+// NetLogTempFile maintains the current logging state (state_) and log file type
+// (log_type_) of the logging into a chrome-net-export-log.json file.
+//
+// The following are the possible states
+// a) Only Start is allowed (STATE_NOT_LOGGING, LOG_TYPE_NONE).
+// b) Only Stop is allowed (STATE_LOGGING).
+// c) Either Send or Start is allowed (STATE_NOT_LOGGING, anything but
+// LOG_TYPE_NONE).
+//
+// This is created/destroyed on the main thread, but all other function calls
+// occur on a background thread.
+//
+// This relies on the UI thread outlasting all other threads for thread safety.
+class NetLogTempFile {
+ public:
+ // This enum lists the UI button commands it could receive.
+ enum Command {
+ DO_START_LOG_BYTES, // Call StartNetLog logging all bytes received.
+ DO_START, // Call StartNetLog.
+ DO_START_STRIP_PRIVATE_DATA, // Call StartNetLog stripping private data.
+ DO_STOP, // Call StopNetLog.
+ };
+
+ virtual ~NetLogTempFile();
+
+ // Accepts the button command and executes it.
+ void ProcessCommand(Command command);
+
+ // Returns true and the path to the temporary file. If there is no file to
+ // send, then it returns false. It also returns false when actively logging to
+ // the file.
+ bool GetFilePath(base::FilePath* path);
+
+ // Creates a Value summary of the state of the NetLogTempFile. The caller is
+ // responsible for deleting the returned value.
+ base::DictionaryValue* GetState();
+
+ protected:
+ // Constructs a NetLogTempFile. Only one instance is created in browser
+ // process.
+ NetLogTempFile(ChromeNetLog* chrome_net_log,
+ const base::CommandLine::StringType& command_line_string,
+ const std::string& channel_string);
+
+ // Returns path name to base::GetTempDir() directory. Returns false if
+ // base::GetTempDir() fails.
+ virtual bool GetNetExportLogBaseDirectory(base::FilePath* path) const;
+
+ private:
+ friend class ChromeNetLog;
+ friend class NetLogTempFileTest;
+
+ // Allow tests to access our innards for testing purposes.
+ FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, EnsureInitFailure);
+ FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, EnsureInitAllowStart);
+ FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, EnsureInitAllowStartOrSend);
+ FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, ProcessCommandDoStartAndStop);
+ FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, DoStartClearsFile);
+ FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, CheckAddEvent);
+
+ // This enum lists the possible state NetLogTempFile could be in. It is used
+ // to enable/disable "Start", "Stop" and "Send" (email) UI actions.
+ enum State {
+ STATE_UNINITIALIZED,
+ // Not currently logging to file.
+ STATE_NOT_LOGGING,
+ // Currently logging to file.
+ STATE_LOGGING,
+ };
+
+ // The type of the current log file on disk.
+ enum LogType {
+ // There is no current log file.
+ LOG_TYPE_NONE,
+ // The file predates this session. May or may not have private data.
+ // TODO(davidben): This state is kind of silly.
+ LOG_TYPE_UNKNOWN,
+ // The log includes raw bytes.
+ LOG_TYPE_LOG_BYTES,
+ // The file includes all data.
+ LOG_TYPE_NORMAL,
+ // The file has credentials and cookies stripped.
+ LOG_TYPE_STRIP_PRIVATE_DATA,
+ };
+
+ // Returns the NetLog::CaptureMode corresponding to a LogType.
+ static net::NetLogCaptureMode GetCaptureModeForLogType(LogType log_type);
+
+ // Initializes the |state_| to STATE_NOT_LOGGING and |log_type_| to
+ // LOG_TYPE_NONE (if there is no temporary file from earlier run) or
+ // LOG_TYPE_UNKNOWN (if there is a temporary file from earlier run). Returns
+ // false if initialization of |log_path_| fails.
+ bool EnsureInit();
+
+ // Start collecting NetLog data into chrome-net-export-log.json file in
+ // base::GetTempDir() directory, using the specified capture mode. It is a
+ // no-op if we are already collecting data into a file, and |capture_mode| is
+ // ignored.
+ // TODO(mmenke): That's rather weird behavior, think about improving it.
+ void StartNetLog(LogType log_type);
+
+ // Stop collecting NetLog data into the temporary file. It is a no-op if we
+ // are not collecting data into a file.
+ void StopNetLog();
+
+ // Updates |log_path_| to be the base::FilePath to use for log files, which
+ // will be inside the base::GetTempDir() directory. Returns false if
+ // base::GetTempDir() fails, or unable to create a subdirectory for logging
+ // withinh that directory.
+ bool SetUpNetExportLogPath();
+
+ // Returns true if a file exists at |log_path_|.
+ bool NetExportLogExists() const;
+
+ base::ThreadChecker thread_checker_;
+
+ // Helper function for unit tests.
+ State state() const { return state_; }
+ LogType log_type() const { return log_type_; }
+
+ State state_; // Current state of NetLogTempFile.
+ LogType log_type_; // Type of current log file on disk.
+
+ base::FilePath log_path_; // base::FilePath to the temporary file.
+
+ // |write_to_file_observer_| watches the NetLog event stream, and
+ // sends all entries to the file created in StartNetLog().
+ scoped_ptr<net::WriteToFileNetLogObserver> write_to_file_observer_;
+
+ // The |chrome_net_log_| is owned by the browser process, cached here to avoid
+ // using global (g_browser_process).
+ ChromeNetLog* chrome_net_log_;
+
+ const base::CommandLine::StringType command_line_string_;
+ const std::string channel_string_;
+
+ DISALLOW_COPY_AND_ASSIGN(NetLogTempFile);
+};
+
+} // namespace net_log
+
+#endif // COMPONENTS_NET_LOG_NET_LOG_TEMP_FILE_H_
diff --git a/chromium/components/net_log/net_log_temp_file_unittest.cc b/chromium/components/net_log/net_log_temp_file_unittest.cc
new file mode 100644
index 00000000000..86b2eb33d29
--- /dev/null
+++ b/chromium/components/net_log/net_log_temp_file_unittest.cc
@@ -0,0 +1,393 @@
+// Copyright (c) 2013 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 "components/net_log/net_log_temp_file.h"
+
+#include <stdint.h>
+
+#include "base/command_line.h"
+#include "base/files/file_path.h"
+#include "base/files/file_util.h"
+#include "base/files/scoped_file.h"
+#include "base/files/scoped_temp_dir.h"
+#include "base/json/json_reader.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/message_loop/message_loop.h"
+#include "base/values.h"
+#include "build/build_config.h"
+#include "components/net_log/chrome_net_log.h"
+#include "net/log/net_log_capture_mode.h"
+#include "net/log/write_to_file_net_log_observer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+const char kChannelString[] = "SomeChannel";
+
+} // namespace
+
+namespace net_log {
+
+class TestNetLogTempFile : public NetLogTempFile {
+ public:
+ explicit TestNetLogTempFile(ChromeNetLog* chrome_net_log)
+ : NetLogTempFile(
+ chrome_net_log,
+ base::CommandLine::ForCurrentProcess()->GetCommandLineString(),
+ kChannelString),
+ lie_about_net_export_log_directory_(false) {
+ EXPECT_TRUE(net_log_temp_dir_.CreateUniqueTempDir());
+ }
+
+ ~TestNetLogTempFile() override { EXPECT_TRUE(net_log_temp_dir_.Delete()); }
+
+ // NetLogTempFile implementation:
+ bool GetNetExportLogBaseDirectory(base::FilePath* path) const override {
+ if (lie_about_net_export_log_directory_)
+ return false;
+ *path = net_log_temp_dir_.path();
+ return true;
+ }
+
+ void set_lie_about_net_export_log_directory(
+ bool lie_about_net_export_log_directory) {
+ lie_about_net_export_log_directory_ = lie_about_net_export_log_directory;
+ }
+
+ private:
+ bool lie_about_net_export_log_directory_;
+
+ base::ScopedTempDir net_log_temp_dir_;
+};
+
+class NetLogTempFileTest : public ::testing::Test {
+ public:
+ NetLogTempFileTest()
+ : net_log_(new ChromeNetLog(
+ base::FilePath(),
+ net::NetLogCaptureMode::Default(),
+ base::CommandLine::ForCurrentProcess()->GetCommandLineString(),
+ kChannelString)),
+ net_log_temp_file_(new TestNetLogTempFile(net_log_.get())) {
+ EXPECT_TRUE(net_log_temp_file_->SetUpNetExportLogPath());
+ net_export_log_ = net_log_temp_file_->log_path_;
+ }
+
+ std::string GetStateString() const {
+ scoped_ptr<base::DictionaryValue> dict(net_log_temp_file_->GetState());
+ std::string state;
+ EXPECT_TRUE(dict->GetString("state", &state));
+ return state;
+ }
+
+ std::string GetLogTypeString() const {
+ scoped_ptr<base::DictionaryValue> dict(net_log_temp_file_->GetState());
+ std::string log_type;
+ EXPECT_TRUE(dict->GetString("logType", &log_type));
+ return log_type;
+ }
+
+ // Make sure the export file has been created and is non-empty, as net
+ // constants will always be written to it on creation.
+ void VerifyNetExportLogExists() const {
+ EXPECT_EQ(net_export_log_, net_log_temp_file_->log_path_);
+ ASSERT_TRUE(base::PathExists(net_export_log_));
+
+ int64_t file_size;
+ // base::GetFileSize returns proper file size on open handles.
+ ASSERT_TRUE(base::GetFileSize(net_export_log_, &file_size));
+ EXPECT_GT(file_size, 0);
+ }
+
+ // Make sure the export file has been created and a valid JSON file. This
+ // should always be the case once logging has been stopped.
+ void VerifyNetExportLogComplete() const {
+ VerifyNetExportLogExists();
+
+ std::string log;
+ ASSERT_TRUE(ReadFileToString(net_export_log_, &log));
+ base::JSONReader reader;
+ scoped_ptr<base::Value> json = base::JSONReader::Read(log);
+ EXPECT_TRUE(json);
+ }
+
+ // Verify state and GetFilePath return correct values if EnsureInit() fails.
+ void VerifyFilePathAndStateAfterEnsureInitFailure() {
+ EXPECT_EQ("UNINITIALIZED", GetStateString());
+ EXPECT_EQ(NetLogTempFile::STATE_UNINITIALIZED, net_log_temp_file_->state());
+
+ base::FilePath net_export_file_path;
+ EXPECT_FALSE(net_log_temp_file_->GetFilePath(&net_export_file_path));
+ }
+
+ // When we lie in NetExportLogExists, make sure state and GetFilePath return
+ // correct values.
+ void VerifyFilePathAndStateAfterEnsureInit() {
+ EXPECT_EQ("NOT_LOGGING", GetStateString());
+ EXPECT_EQ(NetLogTempFile::STATE_NOT_LOGGING, net_log_temp_file_->state());
+ EXPECT_EQ("NONE", GetLogTypeString());
+ EXPECT_EQ(NetLogTempFile::LOG_TYPE_NONE, net_log_temp_file_->log_type());
+
+ base::FilePath net_export_file_path;
+ EXPECT_FALSE(net_log_temp_file_->GetFilePath(&net_export_file_path));
+ EXPECT_FALSE(net_log_temp_file_->NetExportLogExists());
+ }
+
+ // The following methods make sure the export file has been successfully
+ // initialized by a DO_START command of the given type.
+
+ void VerifyFileAndStateAfterDoStart() {
+ VerifyFileAndStateAfterStart(
+ NetLogTempFile::LOG_TYPE_NORMAL, "NORMAL",
+ net::NetLogCaptureMode::IncludeCookiesAndCredentials());
+ }
+
+ void VerifyFileAndStateAfterDoStartStripPrivateData() const {
+ VerifyFileAndStateAfterStart(NetLogTempFile::LOG_TYPE_STRIP_PRIVATE_DATA,
+ "STRIP_PRIVATE_DATA",
+ net::NetLogCaptureMode::Default());
+ }
+
+ void VerifyFileAndStateAfterDoStartLogBytes() const {
+ VerifyFileAndStateAfterStart(NetLogTempFile::LOG_TYPE_LOG_BYTES,
+ "LOG_BYTES",
+ net::NetLogCaptureMode::IncludeSocketBytes());
+ }
+
+ // Make sure the export file has been successfully initialized after DO_STOP
+ // command following a DO_START command of the given type.
+
+ void VerifyFileAndStateAfterDoStop() const {
+ VerifyFileAndStateAfterDoStop(NetLogTempFile::LOG_TYPE_NORMAL, "NORMAL");
+ }
+
+ void VerifyFileAndStateAfterDoStopWithStripPrivateData() const {
+ VerifyFileAndStateAfterDoStop(NetLogTempFile::LOG_TYPE_STRIP_PRIVATE_DATA,
+ "STRIP_PRIVATE_DATA");
+ }
+
+ void VerifyFileAndStateAfterDoStopWithLogBytes() const {
+ VerifyFileAndStateAfterDoStop(NetLogTempFile::LOG_TYPE_LOG_BYTES,
+ "LOG_BYTES");
+ }
+
+ scoped_ptr<ChromeNetLog> net_log_;
+ // |net_log_temp_file_| is initialized after |net_log_| so that it can stop
+ // obvserving on destruction.
+ scoped_ptr<TestNetLogTempFile> net_log_temp_file_;
+ base::FilePath net_export_log_;
+
+ private:
+ // Checks state after one of the DO_START* commands.
+ void VerifyFileAndStateAfterStart(
+ NetLogTempFile::LogType expected_log_type,
+ const std::string& expected_log_type_string,
+ net::NetLogCaptureMode expected_capture_mode) const {
+ EXPECT_EQ(NetLogTempFile::STATE_LOGGING, net_log_temp_file_->state());
+ EXPECT_EQ("LOGGING", GetStateString());
+ EXPECT_EQ(expected_log_type, net_log_temp_file_->log_type());
+ EXPECT_EQ(expected_log_type_string, GetLogTypeString());
+ EXPECT_EQ(expected_capture_mode,
+ net_log_temp_file_->write_to_file_observer_->capture_mode());
+
+ // Check GetFilePath returns false when still writing to the file.
+ base::FilePath net_export_file_path;
+ EXPECT_FALSE(net_log_temp_file_->GetFilePath(&net_export_file_path));
+
+ VerifyNetExportLogExists();
+ }
+
+ void VerifyFileAndStateAfterDoStop(
+ NetLogTempFile::LogType expected_log_type,
+ const std::string& expected_log_type_string) const {
+ EXPECT_EQ(NetLogTempFile::STATE_NOT_LOGGING, net_log_temp_file_->state());
+ EXPECT_EQ("NOT_LOGGING", GetStateString());
+ EXPECT_EQ(expected_log_type, net_log_temp_file_->log_type());
+ EXPECT_EQ(expected_log_type_string, GetLogTypeString());
+
+ base::FilePath net_export_file_path;
+ EXPECT_TRUE(net_log_temp_file_->GetFilePath(&net_export_file_path));
+ EXPECT_EQ(net_export_log_, net_export_file_path);
+
+ VerifyNetExportLogComplete();
+ }
+
+ base::MessageLoop message_loop_;
+};
+
+TEST_F(NetLogTempFileTest, EnsureInitFailure) {
+ net_log_temp_file_->set_lie_about_net_export_log_directory(true);
+
+ EXPECT_FALSE(net_log_temp_file_->EnsureInit());
+ VerifyFilePathAndStateAfterEnsureInitFailure();
+
+ net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_START);
+ VerifyFilePathAndStateAfterEnsureInitFailure();
+}
+
+TEST_F(NetLogTempFileTest, EnsureInitAllowStart) {
+ EXPECT_TRUE(net_log_temp_file_->EnsureInit());
+ VerifyFilePathAndStateAfterEnsureInit();
+
+ // Calling EnsureInit() second time should be a no-op.
+ EXPECT_TRUE(net_log_temp_file_->EnsureInit());
+ VerifyFilePathAndStateAfterEnsureInit();
+
+ // GetFilePath() should failed when there's no temp file.
+ base::FilePath net_export_file_path;
+ EXPECT_FALSE(net_log_temp_file_->GetFilePath(&net_export_file_path));
+}
+
+TEST_F(NetLogTempFileTest, EnsureInitAllowStartOrSend) {
+ // Create and close an empty log file, to simulate an old log file already
+ // existing.
+ base::ScopedFILE created_file(base::OpenFile(net_export_log_, "w"));
+ ASSERT_TRUE(created_file.get());
+ created_file.reset();
+
+ EXPECT_TRUE(net_log_temp_file_->EnsureInit());
+
+ EXPECT_EQ("NOT_LOGGING", GetStateString());
+ EXPECT_EQ(NetLogTempFile::STATE_NOT_LOGGING, net_log_temp_file_->state());
+ EXPECT_EQ("UNKNOWN", GetLogTypeString());
+ EXPECT_EQ(NetLogTempFile::LOG_TYPE_UNKNOWN, net_log_temp_file_->log_type());
+ EXPECT_EQ(net_export_log_, net_log_temp_file_->log_path_);
+ EXPECT_TRUE(base::PathExists(net_export_log_));
+
+ base::FilePath net_export_file_path;
+ EXPECT_TRUE(net_log_temp_file_->GetFilePath(&net_export_file_path));
+ EXPECT_TRUE(base::PathExists(net_export_file_path));
+ EXPECT_EQ(net_export_log_, net_export_file_path);
+}
+
+TEST_F(NetLogTempFileTest, ProcessCommandDoStartAndStop) {
+ net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_START);
+ VerifyFileAndStateAfterDoStart();
+
+ // Calling a second time should be a no-op.
+ net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_START);
+ VerifyFileAndStateAfterDoStart();
+
+ // starting with other log levels should also be no-ops.
+ net_log_temp_file_->ProcessCommand(
+ NetLogTempFile::DO_START_STRIP_PRIVATE_DATA);
+ VerifyFileAndStateAfterDoStart();
+ net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_START_LOG_BYTES);
+ VerifyFileAndStateAfterDoStart();
+
+ net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP);
+ VerifyFileAndStateAfterDoStop();
+
+ // Calling DO_STOP second time should be a no-op.
+ net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP);
+ VerifyFileAndStateAfterDoStop();
+}
+
+TEST_F(NetLogTempFileTest,
+ ProcessCommandDoStartAndStopWithPrivateDataStripping) {
+ net_log_temp_file_->ProcessCommand(
+ NetLogTempFile::DO_START_STRIP_PRIVATE_DATA);
+ VerifyFileAndStateAfterDoStartStripPrivateData();
+
+ // Calling a second time should be a no-op.
+ net_log_temp_file_->ProcessCommand(
+ NetLogTempFile::DO_START_STRIP_PRIVATE_DATA);
+ VerifyFileAndStateAfterDoStartStripPrivateData();
+
+ net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP);
+ VerifyFileAndStateAfterDoStopWithStripPrivateData();
+
+ // Calling DO_STOP second time should be a no-op.
+ net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP);
+ VerifyFileAndStateAfterDoStopWithStripPrivateData();
+}
+
+TEST_F(NetLogTempFileTest, ProcessCommandDoStartAndStopWithByteLogging) {
+ net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_START_LOG_BYTES);
+ VerifyFileAndStateAfterDoStartLogBytes();
+
+ // Calling a second time should be a no-op.
+ net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_START_LOG_BYTES);
+ VerifyFileAndStateAfterDoStartLogBytes();
+
+ net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP);
+ VerifyFileAndStateAfterDoStopWithLogBytes();
+
+ // Calling DO_STOP second time should be a no-op.
+ net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP);
+ VerifyFileAndStateAfterDoStopWithLogBytes();
+}
+
+TEST_F(NetLogTempFileTest, DoStartClearsFile) {
+ // Verify file sizes after two consecutive starts/stops are the same (even if
+ // we add some junk data in between).
+ net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_START);
+ VerifyFileAndStateAfterDoStart();
+
+ int64_t start_file_size;
+ EXPECT_TRUE(base::GetFileSize(net_export_log_, &start_file_size));
+
+ net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP);
+ VerifyFileAndStateAfterDoStop();
+
+ int64_t stop_file_size;
+ EXPECT_TRUE(base::GetFileSize(net_export_log_, &stop_file_size));
+ EXPECT_GE(stop_file_size, start_file_size);
+
+ // Add some junk at the end of the file.
+ std::string junk_data("Hello");
+ EXPECT_TRUE(
+ base::AppendToFile(net_export_log_, junk_data.c_str(), junk_data.size()));
+
+ int64_t junk_file_size;
+ EXPECT_TRUE(base::GetFileSize(net_export_log_, &junk_file_size));
+ EXPECT_GT(junk_file_size, stop_file_size);
+
+ // Execute DO_START/DO_STOP commands and make sure the file is back to the
+ // size before addition of junk data.
+ net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_START);
+ VerifyFileAndStateAfterDoStart();
+
+ int64_t new_start_file_size;
+ EXPECT_TRUE(base::GetFileSize(net_export_log_, &new_start_file_size));
+ EXPECT_EQ(new_start_file_size, start_file_size);
+
+ net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP);
+ VerifyFileAndStateAfterDoStop();
+
+ int64_t new_stop_file_size;
+ EXPECT_TRUE(base::GetFileSize(net_export_log_, &new_stop_file_size));
+ EXPECT_EQ(new_stop_file_size, stop_file_size);
+}
+
+TEST_F(NetLogTempFileTest, CheckAddEvent) {
+ // Add an event to |net_log_| and then test to make sure that, after we stop
+ // logging, the file is larger than the file created without that event.
+ net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_START);
+ VerifyFileAndStateAfterDoStart();
+
+ // Get file size without the event.
+ net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP);
+ VerifyFileAndStateAfterDoStop();
+
+ int64_t stop_file_size;
+ EXPECT_TRUE(base::GetFileSize(net_export_log_, &stop_file_size));
+
+ // Perform DO_START and add an Event and then DO_STOP and then compare
+ // file sizes.
+ net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_START);
+ VerifyFileAndStateAfterDoStart();
+
+ // Log an event.
+ net_log_->AddGlobalEntry(net::NetLog::TYPE_CANCELLED);
+
+ net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP);
+ VerifyFileAndStateAfterDoStop();
+
+ int64_t new_stop_file_size;
+ EXPECT_TRUE(base::GetFileSize(net_export_log_, &new_stop_file_size));
+ EXPECT_GE(new_stop_file_size, stop_file_size);
+}
+
+} // namespace net_log
diff --git a/chromium/components/net_log/resources/net_export.css b/chromium/components/net_log/resources/net_export.css
new file mode 100644
index 00000000000..0fae6394a3d
--- /dev/null
+++ b/chromium/components/net_log/resources/net_export.css
@@ -0,0 +1,36 @@
+/* Copyright (c) 2013 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.
+ */
+
+body {
+ font-size: 80%;
+}
+
+button {
+ display: block;
+ font-size: 110%;
+ font-weight: bold;
+ margin: 10px auto;
+ min-height: 48px;
+ width: 200px;
+}
+
+.radio-button-div {
+ margin: 7px auto;
+}
+
+.warning {
+ color: red;
+ font-size: 90%;
+ font-weight: normal;
+}
+
+#net-export-main {
+ margin: 8px;
+}
+
+#export-view-file-path-text {
+ white-space: pre-wrap;
+ word-wrap: break-word;
+}
diff --git a/chromium/components/net_log/resources/net_export.html b/chromium/components/net_log/resources/net_export.html
new file mode 100644
index 00000000000..0aefeb70664
--- /dev/null
+++ b/chromium/components/net_log/resources/net_export.html
@@ -0,0 +1,90 @@
+<!doctype html>
+<html>
+<head>
+<meta charset="utf-8">
+<if expr="is_android">
+<meta name="viewport" content="width=device-width">
+</if>
+
+<if expr="is_ios">
+<!-- TODO(crbug.com/487000): Remove this once injected by web. -->
+<script src="chrome://resources/js/ios/web_ui.js"></script>
+</if>
+
+<script src="chrome://resources/js/util.js"></script>
+<script src="chrome://resources/js/cr.js"></script>
+<script src="chrome://net-export/net_export.js"></script>
+<link rel="stylesheet" href="chrome://resources/css/text_defaults.css">
+<link rel="stylesheet" href="net_export.css">
+</head>
+<body>
+ <h2>Network Log Export</h2>
+ <div id="net-export-main">
+ <div>
+ <button id="export-view-start-data" disabled>
+ Start Logging to Disk
+ <div class="warning" id="export-view-deletes-log-text" hidden>
+ Deletes old log
+ </div>
+ </button>
+ </div>
+ <div>
+ <button id="export-view-stop-data" disabled>Stop Logging</button>
+ </div>
+ <div>
+ <button id="export-view-send-data" disabled>
+ Email Log
+ <div class="warning" id="export-view-private-data-text" hidden>
+ Log contains private information
+ </div>
+ <div class="warning" id="export-view-send-old-log-text" hidden>
+ Log file from previous session
+ </div>
+ </button>
+ </div>
+ <p>
+ <b>INSTRUCTIONS</b>: Start logging, reproduce the problem,
+ and then stop logging. Make sure to send the email before
+ starting to log again. Otherwise, the log will be deleted.
+ </p>
+ <p>
+ Logs can be loaded in
+ <a href="chrome://net-internals" target="_blank">net-internals</a>
+ of desktop Chrome.
+ </p>
+ <p>
+ <b><span class="warning">WARNING</span></b>: Logs contain a list of sites
+ visited from when logging started to when logging stopped. They may also
+ contain general network configuration information, such as DNS and proxy
+ configuration. If private information is not stripped, the logs also
+ contain cookies and credentials.
+ </p>
+ <p>
+ <b>ADVANCED</b>:
+ <span class="warning">This section should normally be left alone.</span>
+ <div class="radio-button-div">
+ <label>
+ <input id="export-view-strip-private-data-button" type="radio"
+ name="log-mode" value="STRIP_PRIVATE_DATA" checked disabled>
+ Strip private information
+ </label>
+ </div>
+ <div class="radio-button-div">
+ <label>
+ <input id="export-view-include-private-data-button" type="radio"
+ name="log-mode" value="NORMAL" disabled>
+ Include cookies and credentials
+ </label>
+ </div>
+ <div class="radio-button-div">
+ <label>
+ <input id="export-view-log-bytes-button" type="radio"
+ name="log-mode" value="LOG_BYTES" disabled>
+ Include raw bytes (will include cookies and credentials)
+ </label>
+ </div>
+ </p>
+ </div>
+ <pre id="export-view-file-path-text"></pre>
+</body>
+</html>
diff --git a/chromium/components/net_log/resources/net_export.js b/chromium/components/net_log/resources/net_export.js
new file mode 100644
index 00000000000..702b22e5835
--- /dev/null
+++ b/chromium/components/net_log/resources/net_export.js
@@ -0,0 +1,124 @@
+// Copyright (c) 2013 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.
+
+/**
+ * Main entry point called once the page has loaded.
+ */
+function onLoad() {
+ NetExportView.getInstance();
+}
+
+document.addEventListener('DOMContentLoaded', onLoad);
+
+/**
+ * This class handles the presentation of our profiler view. Used as a
+ * singleton.
+ */
+var NetExportView = (function() {
+ 'use strict';
+
+ /**
+ * Delay in milliseconds between updates of certain browser information.
+ */
+ /** @const */ var POLL_INTERVAL_MS = 5000;
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * @constructor
+ */
+ function NetExportView() {
+ $('export-view-start-data').onclick = this.onStartData_.bind(this);
+ $('export-view-stop-data').onclick = this.onStopData_.bind(this);
+ $('export-view-send-data').onclick = this.onSendData_.bind(this);
+
+ window.setInterval(function() { chrome.send('getExportNetLogInfo'); },
+ POLL_INTERVAL_MS);
+
+ chrome.send('getExportNetLogInfo');
+ }
+
+ cr.addSingletonGetter(NetExportView);
+
+ NetExportView.prototype = {
+ /**
+ * Starts saving NetLog data to a file.
+ */
+ onStartData_: function() {
+ var logMode =
+ document.querySelector('input[name="log-mode"]:checked').value;
+ chrome.send('startNetLog', [logMode]);
+ },
+
+ /**
+ * Stops saving NetLog data to a file.
+ */
+ onStopData_: function() {
+ chrome.send('stopNetLog');
+ },
+
+ /**
+ * Sends NetLog data via email from browser.
+ */
+ onSendData_: function() {
+ chrome.send('sendNetLog');
+ },
+
+ /**
+ * Updates the UI to reflect the current state. Displays the path name of
+ * the file where NetLog data is collected.
+ */
+ onExportNetLogInfoChanged: function(exportNetLogInfo) {
+ if (exportNetLogInfo.file) {
+ var message = '';
+ if (exportNetLogInfo.state == 'LOGGING')
+ message = 'NetLog data is collected in: ';
+ else if (exportNetLogInfo.logType != 'NONE')
+ message = 'NetLog data to send is in: ';
+ $('export-view-file-path-text').textContent =
+ message + exportNetLogInfo.file;
+ } else {
+ $('export-view-file-path-text').textContent = '';
+ }
+
+ // Disable all controls. Useable controls are enabled below.
+ var controls = document.querySelectorAll('button, input');
+ for (var i = 0; i < controls.length; ++i) {
+ controls[i].disabled = true;
+ }
+
+ $('export-view-deletes-log-text').hidden = true;
+ $('export-view-private-data-text').hidden = true;
+ $('export-view-send-old-log-text').hidden = true;
+ if (exportNetLogInfo.state == 'NOT_LOGGING') {
+ // Allow making a new log.
+ $('export-view-strip-private-data-button').disabled = false;
+ $('export-view-include-private-data-button').disabled = false;
+ $('export-view-log-bytes-button').disabled = false;
+ $('export-view-start-data').disabled = false;
+
+ // If there's an existing log, allow sending it.
+ if (exportNetLogInfo.logType != 'NONE') {
+ $('export-view-deletes-log-text').hidden = false;
+ $('export-view-send-data').disabled = false;
+ if (exportNetLogInfo.logType == 'UNKNOWN') {
+ $('export-view-send-old-log-text').hidden = false;
+ } else if (exportNetLogInfo.logType == 'NORMAL') {
+ $('export-view-private-data-text').hidden = false;
+ }
+ }
+ } else if (exportNetLogInfo.state == 'LOGGING') {
+ // Only possible to stop logging. Radio buttons reflects current state.
+ document.querySelector('input[name="log-mode"][value="' +
+ exportNetLogInfo.logType + '"]').checked = true;
+ $('export-view-stop-data').disabled = false;
+ } else if (exportNetLogInfo.state == 'UNINITIALIZED') {
+ $('export-view-file-path-text').textContent =
+ 'Unable to initialize NetLog data file.';
+ }
+ }
+ };
+
+ return NetExportView;
+})();