Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1118)

Unified Diff: chrome/browser/chromeos/login/version_info_updater.cc

Issue 7564028: Added version info to WebUI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added boot times label Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/version_info_updater.cc
diff --git a/chrome/browser/chromeos/login/version_info_updater.cc b/chrome/browser/chromeos/login/version_info_updater.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c2b1398bad2322dafa429270c3e6d6ca619137c4
--- /dev/null
+++ b/chrome/browser/chromeos/login/version_info_updater.cc
@@ -0,0 +1,207 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/login/version_info_updater.h"
+
+#include <string>
+#include <vector>
+
+#include "base/string16.h"
+#include "base/string_util.h"
+#include "base/stringprintf.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
+#include "chrome/browser/chromeos/wm_ipc.h"
+#include "chrome/browser/policy/browser_policy_connector.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/common/chrome_version_info.h"
+#include "googleurl/src/gurl.h"
+#include "grit/chromium_strings.h"
+#include "grit/generated_resources.h"
+#include "grit/theme_resources.h"
+#include "third_party/cros/chromeos_wm_ipc_enums.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
+
+namespace chromeos {
+
+///////////////////////////////////////////////////////////////////////////////
+// VersionInfoUpdater public:
+
+VersionInfoUpdater::VersionInfoUpdater(Delegate* delegate)
+ : delegate_(delegate) {
+}
+
+VersionInfoUpdater::~VersionInfoUpdater() {
+}
+
+void VersionInfoUpdater::StartUpdate(bool is_official_build) {
+ if (CrosLibrary::Get()->EnsureLoaded()) {
+ version_loader_.EnablePlatformVersions(true);
+ version_loader_.GetVersion(
+ &version_consumer_,
+ NewCallback(this, &VersionInfoUpdater::OnVersion),
+ is_official_build ?
+ VersionLoader::VERSION_SHORT_WITH_DATE :
+ VersionLoader::VERSION_FULL);
+ if (!is_official_build) {
+ boot_times_loader_.GetBootTimes(
+ &boot_times_consumer_,
+ NewCallback(this, &VersionInfoUpdater::OnBootTimes));
+ }
+ } else {
+ UpdateVersionLabel();
+ }
+
+ policy::CloudPolicySubsystem* cloud_policy =
+ g_browser_process->browser_policy_connector()->
+ device_cloud_policy_subsystem();
+ if (cloud_policy) {
+ // Two-step reset because we want to construct new ObserverRegistrar after
+ // destruction of old ObserverRegistrar to avoid DCHECK violation because
+ // of adding existing observer.
+ cloud_policy_registrar_.reset();
+ cloud_policy_registrar_.reset(
+ new policy::CloudPolicySubsystem::ObserverRegistrar(
+ cloud_policy, this));
+
+ // Ensure that we have up-to-date enterprise info in case enterprise policy
+ // is already fetched and has finished initialization.
+ UpdateEnterpriseInfo();
+ }
+}
+
+void VersionInfoUpdater::UpdateVersionLabel() {
+ if (!CrosLibrary::Get()->EnsureLoaded()) {
+ if (delegate_) {
+ delegate_->OnOSVersionLabelTextUpdated(
+ CrosLibrary::Get()->load_error_string());
+ }
+ return;
+ }
+
+ if (version_text_.empty())
+ return;
+
+ chrome::VersionInfo version_info;
+ std::string label_text = l10n_util::GetStringUTF8(IDS_PRODUCT_NAME);
+ label_text += ' ';
+ label_text += version_info.Version();
+ label_text += " (";
+ // TODO(rkc): Fix this for RTL.
+ // http://code.google.com/p/chromium-os/issues/detail?id=17621
+ label_text += l10n_util::GetStringUTF8(IDS_PLATFORM_LABEL);
+ label_text += ' ';
+ label_text += version_text_;
+ label_text += ')';
+
+ if (!enterprise_domain_text_.empty()) {
+ label_text += ' ';
+ if (enterprise_status_text_.empty()) {
+ label_text += l10n_util::GetStringFUTF8(
+ IDS_LOGIN_MANAGED_BY_LABEL_FORMAT,
+ UTF8ToUTF16(enterprise_domain_text_));
+ } else {
+ label_text += l10n_util::GetStringFUTF8(
+ IDS_LOGIN_MANAGED_BY_WITH_STATUS_LABEL_FORMAT,
+ UTF8ToUTF16(enterprise_domain_text_),
+ UTF8ToUTF16(enterprise_status_text_));
+ }
+ }
+
+ // Workaround over incorrect width calculation in old fonts.
+ // TODO(glotov): remove the following line when new fonts are used.
+ label_text += ' ';
+
+ if (delegate_)
+ delegate_->OnOSVersionLabelTextUpdated(label_text);
+}
+
+void VersionInfoUpdater::UpdateEnterpriseInfo() {
+ policy::BrowserPolicyConnector* policy_connector =
+ g_browser_process->browser_policy_connector();
+
+ std::string status_text;
+ policy::CloudPolicySubsystem* cloud_policy_subsystem =
+ policy_connector->device_cloud_policy_subsystem();
+ if (cloud_policy_subsystem) {
+ switch (cloud_policy_subsystem->state()) {
+ case policy::CloudPolicySubsystem::UNENROLLED:
+ status_text = l10n_util::GetStringUTF8(
+ IDS_LOGIN_MANAGED_BY_STATUS_PENDING);
+ break;
+ case policy::CloudPolicySubsystem::UNMANAGED:
+ case policy::CloudPolicySubsystem::BAD_GAIA_TOKEN:
+ case policy::CloudPolicySubsystem::LOCAL_ERROR:
+ status_text = l10n_util::GetStringUTF8(
+ IDS_LOGIN_MANAGED_BY_STATUS_LOST_CONNECTION);
+ break;
+ case policy::CloudPolicySubsystem::NETWORK_ERROR:
+ status_text = l10n_util::GetStringUTF8(
+ IDS_LOGIN_MANAGED_BY_STATUS_NETWORK_ERROR);
+ break;
+ case policy::CloudPolicySubsystem::TOKEN_FETCHED:
+ case policy::CloudPolicySubsystem::SUCCESS:
+ break;
+ }
+ }
+
+ SetEnterpriseInfo(policy_connector->GetEnterpriseDomain(), status_text);
+}
+
+void VersionInfoUpdater::SetEnterpriseInfo(const std::string& domain_name,
+ const std::string& status_text) {
+ if (domain_name != enterprise_domain_text_ ||
+ status_text != enterprise_status_text_) {
+ enterprise_domain_text_ = domain_name;
+ enterprise_status_text_ = status_text;
+ UpdateVersionLabel();
+ }
+}
+
+void VersionInfoUpdater::OnVersion(
+ VersionLoader::Handle handle, std::string version) {
+ version_text_.swap(version);
+ UpdateVersionLabel();
+}
+
+void VersionInfoUpdater::OnBootTimes(
+ BootTimesLoader::Handle handle, BootTimesLoader::BootTimes boot_times) {
+ const char* kBootTimesNoChromeExec =
+ "Non-firmware boot took %.2f seconds (kernel %.2fs, system %.2fs)";
+ const char* kBootTimesChromeExec =
+ "Non-firmware boot took %.2f seconds "
+ "(kernel %.2fs, system %.2fs, chrome %.2fs)";
+ std::string boot_times_text;
+
+ if (boot_times.chrome > 0) {
+ boot_times_text =
+ base::StringPrintf(
+ kBootTimesChromeExec,
+ boot_times.total,
+ boot_times.pre_startup,
+ boot_times.system,
+ boot_times.chrome);
+ } else {
+ boot_times_text =
+ base::StringPrintf(
+ kBootTimesNoChromeExec,
+ boot_times.total,
+ boot_times.pre_startup,
+ boot_times.system);
+ }
+ // Use UTF8ToWide once this string is localized.
+ if (delegate_)
+ delegate_->OnBootTimesLabelTextUpdated(boot_times_text);
+}
+
+void VersionInfoUpdater::OnPolicyStateChanged(
+ policy::CloudPolicySubsystem::PolicySubsystemState state,
+ policy::CloudPolicySubsystem::ErrorDetails error_details) {
+ UpdateEnterpriseInfo();
+}
+
+} // namespace chromeos
+
« no previous file with comments | « chrome/browser/chromeos/login/version_info_updater.h ('k') | chrome/browser/resources/chromeos/login/oobe.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698