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

Side by Side Diff: chromecast/browser/cast_net_log.cc

Issue 1216443002: [Chromecast] Add net logging. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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 | « chromecast/browser/cast_net_log.h ('k') | chromecast/browser/url_request_context_factory.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/shell/browser/shell_net_log.h" 5 #include "chromecast/browser/cast_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/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/scoped_file.h" 11 #include "base/files/scoped_file.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "content/public/common/content_switches.h" 13 #include "content/public/common/content_switches.h"
14 #include "net/log/net_log_util.h" 14 #include "net/log/net_log_util.h"
15 #include "net/log/write_to_file_net_log_observer.h" 15 #include "net/log/write_to_file_net_log_observer.h"
16 16
17 namespace content { 17 namespace chromecast {
18 18
19 namespace { 19 namespace {
20 20
21 base::DictionaryValue* GetShellConstants(const std::string& app_name) { 21 base::DictionaryValue* GetShellConstants() {
22 scoped_ptr<base::DictionaryValue> constants_dict = net::GetNetConstants(); 22 scoped_ptr<base::DictionaryValue> constants_dict = net::GetNetConstants();
23 23
24 // Add a dictionary with client information 24 // Add a dictionary with client information
25 base::DictionaryValue* dict = new base::DictionaryValue(); 25 base::DictionaryValue* dict = new base::DictionaryValue();
26 26
27 dict->SetString("name", app_name); 27 dict->SetString("name", "cast_shell");
28 dict->SetString( 28 dict->SetString(
29 "command_line", 29 "command_line",
30 base::CommandLine::ForCurrentProcess()->GetCommandLineString()); 30 base::CommandLine::ForCurrentProcess()->GetCommandLineString());
31 31
32 constants_dict->Set("clientInfo", dict); 32 constants_dict->Set("clientInfo", dict);
33 33
34 return constants_dict.release(); 34 return constants_dict.release();
35 } 35 }
36 36
37 } // namespace 37 } // namespace
38 38
39 ShellNetLog::ShellNetLog(const std::string& app_name) { 39 CastNetLog::CastNetLog() {
40 // TODO(mmenke): Other than a different set of constants, this code is 40 // TODO(derekjchow): This code is virtually identical to ShellNetLog which is
41 // identical to code in ChromeNetLog. Consider merging the code. 41 // nearly identical to code in ChromeNetLog. Consider merging the code.
42 const base::CommandLine* command_line = 42 const base::CommandLine* command_line =
43 base::CommandLine::ForCurrentProcess(); 43 base::CommandLine::ForCurrentProcess();
44 44
45 if (command_line->HasSwitch(switches::kLogNetLog)) { 45 if (command_line->HasSwitch(switches::kLogNetLog)) {
46 base::FilePath log_path = 46 base::FilePath log_path =
47 command_line->GetSwitchValuePath(switches::kLogNetLog); 47 command_line->GetSwitchValuePath(switches::kLogNetLog);
48 // Much like logging.h, bypass threading restrictions by using fopen 48 // Much like logging.h, bypass threading restrictions by using fopen
49 // directly. Have to write on a thread that's shutdown to handle events on 49 // directly. Have to write on a thread that's shutdown to handle events on
50 // shutdown properly, and posting events to another thread as they occur 50 // shutdown properly, and posting events to another thread as they occur
51 // would result in an unbounded buffer size, so not much can be gained by 51 // would result in an unbounded buffer size, so not much can be gained by
52 // doing this on another thread. It's only used when debugging, so 52 // doing this on another thread. It's only used when debugging, so
53 // performance is not a big concern. 53 // performance is not a big concern.
54 base::ScopedFILE file; 54 base::ScopedFILE file;
55 #if defined(OS_WIN)
56 file.reset(_wfopen(log_path.value().c_str(), L"w"));
57 #elif defined(OS_POSIX)
58 file.reset(fopen(log_path.value().c_str(), "w")); 55 file.reset(fopen(log_path.value().c_str(), "w"));
59 #endif
60 56
61 if (!file) { 57 if (!file) {
62 LOG(ERROR) << "Could not open file " << log_path.value() 58 LOG(ERROR) << "Could not open file " << log_path.value()
63 << " for net logging"; 59 << " for net logging";
64 } else { 60 } else {
65 scoped_ptr<base::Value> constants(GetShellConstants(app_name)); 61 scoped_ptr<base::Value> constants(GetShellConstants());
66 write_to_file_observer_.reset(new net::WriteToFileNetLogObserver()); 62 write_to_file_observer_.reset(new net::WriteToFileNetLogObserver());
67 write_to_file_observer_->StartObserving(this, file.Pass(), 63 write_to_file_observer_->StartObserving(this, file.Pass(),
68 constants.get(), nullptr); 64 constants.get(), nullptr);
69 } 65 }
70 } 66 }
71 } 67 }
72 68
73 ShellNetLog::~ShellNetLog() { 69 CastNetLog::~CastNetLog() {
74 // Remove the observer we own before we're destroyed. 70 // Remove the observer we own before we're destroyed.
75 if (write_to_file_observer_) 71 if (write_to_file_observer_)
76 write_to_file_observer_->StopObserving(nullptr); 72 write_to_file_observer_->StopObserving(nullptr);
77 } 73 }
78 74
79 } // namespace content 75 } // namespace chromecast
OLDNEW
« no previous file with comments | « chromecast/browser/cast_net_log.h ('k') | chromecast/browser/url_request_context_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698