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

Side by Side Diff: components/net_log/chrome_net_log.cc

Issue 1347043002: Move ChromeNetLog to //components (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DetachFromThread Created 5 years, 3 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
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/browser/net/chrome_net_log.h" 5 #include "components/net_log/chrome_net_log.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/scoped_file.h" 10 #include "base/files/scoped_file.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h"
14 #include "base/values.h" 12 #include "base/values.h"
15 #include "chrome/browser/net/net_log_temp_file.h" 13 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event _store.h"
16 #include "chrome/browser/ui/webui/net_internals/net_internals_ui.h" 14 #include "components/net_log/net_log_temp_file.h"
17 #include "chrome/common/chrome_switches.h" 15 #include "components/net_log/net_log_temp_file.h"
18 #include "content/public/common/content_switches.h" 16 #include "components/version_info/version_info.h"
17 #include "net/log/net_log_util.h"
19 #include "net/log/trace_net_log_observer.h" 18 #include "net/log/trace_net_log_observer.h"
20 #include "net/log/write_to_file_net_log_observer.h" 19 #include "net/log/write_to_file_net_log_observer.h"
21 20
22 namespace { 21 namespace net_log {
23 22
24 net::NetLogCaptureMode GetCaptureModeFromCommandLine( 23 ChromeNetLog::ChromeNetLog(const base::FilePath& log_file,
25 const base::CommandLine& command_line) { 24 net::NetLogCaptureMode log_file_mode,
26 if (command_line.HasSwitch(switches::kNetLogCaptureMode)) { 25 const std::string& channel_string)
27 std::string capture_mode_string = 26 : net_log_temp_file_(new NetLogTempFile(this, channel_string)) {
28 command_line.GetSwitchValueASCII(switches::kNetLogCaptureMode); 27 if (!log_file.empty()) {
29
30 if (capture_mode_string == "Default")
31 return net::NetLogCaptureMode::Default();
32 if (capture_mode_string == "IncludeCookiesAndCredentials")
33 return net::NetLogCaptureMode::IncludeCookiesAndCredentials();
34 if (capture_mode_string == "IncludeSocketBytes")
35 return net::NetLogCaptureMode::IncludeSocketBytes();
36
37 LOG(ERROR) << "Unrecognized value for --" << switches::kNetLogCaptureMode;
38 }
39
40 return net::NetLogCaptureMode::Default();
41 }
42
43 } // namespace
44
45 ChromeNetLog::ChromeNetLog()
46 : net_log_temp_file_(new NetLogTempFile(this)) {
47 const base::CommandLine& command_line =
48 *base::CommandLine::ForCurrentProcess();
49
50 if (command_line.HasSwitch(switches::kLogNetLog)) {
51 base::FilePath log_path =
52 command_line.GetSwitchValuePath(switches::kLogNetLog);
53 // Much like logging.h, bypass threading restrictions by using fopen 28 // Much like logging.h, bypass threading restrictions by using fopen
54 // directly. Have to write on a thread that's shutdown to handle events on 29 // directly. Have to write on a thread that's shutdown to handle events on
55 // shutdown properly, and posting events to another thread as they occur 30 // shutdown properly, and posting events to another thread as they occur
56 // would result in an unbounded buffer size, so not much can be gained by 31 // would result in an unbounded buffer size, so not much can be gained by
57 // doing this on another thread. It's only used when debugging Chrome, so 32 // doing this on another thread. It's only used when debugging Chrome, so
58 // performance is not a big concern. 33 // performance is not a big concern.
59 base::ScopedFILE file; 34 base::ScopedFILE file;
60 #if defined(OS_WIN) 35 #if defined(OS_WIN)
61 file.reset(_wfopen(log_path.value().c_str(), L"w")); 36 file.reset(_wfopen(log_file.value().c_str(), L"w"));
62 #elif defined(OS_POSIX) 37 #elif defined(OS_POSIX)
63 file.reset(fopen(log_path.value().c_str(), "w")); 38 file.reset(fopen(log_file.value().c_str(), "w"));
64 #endif 39 #endif
65 40
66 if (!file) { 41 if (!file) {
67 LOG(ERROR) << "Could not open file " << log_path.value() 42 LOG(ERROR) << "Could not open file " << log_file.value()
68 << " for net logging"; 43 << " for net logging";
69 } else { 44 } else {
70 scoped_ptr<base::Value> constants(NetInternalsUI::GetConstants()); 45 scoped_ptr<base::Value> constants(GetConstants(channel_string));
71 write_to_file_observer_.reset(new net::WriteToFileNetLogObserver()); 46 write_to_file_observer_.reset(new net::WriteToFileNetLogObserver());
72 47
73 net::NetLogCaptureMode capture_mode = 48 write_to_file_observer_->set_capture_mode(log_file_mode);
74 GetCaptureModeFromCommandLine(command_line);
75 write_to_file_observer_->set_capture_mode(capture_mode);
76 49
77 write_to_file_observer_->StartObserving(this, file.Pass(), 50 write_to_file_observer_->StartObserving(this, file.Pass(),
78 constants.get(), nullptr); 51 constants.get(), nullptr);
79 } 52 }
80 } 53 }
81 54
82 trace_net_log_observer_.reset(new net::TraceNetLogObserver()); 55 trace_net_log_observer_.reset(new net::TraceNetLogObserver());
83 trace_net_log_observer_->WatchForTraceStart(this); 56 trace_net_log_observer_->WatchForTraceStart(this);
84 } 57 }
85 58
86 ChromeNetLog::~ChromeNetLog() { 59 ChromeNetLog::~ChromeNetLog() {
87 net_log_temp_file_.reset(); 60 net_log_temp_file_.reset();
88 // Remove the observers we own before we're destroyed. 61 // Remove the observers we own before we're destroyed.
89 if (write_to_file_observer_) 62 if (write_to_file_observer_)
90 write_to_file_observer_->StopObserving(nullptr); 63 write_to_file_observer_->StopObserving(nullptr);
91 if (trace_net_log_observer_) 64 if (trace_net_log_observer_)
92 trace_net_log_observer_->StopWatchForTraceStart(); 65 trace_net_log_observer_->StopWatchForTraceStart();
93 } 66 }
94 67
68 // static
69 base::Value* ChromeNetLog::GetConstants(const std::string& channel_string) {
70 scoped_ptr<base::DictionaryValue> constants_dict = net::GetNetConstants();
71 DCHECK(constants_dict);
72
73 // Add a dictionary with the version of the client and its command line
74 // arguments.
75 {
76 base::DictionaryValue* dict = new base::DictionaryValue();
77
78 // We have everything we need to send the right values.
79 dict->SetString("name", version_info::GetProductName());
80 dict->SetString("version", version_info::GetVersionNumber());
81 dict->SetString("cl", version_info::GetLastChange());
82 dict->SetString("version_mod", channel_string);
83 dict->SetString("official", version_info::IsOfficialBuild() ? "official"
84 : "unofficial");
85 dict->SetString("os_type", version_info::GetOSType());
86 dict->SetString(
87 "command_line",
88 base::CommandLine::ForCurrentProcess()->GetCommandLineString());
eroman 2015/09/16 20:52:21 Same comment as earlier: Could you make this a par
droger 2015/09/17 08:39:10 I don't have a strong opinion. Done.
89
90 constants_dict->Set("clientInfo", dict);
91
92 data_reduction_proxy::DataReductionProxyEventStore::AddConstants(
droger 2015/09/17 08:39:10 Note: this is the dependency on DataReductionProxy
93 constants_dict.get());
94 }
95
96 return constants_dict.release();
97 }
98
99 } // namespace net_log
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698