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

Side by Side Diff: chrome/browser/chromeos/system_logs/lsbrelease_log_source.cc

Issue 10827130: Refactoring the SysInfoProvider. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 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
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 #include "chrome/browser/chromeos/system_logs/lsbrelease_log_source.h"
6
7 #include <string>
8
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/file_path.h"
12 #include "base/file_util.h"
13 #include "base/logging.h"
14 #include "base/string_util.h"
15 #include "base/string_split.h"
16 #include "content/public/browser/browser_thread.h"
17
18 using content::BrowserThread;
19
20 namespace {
21
22 const char kInvalidLogEntry[] = "<invalid characters in log entry>";
23 const char kEmptyLogEntry[] = "<no value>";
24
25 typedef std::pair<std::string, std::string> KV_Pair;
satorux1 2012/08/15 22:01:09 no abbreviation. KeyValuePair
tudalex(Chromium) 2012/08/16 01:08:57 Done.
26
27 } // namespace
28
29 namespace chromeos {
30
31 void LsbReleaseLogSource::Fetch(const SysLogsFetcherCallback& callback) {
32 SystemLogsResponse* response = new SystemLogsResponse;
33 BrowserThread::PostBlockingPoolTaskAndReply(
34 FROM_HERE,
35 base::Bind(&ReadLSBRelease, response),
36 base::Bind(callback,
37 base::Owned(response)));
38 }
39
40 void LsbReleaseLogSource::ReadLSBRelease(SystemLogsResponse* response) {
41 DCHECK(response);
42
43 const FilePath lsb_release_file("/etc/lsb-release");
44 std::string lsb_data;
45 bool read_success = file_util::ReadFileToString(lsb_release_file,
46 &lsb_data);
satorux1 2012/08/15 22:01:09 indentation.
tudalex(Chromium) 2012/08/16 01:08:57 Done.
47 // if we were using an internal temp file, the user does not need the
48 // logs to stay past the ReadFile call - delete the file
49 if (!read_success) {
50 LOG(ERROR) << "Can't access /etc/lsb-release file.";
51 return;
52 }
53 ParseLSBRelease(lsb_data, response);
54 }
55
56 void LsbReleaseLogSource::ParseLSBRelease(const std::string lsb_data,
57 SystemLogsResponse* response) {
58 std::vector<KV_Pair> keys;
satorux1 2012/08/15 22:01:09 |keys| sounds wrong because it's pairs. maybe |pai
tudalex(Chromium) 2012/08/16 01:08:57 Done.
59 base::SplitStringIntoKeyValuePairs(lsb_data, '=', '\n', &keys);
60 for (std::vector<KV_Pair>::iterator it = keys.begin();
61 it != keys.end();
satorux1 2012/08/15 22:01:09 btw, it's a matter of taste, but the following is
tudalex(Chromium) 2012/08/16 01:08:57 Done.
62 ++it) {
63 std::string key, value;
64 TrimWhitespaceASCII(it->first, TRIM_ALL, &key);
65 TrimWhitespaceASCII(it->second, TRIM_ALL, &value);
66 if (!key.empty()) {
67 if (IsStringUTF8(it->second)) {
satorux1 2012/08/15 22:01:09 it->second -> value ?? shouldn't we also check th
tudalex(Chromium) 2012/08/16 01:08:57 Done.
68 if (value.empty())
69 (*response)[key] = kEmptyLogEntry;
70 else
71 (*response)[key] = value;
72 } else {
73 LOG(WARNING) << "Invalid characters in system log entry: " << it->first;
satorux1 2012/08/15 22:01:09 value?
tudalex(Chromium) 2012/08/16 01:08:57 I think the key is better than the value, because
satorux1 2012/08/16 10:50:57 sounds good
74 (*response)[key] = kInvalidLogEntry;
75 }
76 }
77 }
78 }
79
80 } // namespace chromeos
81
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698