| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 30 matching lines...) Expand all Loading... |
| 41 // static | 41 // static |
| 42 const char VersionLoader::kVersionPrefix[] = "CHROMEOS_RELEASE_VERSION="; | 42 const char VersionLoader::kVersionPrefix[] = "CHROMEOS_RELEASE_VERSION="; |
| 43 | 43 |
| 44 // Beginning of line we look for that gives the firmware version. | 44 // Beginning of line we look for that gives the firmware version. |
| 45 const char VersionLoader::kFirmwarePrefix[] = "version"; | 45 const char VersionLoader::kFirmwarePrefix[] = "version"; |
| 46 | 46 |
| 47 VersionLoader::Handle VersionLoader::GetVersion( | 47 VersionLoader::Handle VersionLoader::GetVersion( |
| 48 CancelableRequestConsumerBase* consumer, | 48 CancelableRequestConsumerBase* consumer, |
| 49 const VersionLoader::GetVersionCallback& callback, | 49 const VersionLoader::GetVersionCallback& callback, |
| 50 VersionFormat format) { | 50 VersionFormat format) { |
| 51 if (!g_browser_process->file_thread()) { | 51 if (!BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { |
| 52 // This should only happen if Chrome is shutting down, so we don't do | 52 // This should only happen if Chrome is shutting down, so we don't do |
| 53 // anything. | 53 // anything. |
| 54 return 0; | 54 return 0; |
| 55 } | 55 } |
| 56 | 56 |
| 57 scoped_refptr<GetVersionRequest> request(new GetVersionRequest(callback)); | 57 scoped_refptr<GetVersionRequest> request(new GetVersionRequest(callback)); |
| 58 AddRequest(request, consumer); | 58 AddRequest(request, consumer); |
| 59 | 59 |
| 60 g_browser_process->file_thread()->message_loop()->PostTask( | 60 BrowserThread::PostTask( |
| 61 BrowserThread::FILE, |
| 61 FROM_HERE, | 62 FROM_HERE, |
| 62 NewRunnableMethod(backend_.get(), &Backend::GetVersion, request, format)); | 63 NewRunnableMethod(backend_.get(), &Backend::GetVersion, request, format)); |
| 63 return request->handle(); | 64 return request->handle(); |
| 64 } | 65 } |
| 65 | 66 |
| 66 VersionLoader::Handle VersionLoader::GetFirmware( | 67 VersionLoader::Handle VersionLoader::GetFirmware( |
| 67 CancelableRequestConsumerBase* consumer, | 68 CancelableRequestConsumerBase* consumer, |
| 68 const VersionLoader::GetFirmwareCallback& callback) { | 69 const VersionLoader::GetFirmwareCallback& callback) { |
| 69 if (!g_browser_process->file_thread()) { | 70 if (!BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { |
| 70 // This should only happen if Chrome is shutting down, so we don't do | 71 // This should only happen if Chrome is shutting down, so we don't do |
| 71 // anything. | 72 // anything. |
| 72 return 0; | 73 return 0; |
| 73 } | 74 } |
| 74 | 75 |
| 75 scoped_refptr<GetFirmwareRequest> request(new GetFirmwareRequest(callback)); | 76 scoped_refptr<GetFirmwareRequest> request(new GetFirmwareRequest(callback)); |
| 76 AddRequest(request, consumer); | 77 AddRequest(request, consumer); |
| 77 | 78 |
| 78 g_browser_process->file_thread()->message_loop()->PostTask( | 79 BrowserThread::PostTask( |
| 80 BrowserThread::FILE, |
| 79 FROM_HERE, | 81 FROM_HERE, |
| 80 NewRunnableMethod(backend_.get(), &Backend::GetFirmware, request)); | 82 NewRunnableMethod(backend_.get(), &Backend::GetFirmware, request)); |
| 81 return request->handle(); | 83 return request->handle(); |
| 82 } | 84 } |
| 83 | 85 |
| 84 // static | 86 // static |
| 85 std::string VersionLoader::ParseVersion(const std::string& contents, | 87 std::string VersionLoader::ParseVersion(const std::string& contents, |
| 86 const std::string& prefix) { | 88 const std::string& prefix) { |
| 87 // The file contains lines such as: | 89 // The file contains lines such as: |
| 88 // XXX=YYY | 90 // XXX=YYY |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 std::string contents; | 171 std::string contents; |
| 170 const FilePath file_path(kPathFirmware); | 172 const FilePath file_path(kPathFirmware); |
| 171 if (file_util::ReadFileToString(file_path, &contents)) { | 173 if (file_util::ReadFileToString(file_path, &contents)) { |
| 172 firmware = ParseFirmware(contents); | 174 firmware = ParseFirmware(contents); |
| 173 } | 175 } |
| 174 | 176 |
| 175 request->ForwardResult(request->handle(), firmware); | 177 request->ForwardResult(request->handle(), firmware); |
| 176 } | 178 } |
| 177 | 179 |
| 178 } // namespace chromeos | 180 } // namespace chromeos |
| OLD | NEW |