diff options
author | chocobo@google.com <chocobo@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-30 00:35:00 +0000 |
---|---|---|
committer | chocobo@google.com <chocobo@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-30 00:35:00 +0000 |
commit | b22c21c1688727edabf33ef4eebac0c00484271f (patch) | |
tree | e64a91d707ceb8c86bebc6a1bbfb3c76f754dc5c /chrome/browser/chromeos/version_loader.cc | |
parent | 15ab7409218f0bed6e0f448b8707fcfc68ef26bb (diff) | |
download | chromium_src-b22c21c1688727edabf33ef4eebac0c00484271f.zip chromium_src-b22c21c1688727edabf33ef4eebac0c00484271f.tar.gz chromium_src-b22c21c1688727edabf33ef4eebac0c00484271f.tar.bz2 |
Move chromeos code to namespace chromeos.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/341044
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30541 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/version_loader.cc')
-rw-r--r-- | chrome/browser/chromeos/version_loader.cc | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/chrome/browser/chromeos/version_loader.cc b/chrome/browser/chromeos/version_loader.cc new file mode 100644 index 0000000..9475205 --- /dev/null +++ b/chrome/browser/chromeos/version_loader.cc @@ -0,0 +1,82 @@ +// Copyright (c) 2009 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/version_loader.h" + +#include <vector> + +#include "base/file_path.h" +#include "base/file_util.h" +#include "base/message_loop.h" +#include "base/string_util.h" +#include "base/thread.h" +#include "chrome/browser/browser_process.h" + +namespace chromeos { + +// Beginning of line we look for that gives version number. +static const char kPrefix[] = "CHROMEOS_RELEASE_DESCRIPTION="; + +// File to look for version number in. +static const char kPath[] = "/etc/lsb-release"; + +VersionLoader::VersionLoader() : backend_(new Backend()) { +} + +VersionLoader::Handle VersionLoader::GetVersion( + CancelableRequestConsumerBase* consumer, + VersionLoader::GetVersionCallback* callback) { + if (!g_browser_process->file_thread()) { + // This should only happen if Chrome is shutting down, so we don't do + // anything. + return 0; + } + + scoped_refptr<CancelableRequest<GetVersionCallback> > request( + new CancelableRequest<GetVersionCallback>(callback)); + AddRequest(request, consumer); + + g_browser_process->file_thread()->message_loop()->PostTask( + FROM_HERE, + NewRunnableMethod(backend_.get(), &Backend::GetVersion, request)); + return request->handle(); +} + +// static +std::string VersionLoader::ParseVersion(const std::string& contents) { + // The file contains lines such as: + // XXX=YYY + // AAA=ZZZ + // Split the lines and look for the one that starts with kPrefix. The version + // file is small, which is why we don't try and be tricky. + std::vector<std::string> lines; + SplitString(contents, '\n', &lines); + for (size_t i = 0; i < lines.size(); ++i) { + if (StartsWithASCII(lines[i], kPrefix, false)) { + std::string version = lines[i].substr(std::string(kPrefix).size()); + if (version.size() > 1 && version[0] == '"' && + version[version.size() - 1] == '"') { + // Trim trailing and leading quotes. + version = version.substr(1, version.size() - 2); + } + return version; + } + } + return std::string(); +} + +void VersionLoader::Backend::GetVersion( + scoped_refptr<GetVersionRequest> request) { + if (request->canceled()) + return; + + std::string version; + std::string contents; + if (file_util::ReadFileToString(FilePath(kPath), &contents)) + version = ParseVersion(contents); + request->ForwardResult(GetVersionCallback::TupleType(request->handle(), + version)); +} + +} // namespace chromeos |