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