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

Side by Side Diff: chrome/browser/chromeos/system/name_value_pairs_parser.h

Issue 14643006: [chromeos] Remove dependencies of StatisticsProvider on chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: trybots Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_NAME_VALUE_PAIRS_PARSER_H_
6 #define CHROME_BROWSER_CHROMEOS_SYSTEM_NAME_VALUE_PAIRS_PARSER_H_
7
8 #include <map>
9 #include <string>
10
11 #include "base/basictypes.h"
12
13 namespace base {
14 class FilePath;
15 }
16
17 namespace chromeos {
18 namespace system {
19
20 // The parser is used to get machine info as name-value pairs. Defined
21 // here to be accessible by tests.
22 class NameValuePairsParser {
23 public:
24 typedef std::map<std::string, std::string> NameValueMap;
25
26 // The obtained info will be written into the given map.
27 explicit NameValuePairsParser(NameValueMap* map);
28
29 void AddNameValuePair(const std::string& key, const std::string& value);
30
31 // Executes tool and inserts (key, <output>) into map_.
32 // The program name (argv[0]) should be an absolute path. The function
33 // checks if the program exists before executing it as some programs
34 // don't exist on Linux desktop; returns false in that case.
35 bool GetSingleValueFromTool(int argc, const char* argv[],
36 const std::string& key);
37
38 // Parses name-value pairs from the file.
39 // Returns false if there was any error in the file. Valid pairs will still be
40 // added to the map.
41 bool GetNameValuePairsFromFile(const base::FilePath& file_path,
42 const std::string& eq,
43 const std::string& delim);
44
45 // These will parse strings with output in the format:
46 // <key><EQ><value><DELIM>[<key><EQ><value>][...]
47 // e.g. ParseNameValuePairs("key1=value1 key2=value2", "=", " ")
48 // Returns false if there was any error in in_string. Valid pairs will still
49 // be added to the map.
50 bool ParseNameValuePairs(const std::string& in_string,
51 const std::string& eq,
52 const std::string& delim);
53
54 // This version allows for values which end with a comment
55 // beginning with comment_delim.
56 // e.g. "key2=value2 # Explanation of value\n"
57 // Returns false if there was any error in in_string. Valid pairs will still
58 // be added to the map.
59 bool ParseNameValuePairsWithComments(const std::string& in_string,
60 const std::string& eq,
61 const std::string& delim,
62 const std::string& comment_delim);
63
64 // Same as ParseNameValuePairsWithComments(), but uses the output of the given
65 // tool as the input to parse.
66 bool ParseNameValuePairsFromTool(
67 int argc,
68 const char* argv[],
69 const std::string& eq,
70 const std::string& delim,
71 const std::string& comment_delim);
72
73 private:
74 NameValueMap* map_;
75
76 DISALLOW_COPY_AND_ASSIGN(NameValuePairsParser);
77 };
78
79 } // namespace system
80 } // namespace chromeos
81
82 #endif // CHROME_BROWSER_CHROMEOS_SYSTEM_NAME_VALUE_PAIRS_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698