| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_NAME_VALUE_PAIRS_PARSER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_NAME_VALUE_PAIRS_PARSER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_SYSTEM_NAME_VALUE_PAIRS_PARSER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_SYSTEM_NAME_VALUE_PAIRS_PARSER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 | 14 |
| 15 class FilePath; |
| 16 |
| 15 namespace chromeos { | 17 namespace chromeos { |
| 16 namespace system { | 18 namespace system { |
| 17 | 19 |
| 18 // The parser is used to get machine info as name-value pairs. Defined | 20 // The parser is used to get machine info as name-value pairs. Defined |
| 19 // here to be accessable by tests. | 21 // here to be accessable by tests. |
| 20 class NameValuePairsParser { | 22 class NameValuePairsParser { |
| 21 public: | 23 public: |
| 22 typedef std::map<std::string, std::string> NameValueMap; | 24 typedef std::map<std::string, std::string> NameValueMap; |
| 23 | 25 |
| 24 // The obtained info will be written into machine_info. | 26 // The obtained info will be written into machine_info. |
| 25 explicit NameValuePairsParser(NameValueMap* map); | 27 explicit NameValuePairsParser(NameValueMap* map); |
| 26 | 28 |
| 27 void AddNameValuePair(const std::string& key, const std::string& value); | 29 void AddNameValuePair(const std::string& key, const std::string& value); |
| 28 | 30 |
| 29 // Executes tool and inserts (key, <output>) into map_. | 31 // Executes tool and inserts (key, <output>) into map_. |
| 30 // The program name (argv[0]) should be an absolute path. The function | 32 // The program name (argv[0]) should be an absolute path. The function |
| 31 // checks if the program exists before executing it as some programs | 33 // checks if the program exists before executing it as some programs |
| 32 // don't exist on Linux desktop. | 34 // don't exist on Linux desktop. |
| 33 bool GetSingleValueFromTool(int argc, const char* argv[], | 35 bool GetSingleValueFromTool(int argc, const char* argv[], |
| 34 const std::string& key); | 36 const std::string& key); |
| 35 | 37 |
| 38 // Parses name-value pairs from the file. |
| 39 void GetNameValuePairsFromFile(const FilePath& file_path, |
| 40 const std::string& eq, |
| 41 const std::string& delim); |
| 42 |
| 36 // This will parse strings with output in the format: | 43 // This will parse strings with output in the format: |
| 37 // <key><EQ><value><DELIM>[<key><EQ><value>][...] | 44 // <key><EQ><value><DELIM>[<key><EQ><value>][...] |
| 38 // e.g. ParseNameValuePairs("key1=value1 key2=value2", "=", " ") | 45 // e.g. ParseNameValuePairs("key1=value1 key2=value2", "=", " ") |
| 39 bool ParseNameValuePairs(const std::string& in_string, | 46 bool ParseNameValuePairs(const std::string& in_string, |
| 40 const std::string& eq, | 47 const std::string& eq, |
| 41 const std::string& delim); | 48 const std::string& delim); |
| 42 | 49 |
| 43 NameValueMap* map_; | 50 NameValueMap* map_; |
| 44 | 51 |
| 45 DISALLOW_COPY_AND_ASSIGN(NameValuePairsParser); | 52 DISALLOW_COPY_AND_ASSIGN(NameValuePairsParser); |
| 46 }; | 53 }; |
| 47 | 54 |
| 48 } // namespace system | 55 } // namespace system |
| 49 } // namespace chromeos | 56 } // namespace chromeos |
| 50 | 57 |
| 51 #endif // CHROME_BROWSER_CHROMEOS_SYSTEM_NAME_VALUE_PAIRS_PARSER_H_ | 58 #endif // CHROME_BROWSER_CHROMEOS_SYSTEM_NAME_VALUE_PAIRS_PARSER_H_ |
| OLD | NEW |