OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "components/tracing/browser/trace_config_file.h" | 5 #include "components/tracing/common/trace_config_file.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
14 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
(...skipping 18 matching lines...) Expand all Loading... |
34 #endif | 34 #endif |
35 | 35 |
36 const base::FilePath::CharType kDefaultResultFile[] = | 36 const base::FilePath::CharType kDefaultResultFile[] = |
37 FILE_PATH_LITERAL("chrometrace.log"); | 37 FILE_PATH_LITERAL("chrometrace.log"); |
38 | 38 |
39 // String parameters that can be used to parse the trace config file content. | 39 // String parameters that can be used to parse the trace config file content. |
40 const char kTraceConfigParam[] = "trace_config"; | 40 const char kTraceConfigParam[] = "trace_config"; |
41 const char kStartupDurationParam[] = "startup_duration"; | 41 const char kStartupDurationParam[] = "startup_duration"; |
42 const char kResultFileParam[] = "result_file"; | 42 const char kResultFileParam[] = "result_file"; |
43 | 43 |
44 } // namespace | 44 } // namespace |
45 | 45 |
46 TraceConfigFile* TraceConfigFile::GetInstance() { | 46 TraceConfigFile* TraceConfigFile::GetInstance() { |
47 return base::Singleton<TraceConfigFile, | 47 return base::Singleton<TraceConfigFile, |
48 base::DefaultSingletonTraits<TraceConfigFile>>::get(); | 48 base::DefaultSingletonTraits<TraceConfigFile>>::get(); |
49 } | 49 } |
50 | 50 |
51 TraceConfigFile::TraceConfigFile() | 51 TraceConfigFile::TraceConfigFile() |
52 : is_enabled_(false), | 52 : is_enabled_(false), |
53 trace_config_(base::trace_event::TraceConfig()), | 53 trace_config_(base::trace_event::TraceConfig()), |
54 startup_duration_(0), | 54 startup_duration_(0), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 &trace_config_file_content, | 86 &trace_config_file_content, |
87 kTraceConfigFileSizeLimit)) { | 87 kTraceConfigFileSizeLimit)) { |
88 DLOG(WARNING) << "Cannot read the trace config file correctly."; | 88 DLOG(WARNING) << "Cannot read the trace config file correctly."; |
89 return; | 89 return; |
90 } | 90 } |
91 is_enabled_ = ParseTraceConfigFileContent(trace_config_file_content); | 91 is_enabled_ = ParseTraceConfigFileContent(trace_config_file_content); |
92 if (!is_enabled_) | 92 if (!is_enabled_) |
93 DLOG(WARNING) << "Cannot parse the trace config file correctly."; | 93 DLOG(WARNING) << "Cannot parse the trace config file correctly."; |
94 } | 94 } |
95 | 95 |
96 TraceConfigFile::~TraceConfigFile() { | 96 TraceConfigFile::~TraceConfigFile() {} |
97 } | |
98 | 97 |
99 bool TraceConfigFile::ParseTraceConfigFileContent(const std::string& content) { | 98 bool TraceConfigFile::ParseTraceConfigFileContent(const std::string& content) { |
100 std::unique_ptr<base::Value> value(base::JSONReader::Read(content)); | 99 std::unique_ptr<base::Value> value(base::JSONReader::Read(content)); |
101 if (!value || !value->IsType(base::Value::Type::DICTIONARY)) | 100 if (!value || !value->IsType(base::Value::Type::DICTIONARY)) |
102 return false; | 101 return false; |
103 | 102 |
104 std::unique_ptr<base::DictionaryValue> dict( | 103 std::unique_ptr<base::DictionaryValue> dict( |
105 static_cast<base::DictionaryValue*>(value.release())); | 104 static_cast<base::DictionaryValue*>(value.release())); |
106 | 105 |
107 base::DictionaryValue* trace_config_dict = NULL; | 106 base::DictionaryValue* trace_config_dict = NULL; |
108 if (!dict->GetDictionary(kTraceConfigParam, &trace_config_dict)) | 107 if (!dict->GetDictionary(kTraceConfigParam, &trace_config_dict)) |
109 return false; | 108 return false; |
110 | 109 |
111 trace_config_ = base::trace_event::TraceConfig(*trace_config_dict); | 110 trace_config_ = base::trace_event::TraceConfig(*trace_config_dict); |
112 | 111 |
113 if (!dict->GetInteger(kStartupDurationParam, &startup_duration_)) | 112 if (!dict->GetInteger(kStartupDurationParam, &startup_duration_)) |
114 startup_duration_ = 0; | 113 startup_duration_ = 0; |
115 | 114 |
116 if (startup_duration_ < 0) | 115 if (startup_duration_ < 0) |
117 startup_duration_ = 0; | 116 startup_duration_ = 0; |
118 | 117 |
119 base::FilePath::StringType result_file_str; | 118 base::FilePath::StringType result_file_str; |
120 if (dict->GetString(kResultFileParam, &result_file_str)) | 119 if (dict->GetString(kResultFileParam, &result_file_str)) |
121 result_file_ = base::FilePath(result_file_str); | 120 result_file_ = base::FilePath(result_file_str); |
122 | 121 |
123 return true; | 122 return true; |
124 } | 123 } |
125 | 124 |
126 bool TraceConfigFile::IsEnabled() const { | 125 bool TraceConfigFile::IsEnabled() const { |
127 return is_enabled_; | 126 return is_enabled_; |
(...skipping 10 matching lines...) Expand all Loading... |
138 } | 137 } |
139 | 138 |
140 #if !defined(OS_ANDROID) | 139 #if !defined(OS_ANDROID) |
141 base::FilePath TraceConfigFile::GetResultFile() const { | 140 base::FilePath TraceConfigFile::GetResultFile() const { |
142 DCHECK(IsEnabled()); | 141 DCHECK(IsEnabled()); |
143 return result_file_; | 142 return result_file_; |
144 } | 143 } |
145 #endif | 144 #endif |
146 | 145 |
147 } // namespace tracing | 146 } // namespace tracing |
OLD | NEW |