OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/login/version_info_updater.h" |
| 6 |
| 7 #include <string> |
| 8 #include <vector> |
| 9 |
| 10 #include "base/string16.h" |
| 11 #include "base/string_util.h" |
| 12 #include "base/stringprintf.h" |
| 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 16 #include "chrome/browser/chromeos/wm_ipc.h" |
| 17 #include "chrome/browser/policy/browser_policy_connector.h" |
| 18 #include "chrome/browser/profiles/profile_manager.h" |
| 19 #include "chrome/common/chrome_version_info.h" |
| 20 #include "googleurl/src/gurl.h" |
| 21 #include "grit/chromium_strings.h" |
| 22 #include "grit/generated_resources.h" |
| 23 #include "grit/theme_resources.h" |
| 24 #include "third_party/cros/chromeos_wm_ipc_enums.h" |
| 25 #include "ui/base/l10n/l10n_util.h" |
| 26 #include "ui/base/resource/resource_bundle.h" |
| 27 |
| 28 namespace chromeos { |
| 29 |
| 30 /////////////////////////////////////////////////////////////////////////////// |
| 31 // VersionInfoUpdater public: |
| 32 |
| 33 VersionInfoUpdater::VersionInfoUpdater(Delegate* delegate) |
| 34 : delegate_(delegate) { |
| 35 } |
| 36 |
| 37 VersionInfoUpdater::~VersionInfoUpdater() { |
| 38 } |
| 39 |
| 40 void VersionInfoUpdater::StartUpdate(bool is_official_build) { |
| 41 if (CrosLibrary::Get()->EnsureLoaded()) { |
| 42 version_loader_.EnablePlatformVersions(true); |
| 43 version_loader_.GetVersion( |
| 44 &version_consumer_, |
| 45 NewCallback(this, &VersionInfoUpdater::OnVersion), |
| 46 is_official_build ? |
| 47 VersionLoader::VERSION_SHORT_WITH_DATE : |
| 48 VersionLoader::VERSION_FULL); |
| 49 if (!is_official_build) { |
| 50 boot_times_loader_.GetBootTimes( |
| 51 &boot_times_consumer_, |
| 52 NewCallback(this, &VersionInfoUpdater::OnBootTimes)); |
| 53 } |
| 54 } else { |
| 55 UpdateVersionLabel(); |
| 56 } |
| 57 |
| 58 policy::CloudPolicySubsystem* cloud_policy = |
| 59 g_browser_process->browser_policy_connector()-> |
| 60 device_cloud_policy_subsystem(); |
| 61 if (cloud_policy) { |
| 62 // Two-step reset because we want to construct new ObserverRegistrar after |
| 63 // destruction of old ObserverRegistrar to avoid DCHECK violation because |
| 64 // of adding existing observer. |
| 65 cloud_policy_registrar_.reset(); |
| 66 cloud_policy_registrar_.reset( |
| 67 new policy::CloudPolicySubsystem::ObserverRegistrar( |
| 68 cloud_policy, this)); |
| 69 |
| 70 // Ensure that we have up-to-date enterprise info in case enterprise policy |
| 71 // is already fetched and has finished initialization. |
| 72 UpdateEnterpriseInfo(); |
| 73 } |
| 74 } |
| 75 |
| 76 void VersionInfoUpdater::UpdateVersionLabel() { |
| 77 if (!CrosLibrary::Get()->EnsureLoaded()) { |
| 78 if (delegate_) { |
| 79 delegate_->OnOSVersionLabelTextUpdated( |
| 80 CrosLibrary::Get()->load_error_string()); |
| 81 } |
| 82 return; |
| 83 } |
| 84 |
| 85 if (version_text_.empty()) |
| 86 return; |
| 87 |
| 88 chrome::VersionInfo version_info; |
| 89 std::string label_text = l10n_util::GetStringUTF8(IDS_PRODUCT_NAME); |
| 90 label_text += ' '; |
| 91 label_text += version_info.Version(); |
| 92 label_text += " ("; |
| 93 // TODO(rkc): Fix this for RTL. |
| 94 // http://code.google.com/p/chromium-os/issues/detail?id=17621 |
| 95 label_text += l10n_util::GetStringUTF8(IDS_PLATFORM_LABEL); |
| 96 label_text += ' '; |
| 97 label_text += version_text_; |
| 98 label_text += ')'; |
| 99 |
| 100 if (!enterprise_domain_text_.empty()) { |
| 101 label_text += ' '; |
| 102 if (enterprise_status_text_.empty()) { |
| 103 label_text += l10n_util::GetStringFUTF8( |
| 104 IDS_LOGIN_MANAGED_BY_LABEL_FORMAT, |
| 105 UTF8ToUTF16(enterprise_domain_text_)); |
| 106 } else { |
| 107 label_text += l10n_util::GetStringFUTF8( |
| 108 IDS_LOGIN_MANAGED_BY_WITH_STATUS_LABEL_FORMAT, |
| 109 UTF8ToUTF16(enterprise_domain_text_), |
| 110 UTF8ToUTF16(enterprise_status_text_)); |
| 111 } |
| 112 } |
| 113 |
| 114 // Workaround over incorrect width calculation in old fonts. |
| 115 // TODO(glotov): remove the following line when new fonts are used. |
| 116 label_text += ' '; |
| 117 |
| 118 if (delegate_) |
| 119 delegate_->OnOSVersionLabelTextUpdated(label_text); |
| 120 } |
| 121 |
| 122 void VersionInfoUpdater::UpdateEnterpriseInfo() { |
| 123 policy::BrowserPolicyConnector* policy_connector = |
| 124 g_browser_process->browser_policy_connector(); |
| 125 |
| 126 std::string status_text; |
| 127 policy::CloudPolicySubsystem* cloud_policy_subsystem = |
| 128 policy_connector->device_cloud_policy_subsystem(); |
| 129 if (cloud_policy_subsystem) { |
| 130 switch (cloud_policy_subsystem->state()) { |
| 131 case policy::CloudPolicySubsystem::UNENROLLED: |
| 132 status_text = l10n_util::GetStringUTF8( |
| 133 IDS_LOGIN_MANAGED_BY_STATUS_PENDING); |
| 134 break; |
| 135 case policy::CloudPolicySubsystem::UNMANAGED: |
| 136 case policy::CloudPolicySubsystem::BAD_GAIA_TOKEN: |
| 137 case policy::CloudPolicySubsystem::LOCAL_ERROR: |
| 138 status_text = l10n_util::GetStringUTF8( |
| 139 IDS_LOGIN_MANAGED_BY_STATUS_LOST_CONNECTION); |
| 140 break; |
| 141 case policy::CloudPolicySubsystem::NETWORK_ERROR: |
| 142 status_text = l10n_util::GetStringUTF8( |
| 143 IDS_LOGIN_MANAGED_BY_STATUS_NETWORK_ERROR); |
| 144 break; |
| 145 case policy::CloudPolicySubsystem::TOKEN_FETCHED: |
| 146 case policy::CloudPolicySubsystem::SUCCESS: |
| 147 break; |
| 148 } |
| 149 } |
| 150 |
| 151 SetEnterpriseInfo(policy_connector->GetEnterpriseDomain(), status_text); |
| 152 } |
| 153 |
| 154 void VersionInfoUpdater::SetEnterpriseInfo(const std::string& domain_name, |
| 155 const std::string& status_text) { |
| 156 if (domain_name != enterprise_domain_text_ || |
| 157 status_text != enterprise_status_text_) { |
| 158 enterprise_domain_text_ = domain_name; |
| 159 enterprise_status_text_ = status_text; |
| 160 UpdateVersionLabel(); |
| 161 } |
| 162 } |
| 163 |
| 164 void VersionInfoUpdater::OnVersion( |
| 165 VersionLoader::Handle handle, std::string version) { |
| 166 version_text_.swap(version); |
| 167 UpdateVersionLabel(); |
| 168 } |
| 169 |
| 170 void VersionInfoUpdater::OnBootTimes( |
| 171 BootTimesLoader::Handle handle, BootTimesLoader::BootTimes boot_times) { |
| 172 const char* kBootTimesNoChromeExec = |
| 173 "Non-firmware boot took %.2f seconds (kernel %.2fs, system %.2fs)"; |
| 174 const char* kBootTimesChromeExec = |
| 175 "Non-firmware boot took %.2f seconds " |
| 176 "(kernel %.2fs, system %.2fs, chrome %.2fs)"; |
| 177 std::string boot_times_text; |
| 178 |
| 179 if (boot_times.chrome > 0) { |
| 180 boot_times_text = |
| 181 base::StringPrintf( |
| 182 kBootTimesChromeExec, |
| 183 boot_times.total, |
| 184 boot_times.pre_startup, |
| 185 boot_times.system, |
| 186 boot_times.chrome); |
| 187 } else { |
| 188 boot_times_text = |
| 189 base::StringPrintf( |
| 190 kBootTimesNoChromeExec, |
| 191 boot_times.total, |
| 192 boot_times.pre_startup, |
| 193 boot_times.system); |
| 194 } |
| 195 // Use UTF8ToWide once this string is localized. |
| 196 if (delegate_) |
| 197 delegate_->OnBootTimesLabelTextUpdated(boot_times_text); |
| 198 } |
| 199 |
| 200 void VersionInfoUpdater::OnPolicyStateChanged( |
| 201 policy::CloudPolicySubsystem::PolicySubsystemState state, |
| 202 policy::CloudPolicySubsystem::ErrorDetails error_details) { |
| 203 UpdateEnterpriseInfo(); |
| 204 } |
| 205 |
| 206 } // namespace chromeos |
| 207 |
OLD | NEW |