Chromium Code Reviews| OLD | NEW |
|---|---|
| (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> KeyValuePair; | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 namespace chromeos { | |
| 30 | |
| 31 void LsbReleaseLogSource::Fetch(const SysLogsFetcherCallback& callback) { | |
| 32 DCHECK(!callback.is_null()); | |
| 33 | |
| 34 SystemLogsResponse* response = new SystemLogsResponse; | |
| 35 BrowserThread::PostBlockingPoolTaskAndReply( | |
| 36 FROM_HERE, | |
| 37 base::Bind(&ReadLSBRelease, response), | |
|
satorux1
2012/08/16 10:50:57
this should be &LsbReleaseLogSource::ReadLSBReleas
tudalex(Chromium)
2012/08/16 22:33:03
Done.
| |
| 38 base::Bind(callback, | |
| 39 base::Owned(response))); | |
| 40 } | |
| 41 | |
| 42 void LsbReleaseLogSource::ReadLSBRelease(SystemLogsResponse* response) { | |
| 43 DCHECK(response); | |
| 44 | |
| 45 const FilePath lsb_release_file("/etc/lsb-release"); | |
| 46 std::string lsb_data; | |
| 47 bool read_success = file_util::ReadFileToString(lsb_release_file, &lsb_data); | |
| 48 // if we were using an internal temp file, the user does not need the | |
| 49 // logs to stay past the ReadFile call - delete the file | |
| 50 if (!read_success) { | |
| 51 LOG(ERROR) << "Can't access /etc/lsb-release file."; | |
| 52 return; | |
| 53 } | |
| 54 ParseLSBRelease(lsb_data, response); | |
| 55 } | |
| 56 | |
| 57 void LsbReleaseLogSource::ParseLSBRelease(const std::string& lsb_data, | |
| 58 SystemLogsResponse* response) { | |
| 59 std::vector<KeyValuePair> pairs; | |
| 60 base::SplitStringIntoKeyValuePairs(lsb_data, '=', '\n', &pairs); | |
| 61 for (size_t i = 0; i < pairs.size(); ++i) { | |
| 62 std::string key, value; | |
| 63 TrimWhitespaceASCII(pairs[i].first, TRIM_ALL, &key); | |
| 64 TrimWhitespaceASCII(pairs[i].second, TRIM_ALL, &value); | |
| 65 if (!key.empty()) { | |
|
satorux1
2012/08/16 10:50:57
you might want to do
if (key.empty())
continue;
tudalex(Chromium)
2012/08/16 22:33:03
Done.
| |
| 66 if (IsStringUTF8(value) && IsStringUTF8(key)) { | |
|
satorux1
2012/08/16 10:50:57
Likewise,
if (!IsStringUTF8(value) || !IsStringUT
tudalex(Chromium)
2012/08/16 22:33:03
Done.
| |
| 67 if (value.empty()) | |
| 68 (*response)[key] = kEmptyLogEntry; | |
| 69 else | |
| 70 (*response)[key] = value; | |
| 71 } else { | |
| 72 LOG(WARNING) << "Invalid characters in system log entry: " << key; | |
| 73 (*response)[key] = kInvalidLogEntry; | |
| 74 } | |
| 75 } | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 } // namespace chromeos | |
| 80 | |
| OLD | NEW |