Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / version_info_updater.cc
blobfbdd31c94aad0d97b6949d105631ab205a4ed56c
1 // Copyright (c) 2012 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.
5 #include "chrome/browser/chromeos/login/version_info_updater.h"
7 #include <vector>
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "base/sys_info.h"
15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
17 #include "chrome/browser/chromeos/settings/cros_settings.h"
18 #include "chrome/browser/policy/browser_policy_connector.h"
19 #include "chrome/common/chrome_version_info.h"
20 #include "chromeos/settings/cros_settings_names.h"
21 #include "grit/chromium_strings.h"
22 #include "grit/generated_resources.h"
23 #include "grit/theme_resources.h"
24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/resource/resource_bundle.h"
27 namespace chromeos {
29 namespace {
31 const char* kReportingFlags[] = {
32 chromeos::kReportDeviceVersionInfo,
33 chromeos::kReportDeviceActivityTimes,
34 chromeos::kReportDeviceBootMode,
35 chromeos::kReportDeviceLocation,
40 ///////////////////////////////////////////////////////////////////////////////
41 // VersionInfoUpdater public:
43 VersionInfoUpdater::VersionInfoUpdater(Delegate* delegate)
44 : cros_settings_(chromeos::CrosSettings::Get()),
45 delegate_(delegate),
46 weak_pointer_factory_(this) {
49 VersionInfoUpdater::~VersionInfoUpdater() {
50 policy::DeviceCloudPolicyManagerChromeOS* policy_manager =
51 g_browser_process->browser_policy_connector()->
52 GetDeviceCloudPolicyManager();
53 if (policy_manager)
54 policy_manager->core()->store()->RemoveObserver(this);
57 void VersionInfoUpdater::StartUpdate(bool is_official_build) {
58 if (base::SysInfo::IsRunningOnChromeOS()) {
59 version_loader_.GetVersion(
60 is_official_build ? VersionLoader::VERSION_SHORT_WITH_DATE
61 : VersionLoader::VERSION_FULL,
62 base::Bind(&VersionInfoUpdater::OnVersion,
63 weak_pointer_factory_.GetWeakPtr()),
64 &tracker_);
65 } else {
66 UpdateVersionLabel();
69 policy::DeviceCloudPolicyManagerChromeOS* policy_manager =
70 g_browser_process->browser_policy_connector()->
71 GetDeviceCloudPolicyManager();
72 if (policy_manager) {
73 policy_manager->core()->store()->AddObserver(this);
75 // Ensure that we have up-to-date enterprise info in case enterprise policy
76 // is already fetched and has finished initialization.
77 UpdateEnterpriseInfo();
80 // Watch for changes to the reporting flags.
81 base::Closure callback =
82 base::Bind(&VersionInfoUpdater::UpdateEnterpriseInfo,
83 base::Unretained(this));
84 for (unsigned int i = 0; i < arraysize(kReportingFlags); ++i) {
85 subscriptions_.push_back(
86 cros_settings_->AddSettingsObserver(kReportingFlags[i],
87 callback).release());
91 void VersionInfoUpdater::UpdateVersionLabel() {
92 if (version_text_.empty())
93 return;
95 chrome::VersionInfo version_info;
96 std::string label_text = l10n_util::GetStringFUTF8(
97 IDS_LOGIN_VERSION_LABEL_FORMAT,
98 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME),
99 base::UTF8ToUTF16(version_info.Version()),
100 base::UTF8ToUTF16(version_text_));
102 // Workaround over incorrect width calculation in old fonts.
103 // TODO(glotov): remove the following line when new fonts are used.
104 label_text += ' ';
106 if (delegate_)
107 delegate_->OnOSVersionLabelTextUpdated(label_text);
110 void VersionInfoUpdater::UpdateEnterpriseInfo() {
111 SetEnterpriseInfo(
112 g_browser_process->browser_policy_connector()->GetEnterpriseDomain());
115 void VersionInfoUpdater::SetEnterpriseInfo(const std::string& domain_name) {
116 // Update the notification about device status reporting.
117 if (delegate_ && !domain_name.empty()) {
118 std::string enterprise_info;
119 enterprise_info = l10n_util::GetStringFUTF8(
120 IDS_DEVICE_OWNED_BY_NOTICE,
121 base::UTF8ToUTF16(domain_name));
122 delegate_->OnEnterpriseInfoUpdated(enterprise_info);
126 void VersionInfoUpdater::OnVersion(const std::string& version) {
127 version_text_ = version;
128 UpdateVersionLabel();
131 void VersionInfoUpdater::OnStoreLoaded(policy::CloudPolicyStore* store) {
132 UpdateEnterpriseInfo();
135 void VersionInfoUpdater::OnStoreError(policy::CloudPolicyStore* store) {
136 UpdateEnterpriseInfo();
139 } // namespace chromeos