| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/version_loader.h" | 5 #include "chrome/browser/chromeos/version_loader.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 } | 45 } |
| 46 | 46 |
| 47 // static | 47 // static |
| 48 std::string VersionLoader::ParseVersion(const std::string& contents) { | 48 std::string VersionLoader::ParseVersion(const std::string& contents) { |
| 49 // The file contains lines such as: | 49 // The file contains lines such as: |
| 50 // XXX=YYY | 50 // XXX=YYY |
| 51 // AAA=ZZZ | 51 // AAA=ZZZ |
| 52 // Split the lines and look for the one that starts with kPrefix. The version | 52 // Split the lines and look for the one that starts with kPrefix. The version |
| 53 // file is small, which is why we don't try and be tricky. | 53 // file is small, which is why we don't try and be tricky. |
| 54 std::vector<std::string> lines; | 54 std::vector<std::string> lines; |
| 55 SplitString(contents, '\n', &lines); | 55 base::SplitString(contents, '\n', &lines); |
| 56 for (size_t i = 0; i < lines.size(); ++i) { | 56 for (size_t i = 0; i < lines.size(); ++i) { |
| 57 if (StartsWithASCII(lines[i], kPrefix, false)) { | 57 if (StartsWithASCII(lines[i], kPrefix, false)) { |
| 58 std::string version = lines[i].substr(std::string(kPrefix).size()); | 58 std::string version = lines[i].substr(std::string(kPrefix).size()); |
| 59 if (version.size() > 1 && version[0] == '"' && | 59 if (version.size() > 1 && version[0] == '"' && |
| 60 version[version.size() - 1] == '"') { | 60 version[version.size() - 1] == '"') { |
| 61 // Trim trailing and leading quotes. | 61 // Trim trailing and leading quotes. |
| 62 version = version.substr(1, version.size() - 2); | 62 version = version.substr(1, version.size() - 2); |
| 63 } | 63 } |
| 64 return version; | 64 return version; |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 return std::string(); | 67 return std::string(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void VersionLoader::Backend::GetVersion( | 70 void VersionLoader::Backend::GetVersion( |
| 71 scoped_refptr<GetVersionRequest> request) { | 71 scoped_refptr<GetVersionRequest> request) { |
| 72 if (request->canceled()) | 72 if (request->canceled()) |
| 73 return; | 73 return; |
| 74 | 74 |
| 75 std::string version; | 75 std::string version; |
| 76 std::string contents; | 76 std::string contents; |
| 77 if (file_util::ReadFileToString(FilePath(kPath), &contents)) | 77 if (file_util::ReadFileToString(FilePath(kPath), &contents)) |
| 78 version = ParseVersion(contents); | 78 version = ParseVersion(contents); |
| 79 request->ForwardResult(GetVersionCallback::TupleType(request->handle(), | 79 request->ForwardResult(GetVersionCallback::TupleType(request->handle(), |
| 80 version)); | 80 version)); |
| 81 } | 81 } |
| 82 | 82 |
| 83 } // namespace chromeos | 83 } // namespace chromeos |
| OLD | NEW |