| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/chromeos/system/syslogs_provider.h" | 5 #include "chrome/browser/chromeos/system/syslogs_provider.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 const char kInvalidLogEntry[] = "<invalid characters in log entry>"; | 44 const char kInvalidLogEntry[] = "<invalid characters in log entry>"; |
| 45 const char kEmptyLogEntry[] = "<no value>"; | 45 const char kEmptyLogEntry[] = "<no value>"; |
| 46 | 46 |
| 47 const char kContextFeedback[] = "feedback"; | 47 const char kContextFeedback[] = "feedback"; |
| 48 const char kContextSysInfo[] = "sysinfo"; | 48 const char kContextSysInfo[] = "sysinfo"; |
| 49 const char kContextNetwork[] = "network"; | 49 const char kContextNetwork[] = "network"; |
| 50 | 50 |
| 51 // Reads a key from the input string erasing the read values + delimiters read | 51 // Reads a key from the input string erasing the read values + delimiters read |
| 52 // from the initial string | 52 // from the initial string |
| 53 std::string ReadKey(std::string* data) { | 53 std::string ReadKey(std::string* data) { |
| 54 std::string key; |
| 54 size_t equal_sign = data->find("="); | 55 size_t equal_sign = data->find("="); |
| 55 if (equal_sign == std::string::npos) | 56 if (equal_sign == std::string::npos) |
| 56 return std::string(""); | 57 return key; |
| 57 std::string key = data->substr(0, equal_sign); | 58 key = data->substr(0, equal_sign); |
| 58 data->erase(0, equal_sign); | 59 data->erase(0, equal_sign); |
| 59 if (data->size() > 0) { | 60 if (data->empty()) |
| 60 // erase the equal to sign also | |
| 61 data->erase(0,1); | |
| 62 return key; | 61 return key; |
| 63 } | 62 // erase the equal to sign also |
| 64 return std::string(); | 63 data->erase(0, 1); |
| 64 return key; |
| 65 } | 65 } |
| 66 | 66 |
| 67 // Reads a value from the input string; erasing the read values from | 67 // Reads a value from the input string; erasing the read values from |
| 68 // the initial string; detects if the value is multiline and reads | 68 // the initial string; detects if the value is multiline and reads |
| 69 // accordingly | 69 // accordingly |
| 70 std::string ReadValue(std::string* data) { | 70 std::string ReadValue(std::string* data) { |
| 71 // Trim the leading spaces and tabs. In order to use a multi-line | 71 // Trim the leading spaces and tabs. In order to use a multi-line |
| 72 // value, you have to place the multi-line quote on the same line as | 72 // value, you have to place the multi-line quote on the same line as |
| 73 // the equal sign. | 73 // the equal sign. |
| 74 // | 74 // |
| (...skipping 11 matching lines...) Expand all Loading... |
| 86 data->erase(0, strlen(kMultilineQuote)); | 86 data->erase(0, strlen(kMultilineQuote)); |
| 87 size_t next_multi = data->find(kMultilineQuote); | 87 size_t next_multi = data->find(kMultilineQuote); |
| 88 if (next_multi == std::string::npos) { | 88 if (next_multi == std::string::npos) { |
| 89 // Error condition, clear data to stop further processing | 89 // Error condition, clear data to stop further processing |
| 90 data->erase(); | 90 data->erase(); |
| 91 return std::string(); | 91 return std::string(); |
| 92 } | 92 } |
| 93 std::string value = data->substr(0, next_multi); | 93 std::string value = data->substr(0, next_multi); |
| 94 data->erase(0, next_multi + 3); | 94 data->erase(0, next_multi + 3); |
| 95 return value; | 95 return value; |
| 96 } else { // single line value | 96 } else { |
| 97 // single line value |
| 97 size_t endl_pos = data->find_first_of(kNewLineChars); | 98 size_t endl_pos = data->find_first_of(kNewLineChars); |
| 98 // if we don't find a new line, we just return the rest of the data | 99 // if we don't find a new line, we just return the rest of the data |
| 99 std::string value = data->substr(0, endl_pos); | 100 std::string value = data->substr(0, endl_pos); |
| 100 data->erase(0, endl_pos); | 101 data->erase(0, endl_pos); |
| 101 return value; | 102 return value; |
| 102 } | 103 } |
| 103 } | 104 } |
| 104 | 105 |
| 105 // Returns a map of system log keys and values. | 106 // Returns a map of system log keys and values. |
| 106 // | 107 // |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 return Singleton<SyslogsProviderImpl, | 398 return Singleton<SyslogsProviderImpl, |
| 398 DefaultSingletonTraits<SyslogsProviderImpl> >::get(); | 399 DefaultSingletonTraits<SyslogsProviderImpl> >::get(); |
| 399 } | 400 } |
| 400 | 401 |
| 401 SyslogsProvider* SyslogsProvider::GetInstance() { | 402 SyslogsProvider* SyslogsProvider::GetInstance() { |
| 402 return SyslogsProviderImpl::GetInstance(); | 403 return SyslogsProviderImpl::GetInstance(); |
| 403 } | 404 } |
| 404 | 405 |
| 405 } // namespace system | 406 } // namespace system |
| 406 } // namespace chromeos | 407 } // namespace chromeos |
| OLD | NEW |