| Index: components/net_log/net_log_temp_file.cc
|
| diff --git a/chrome/browser/net/net_log_temp_file.cc b/components/net_log/net_log_temp_file.cc
|
| similarity index 73%
|
| rename from chrome/browser/net/net_log_temp_file.cc
|
| rename to components/net_log/net_log_temp_file.cc
|
| index c630174716d7e1acdb2a2a2b347d7924d0301eb1..a8073dd50b88cfd917e199c99a2ba1a14c4c1578 100644
|
| --- a/chrome/browser/net/net_log_temp_file.cc
|
| +++ b/components/net_log/net_log_temp_file.cc
|
| @@ -2,17 +2,16 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chrome/browser/net/net_log_temp_file.h"
|
| +#include "components/net_log/net_log_temp_file.h"
|
|
|
| +#include "base/files/file_path.h"
|
| #include "base/files/file_util.h"
|
| #include "base/files/scoped_file.h"
|
| #include "base/values.h"
|
| -#include "chrome/browser/net/chrome_net_log.h"
|
| -#include "chrome/browser/ui/webui/net_internals/net_internals_ui.h"
|
| -#include "content/public/browser/browser_thread.h"
|
| +#include "components/net_log/chrome_net_log.h"
|
| #include "net/log/write_to_file_net_log_observer.h"
|
|
|
| -using content::BrowserThread;
|
| +namespace net_log {
|
|
|
| // Path of logs relative to base::GetTempDir(). Must be kept in sync
|
| // with chrome/android/java/res/xml/file_paths.xml
|
| @@ -30,7 +29,7 @@ NetLogTempFile::~NetLogTempFile() {
|
| }
|
|
|
| void NetLogTempFile::ProcessCommand(Command command) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE_USER_BLOCKING);
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| if (!EnsureInit())
|
| return;
|
|
|
| @@ -54,7 +53,7 @@ void NetLogTempFile::ProcessCommand(Command command) {
|
| }
|
|
|
| bool NetLogTempFile::GetFilePath(base::FilePath* path) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE_USER_BLOCKING);
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| if (log_type_ == LOG_TYPE_NONE || state_ == STATE_LOGGING)
|
| return false;
|
|
|
| @@ -73,7 +72,7 @@ bool NetLogTempFile::GetFilePath(base::FilePath* path) {
|
| }
|
|
|
| base::DictionaryValue* NetLogTempFile::GetState() {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE_USER_BLOCKING);
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| base::DictionaryValue* dict = new base::DictionaryValue;
|
|
|
| EnsureInit();
|
| @@ -115,36 +114,42 @@ base::DictionaryValue* NetLogTempFile::GetState() {
|
| return dict;
|
| }
|
|
|
| -NetLogTempFile::NetLogTempFile(ChromeNetLog* chrome_net_log)
|
| +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) {
|
| + 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_CURRENTLY_ON(BrowserThread::FILE_USER_BLOCKING);
|
| +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();
|
| + 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_CURRENTLY_ON(BrowserThread::FILE_USER_BLOCKING);
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| if (state_ != STATE_UNINITIALIZED)
|
| return true;
|
|
|
| @@ -161,7 +166,7 @@ bool NetLogTempFile::EnsureInit() {
|
| }
|
|
|
| void NetLogTempFile::StartNetLog(LogType log_type) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE_USER_BLOCKING);
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| if (state_ == STATE_LOGGING)
|
| return;
|
|
|
| @@ -178,15 +183,16 @@ void NetLogTempFile::StartNetLog(LogType log_type) {
|
| log_type_ = log_type;
|
| state_ = STATE_LOGGING;
|
|
|
| - scoped_ptr<base::Value> constants(NetInternalsUI::GetConstants());
|
| + 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_, file.Pass(),
|
| - constants.get(), nullptr);
|
| + constants.get(), nullptr);
|
| }
|
|
|
| void NetLogTempFile::StopNetLog() {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE_USER_BLOCKING);
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| if (state_ != STATE_LOGGING)
|
| return;
|
|
|
| @@ -196,7 +202,7 @@ void NetLogTempFile::StopNetLog() {
|
| }
|
|
|
| bool NetLogTempFile::SetUpNetExportLogPath() {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE_USER_BLOCKING);
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| base::FilePath temp_dir;
|
| if (!GetNetExportLogBaseDirectory(&temp_dir))
|
| return false;
|
| @@ -206,8 +212,7 @@ bool NetLogTempFile::SetUpNetExportLogPath() {
|
|
|
| base::FilePath log_path = temp_dir.Append(kLogRelativePath);
|
|
|
| - if (!base::CreateDirectoryAndGetError(log_path.DirName(),
|
| - nullptr)) {
|
| + if (!base::CreateDirectoryAndGetError(log_path.DirName(), nullptr)) {
|
| return false;
|
| }
|
|
|
| @@ -216,7 +221,9 @@ bool NetLogTempFile::SetUpNetExportLogPath() {
|
| }
|
|
|
| bool NetLogTempFile::NetExportLogExists() const {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE_USER_BLOCKING);
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| DCHECK(!log_path_.empty());
|
| return base::PathExists(log_path_);
|
| }
|
| +
|
| +} // namespace net_log
|
|
|