OLD | NEW |
---|---|
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) | 55 #if defined(OS_WIN) |
lcwu1
2015/06/26 04:30:26
Cast doesn't care about OS_WIN. :-)
derekjchow1
2015/06/26 17:58:53
Done.
| |
56 file.reset(_wfopen(log_path.value().c_str(), L"w")); | 56 file.reset(_wfopen(log_path.value().c_str(), L"w")); |
57 #elif defined(OS_POSIX) | 57 #elif defined(OS_POSIX) |
58 file.reset(fopen(log_path.value().c_str(), "w")); | 58 file.reset(fopen(log_path.value().c_str(), "w")); |
59 #endif | 59 #endif |
60 | 60 |
61 if (!file) { | 61 if (!file) { |
62 LOG(ERROR) << "Could not open file " << log_path.value() | 62 LOG(ERROR) << "Could not open file " << log_path.value() |
63 << " for net logging"; | 63 << " for net logging"; |
64 } else { | 64 } else { |
65 scoped_ptr<base::Value> constants(GetShellConstants(app_name)); | 65 scoped_ptr<base::Value> constants(GetShellConstants()); |
66 write_to_file_observer_.reset(new net::WriteToFileNetLogObserver()); | 66 write_to_file_observer_.reset(new net::WriteToFileNetLogObserver()); |
67 write_to_file_observer_->StartObserving(this, file.Pass(), | 67 write_to_file_observer_->StartObserving(this, file.Pass(), |
68 constants.get(), nullptr); | 68 constants.get(), nullptr); |
69 } | 69 } |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 ShellNetLog::~ShellNetLog() { | 73 CastNetLog::~CastNetLog() { |
74 // Remove the observer we own before we're destroyed. | 74 // Remove the observer we own before we're destroyed. |
75 if (write_to_file_observer_) | 75 if (write_to_file_observer_) |
76 write_to_file_observer_->StopObserving(nullptr); | 76 write_to_file_observer_->StopObserving(nullptr); |
77 } | 77 } |
78 | 78 |
79 } // namespace content | 79 } // namespace chromecast |
OLD | NEW |