Home | History | Annotate | Download | only in common
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/common/chrome_version_info.h"
      6 
      7 #include "base/basictypes.h"
      8 #include "base/file_version_info.h"
      9 #include "base/string_util.h"
     10 #include "base/threading/thread_restrictions.h"
     11 #include "build/build_config.h"
     12 
     13 namespace chrome {
     14 
     15 #if defined(OS_WIN) || defined(OS_MACOSX)
     16 // On Windows and Mac, we get the Chrome version info by querying
     17 // FileVersionInfo for the current module.
     18 
     19 VersionInfo::VersionInfo() {
     20   // The current module is already loaded in memory, so this will be cheap.
     21   base::ThreadRestrictions::ScopedAllowIO allow_io;
     22   version_info_.reset(FileVersionInfo::CreateFileVersionInfoForCurrentModule());
     23 }
     24 
     25 VersionInfo::~VersionInfo() {
     26 }
     27 
     28 bool VersionInfo::is_valid() const {
     29   return version_info_.get() != NULL;
     30 }
     31 
     32 std::string VersionInfo::Name() const {
     33   if (!is_valid())
     34     return std::string();
     35   return UTF16ToASCII(version_info_->product_name());
     36 }
     37 
     38 std::string VersionInfo::Version() const {
     39   if (!is_valid())
     40     return std::string();
     41   return UTF16ToASCII(version_info_->product_version());
     42 }
     43 
     44 std::string VersionInfo::LastChange() const {
     45   if (!is_valid())
     46     return std::string();
     47   return UTF16ToASCII(version_info_->last_change());
     48 }
     49 
     50 bool VersionInfo::IsOfficialBuild() const {
     51   if (!is_valid())
     52     return false;
     53   return version_info_->is_official_build();
     54 }
     55 
     56 #elif defined(OS_POSIX)
     57 // We get chrome version information from chrome_version_info_posix.h,
     58 // a generated header.
     59 
     60 #include "chrome/common/chrome_version_info_posix.h"
     61 
     62 VersionInfo::VersionInfo() {
     63 }
     64 
     65 VersionInfo::~VersionInfo() {
     66 }
     67 
     68 bool VersionInfo::is_valid() const {
     69   return true;
     70 }
     71 
     72 std::string VersionInfo::Name() const {
     73   return PRODUCT_NAME;
     74 }
     75 
     76 std::string VersionInfo::Version() const {
     77   return PRODUCT_VERSION;
     78 }
     79 
     80 std::string VersionInfo::LastChange() const {
     81   return LAST_CHANGE;
     82 }
     83 
     84 bool VersionInfo::IsOfficialBuild() const {
     85   return OFFICIAL_BUILD;
     86 }
     87 
     88 #endif
     89 
     90 }  // namespace chrome
     91