This source file includes following definitions.
- weak_pointer_factory_
- StartUpdate
- UpdateVersionLabel
- UpdateEnterpriseInfo
- SetEnterpriseInfo
- OnVersion
- OnStoreLoaded
- OnStoreError
#include "chrome/browser/chromeos/login/version_info_updater.h"
#include <vector>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/sys_info.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/common/chrome_version_info.h"
#include "chromeos/settings/cros_settings_names.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
namespace chromeos {
namespace {
const char* kReportingFlags[] = {
chromeos::kReportDeviceVersionInfo,
chromeos::kReportDeviceActivityTimes,
chromeos::kReportDeviceBootMode,
chromeos::kReportDeviceLocation,
};
}
VersionInfoUpdater::VersionInfoUpdater(Delegate* delegate)
: cros_settings_(chromeos::CrosSettings::Get()),
delegate_(delegate),
weak_pointer_factory_(this) {
}
VersionInfoUpdater::~VersionInfoUpdater() {
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
policy::DeviceCloudPolicyManagerChromeOS* policy_manager =
connector->GetDeviceCloudPolicyManager();
if (policy_manager)
policy_manager->core()->store()->RemoveObserver(this);
}
void VersionInfoUpdater::StartUpdate(bool is_official_build) {
if (base::SysInfo::IsRunningOnChromeOS()) {
version_loader_.GetVersion(
is_official_build ? VersionLoader::VERSION_SHORT_WITH_DATE
: VersionLoader::VERSION_FULL,
base::Bind(&VersionInfoUpdater::OnVersion,
weak_pointer_factory_.GetWeakPtr()),
&tracker_);
} else {
UpdateVersionLabel();
}
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
policy::DeviceCloudPolicyManagerChromeOS* policy_manager =
connector->GetDeviceCloudPolicyManager();
if (policy_manager) {
policy_manager->core()->store()->AddObserver(this);
UpdateEnterpriseInfo();
}
base::Closure callback =
base::Bind(&VersionInfoUpdater::UpdateEnterpriseInfo,
base::Unretained(this));
for (unsigned int i = 0; i < arraysize(kReportingFlags); ++i) {
subscriptions_.push_back(
cros_settings_->AddSettingsObserver(kReportingFlags[i],
callback).release());
}
}
void VersionInfoUpdater::UpdateVersionLabel() {
if (version_text_.empty())
return;
chrome::VersionInfo version_info;
std::string label_text = l10n_util::GetStringFUTF8(
IDS_LOGIN_VERSION_LABEL_FORMAT,
l10n_util::GetStringUTF16(IDS_PRODUCT_NAME),
base::UTF8ToUTF16(version_info.Version()),
base::UTF8ToUTF16(version_text_));
label_text += ' ';
if (delegate_)
delegate_->OnOSVersionLabelTextUpdated(label_text);
}
void VersionInfoUpdater::UpdateEnterpriseInfo() {
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
SetEnterpriseInfo(connector->GetEnterpriseDomain());
}
void VersionInfoUpdater::SetEnterpriseInfo(const std::string& domain_name) {
if (delegate_ && !domain_name.empty()) {
std::string enterprise_info;
enterprise_info = l10n_util::GetStringFUTF8(
IDS_DEVICE_OWNED_BY_NOTICE,
base::UTF8ToUTF16(domain_name));
delegate_->OnEnterpriseInfoUpdated(enterprise_info);
}
}
void VersionInfoUpdater::OnVersion(const std::string& version) {
version_text_ = version;
UpdateVersionLabel();
}
void VersionInfoUpdater::OnStoreLoaded(policy::CloudPolicyStore* store) {
UpdateEnterpriseInfo();
}
void VersionInfoUpdater::OnStoreError(policy::CloudPolicyStore* store) {
UpdateEnterpriseInfo();
}
}