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

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: Rebase 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
« no previous file with comments | « components/net_log/chrome_net_log.h ('k') | components/net_log/net_log_temp_file.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(
25 const base::CommandLine& command_line) { 24 const base::FilePath& log_file,
26 if (command_line.HasSwitch(switches::kNetLogCaptureMode)) { 25 net::NetLogCaptureMode log_file_mode,
27 std::string capture_mode_string = 26 const base::CommandLine::StringType& command_line_string,
28 command_line.GetSwitchValueASCII(switches::kNetLogCaptureMode); 27 const std::string& channel_string)
29 28 : net_log_temp_file_(
30 if (capture_mode_string == "Default") 29 new NetLogTempFile(this, command_line_string, channel_string)) {
31 return net::NetLogCaptureMode::Default(); 30 if (!log_file.empty()) {
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 31 // 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 32 // 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 33 // 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 34 // 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 35 // doing this on another thread. It's only used when debugging Chrome, so
58 // performance is not a big concern. 36 // performance is not a big concern.
59 base::ScopedFILE file; 37 base::ScopedFILE file;
60 #if defined(OS_WIN) 38 #if defined(OS_WIN)
61 file.reset(_wfopen(log_path.value().c_str(), L"w")); 39 file.reset(_wfopen(log_file.value().c_str(), L"w"));
62 #elif defined(OS_POSIX) 40 #elif defined(OS_POSIX)
63 file.reset(fopen(log_path.value().c_str(), "w")); 41 file.reset(fopen(log_file.value().c_str(), "w"));
64 #endif 42 #endif
65 43
66 if (!file) { 44 if (!file) {
67 LOG(ERROR) << "Could not open file " << log_path.value() 45 LOG(ERROR) << "Could not open file " << log_file.value()
68 << " for net logging"; 46 << " for net logging";
69 } else { 47 } else {
70 scoped_ptr<base::Value> constants(NetInternalsUI::GetConstants()); 48 scoped_ptr<base::Value> constants(
49 GetConstants(command_line_string, channel_string));
71 write_to_file_observer_.reset(new net::WriteToFileNetLogObserver()); 50 write_to_file_observer_.reset(new net::WriteToFileNetLogObserver());
72 51
73 net::NetLogCaptureMode capture_mode = 52 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 53
77 write_to_file_observer_->StartObserving(this, file.Pass(), 54 write_to_file_observer_->StartObserving(this, file.Pass(),
78 constants.get(), nullptr); 55 constants.get(), nullptr);
79 } 56 }
80 } 57 }
81 58
82 trace_net_log_observer_.reset(new net::TraceNetLogObserver()); 59 trace_net_log_observer_.reset(new net::TraceNetLogObserver());
83 trace_net_log_observer_->WatchForTraceStart(this); 60 trace_net_log_observer_->WatchForTraceStart(this);
84 } 61 }
85 62
86 ChromeNetLog::~ChromeNetLog() { 63 ChromeNetLog::~ChromeNetLog() {
87 net_log_temp_file_.reset(); 64 net_log_temp_file_.reset();
88 // Remove the observers we own before we're destroyed. 65 // Remove the observers we own before we're destroyed.
89 if (write_to_file_observer_) 66 if (write_to_file_observer_)
90 write_to_file_observer_->StopObserving(nullptr); 67 write_to_file_observer_->StopObserving(nullptr);
91 if (trace_net_log_observer_) 68 if (trace_net_log_observer_)
92 trace_net_log_observer_->StopWatchForTraceStart(); 69 trace_net_log_observer_->StopWatchForTraceStart();
93 } 70 }
94 71
72 // static
73 base::Value* ChromeNetLog::GetConstants(
74 const base::CommandLine::StringType& command_line_string,
75 const std::string& channel_string) {
76 scoped_ptr<base::DictionaryValue> constants_dict = net::GetNetConstants();
77 DCHECK(constants_dict);
78
79 // Add a dictionary with the version of the client and its command line
80 // arguments.
81 {
82 base::DictionaryValue* dict = new base::DictionaryValue();
83
84 // We have everything we need to send the right values.
85 dict->SetString("name", version_info::GetProductName());
86 dict->SetString("version", version_info::GetVersionNumber());
87 dict->SetString("cl", version_info::GetLastChange());
88 dict->SetString("version_mod", channel_string);
89 dict->SetString("official", version_info::IsOfficialBuild() ? "official"
90 : "unofficial");
91 dict->SetString("os_type", version_info::GetOSType());
92 dict->SetString("command_line", command_line_string);
93
94 constants_dict->Set("clientInfo", dict);
95
96 data_reduction_proxy::DataReductionProxyEventStore::AddConstants(
97 constants_dict.get());
98 }
99
100 return constants_dict.release();
101 }
102
103 } // namespace net_log
OLDNEW
« no previous file with comments | « components/net_log/chrome_net_log.h ('k') | components/net_log/net_log_temp_file.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698