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