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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/system_logs/lsbrelease_log_source.cc
diff --git a/chrome/browser/chromeos/system_logs/lsbrelease_log_source.cc b/chrome/browser/chromeos/system_logs/lsbrelease_log_source.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c504edab1be35d8f98b5fd45e84bede2932354e9
--- /dev/null
+++ b/chrome/browser/chromeos/system_logs/lsbrelease_log_source.cc
@@ -0,0 +1,81 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/system_logs/lsbrelease_log_source.h"
+
+#include <string>
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/logging.h"
+#include "base/string_util.h"
+#include "base/string_split.h"
+#include "content/public/browser/browser_thread.h"
+
+using content::BrowserThread;
+
+namespace {
+
+const char kInvalidLogEntry[] = "<invalid characters in log entry>";
+const char kEmptyLogEntry[] = "<no value>";
+
+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.
+
+} // namespace
+
+namespace chromeos {
+
+void LsbReleaseLogSource::Fetch(const SysLogsFetcherCallback& callback) {
+ SystemLogsResponse* response = new SystemLogsResponse;
+ BrowserThread::PostBlockingPoolTaskAndReply(
+ FROM_HERE,
+ base::Bind(&ReadLSBRelease, response),
+ base::Bind(callback,
+ base::Owned(response)));
+}
+
+void LsbReleaseLogSource::ReadLSBRelease(SystemLogsResponse* response) {
+ DCHECK(response);
+
+ const FilePath lsb_release_file("/etc/lsb-release");
+ std::string lsb_data;
+ bool read_success = file_util::ReadFileToString(lsb_release_file,
+ &lsb_data);
satorux1 2012/08/15 22:01:09 indentation.
tudalex(Chromium) 2012/08/16 01:08:57 Done.
+ // if we were using an internal temp file, the user does not need the
+ // logs to stay past the ReadFile call - delete the file
+ if (!read_success) {
+ LOG(ERROR) << "Can't access /etc/lsb-release file.";
+ return;
+ }
+ ParseLSBRelease(lsb_data, response);
+}
+
+void LsbReleaseLogSource::ParseLSBRelease(const std::string lsb_data,
+ SystemLogsResponse* response) {
+ 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.
+ base::SplitStringIntoKeyValuePairs(lsb_data, '=', '\n', &keys);
+ for (std::vector<KV_Pair>::iterator it = keys.begin();
+ 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.
+ ++it) {
+ std::string key, value;
+ TrimWhitespaceASCII(it->first, TRIM_ALL, &key);
+ TrimWhitespaceASCII(it->second, TRIM_ALL, &value);
+ if (!key.empty()) {
+ 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.
+ if (value.empty())
+ (*response)[key] = kEmptyLogEntry;
+ else
+ (*response)[key] = value;
+ } else {
+ 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
+ (*response)[key] = kInvalidLogEntry;
+ }
+ }
+ }
+}
+
+} // namespace chromeos
+

Powered by Google App Engine
This is Rietveld 408576698