Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/login/version_info_updater.h" | 5 #include "chrome/browser/chromeos/login/version_info_updater.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/chromeos/chromeos_version.h" | 11 #include "base/chromeos/chromeos_version.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
|
Mattias Nissler (ping if slow)
2013/09/18 09:09:48
remove?
Avi (use Gerrit)
2013/09/18 16:41:44
Done.
| |
| 17 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" | 17 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
| 18 #include "chrome/browser/chromeos/settings/cros_settings.h" | 18 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 19 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 19 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
| 20 #include "chrome/browser/policy/browser_policy_connector.h" | 20 #include "chrome/browser/policy/browser_policy_connector.h" |
| 21 #include "chrome/common/chrome_version_info.h" | 21 #include "chrome/common/chrome_version_info.h" |
| 22 #include "grit/chromium_strings.h" | 22 #include "grit/chromium_strings.h" |
| 23 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 24 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 26 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
| 27 | 27 |
| 28 namespace chromeos { | 28 namespace chromeos { |
| 29 | 29 |
| 30 namespace { | |
| 31 | |
| 32 const char* kReportingFlags[] = { | |
| 33 chromeos::kReportDeviceVersionInfo, | |
| 34 chromeos::kReportDeviceActivityTimes, | |
| 35 chromeos::kReportDeviceBootMode, | |
| 36 chromeos::kReportDeviceLocation, | |
| 37 }; | |
| 38 | |
| 39 } | |
| 40 | |
| 41 /////////////////////////////////////////////////////////////////////////////// | 30 /////////////////////////////////////////////////////////////////////////////// |
| 42 // VersionInfoUpdater public: | 31 // VersionInfoUpdater public: |
| 43 | 32 |
| 44 VersionInfoUpdater::VersionInfoUpdater(Delegate* delegate) | 33 VersionInfoUpdater::VersionInfoUpdater(Delegate* delegate) |
| 45 : cros_settings_(chromeos::CrosSettings::Get()), | 34 : cros_settings_(chromeos::CrosSettings::Get()), |
| 46 delegate_(delegate), | 35 delegate_(delegate), |
| 47 weak_pointer_factory_(this) { | 36 weak_pointer_factory_(this) { |
| 48 } | 37 } |
| 49 | 38 |
| 50 VersionInfoUpdater::~VersionInfoUpdater() { | 39 VersionInfoUpdater::~VersionInfoUpdater() { |
| 51 policy::DeviceCloudPolicyManagerChromeOS* policy_manager = | 40 policy::DeviceCloudPolicyManagerChromeOS* policy_manager = |
| 52 g_browser_process->browser_policy_connector()-> | 41 g_browser_process->browser_policy_connector()-> |
| 53 GetDeviceCloudPolicyManager(); | 42 GetDeviceCloudPolicyManager(); |
| 54 if (policy_manager) | 43 if (policy_manager) |
| 55 policy_manager->core()->store()->RemoveObserver(this); | 44 policy_manager->core()->store()->RemoveObserver(this); |
| 56 | |
| 57 for (unsigned int i = 0; i < arraysize(kReportingFlags); ++i) | |
| 58 cros_settings_->RemoveSettingsObserver(kReportingFlags[i], this); | |
| 59 } | 45 } |
| 60 | 46 |
| 61 void VersionInfoUpdater::StartUpdate(bool is_official_build) { | 47 void VersionInfoUpdater::StartUpdate(bool is_official_build) { |
| 62 if (base::chromeos::IsRunningOnChromeOS()) { | 48 if (base::chromeos::IsRunningOnChromeOS()) { |
| 63 version_loader_.GetVersion( | 49 version_loader_.GetVersion( |
| 64 is_official_build ? VersionLoader::VERSION_SHORT_WITH_DATE | 50 is_official_build ? VersionLoader::VERSION_SHORT_WITH_DATE |
| 65 : VersionLoader::VERSION_FULL, | 51 : VersionLoader::VERSION_FULL, |
| 66 base::Bind(&VersionInfoUpdater::OnVersion, | 52 base::Bind(&VersionInfoUpdater::OnVersion, |
| 67 weak_pointer_factory_.GetWeakPtr()), | 53 weak_pointer_factory_.GetWeakPtr()), |
| 68 &tracker_); | 54 &tracker_); |
| 69 } else { | 55 } else { |
| 70 UpdateVersionLabel(); | 56 UpdateVersionLabel(); |
| 71 } | 57 } |
| 72 | 58 |
| 73 policy::DeviceCloudPolicyManagerChromeOS* policy_manager = | 59 policy::DeviceCloudPolicyManagerChromeOS* policy_manager = |
| 74 g_browser_process->browser_policy_connector()-> | 60 g_browser_process->browser_policy_connector()-> |
| 75 GetDeviceCloudPolicyManager(); | 61 GetDeviceCloudPolicyManager(); |
| 76 if (policy_manager) { | 62 if (policy_manager) { |
| 77 policy_manager->core()->store()->AddObserver(this); | 63 policy_manager->core()->store()->AddObserver(this); |
| 78 | 64 |
| 79 // Ensure that we have up-to-date enterprise info in case enterprise policy | 65 // Ensure that we have up-to-date enterprise info in case enterprise policy |
| 80 // is already fetched and has finished initialization. | 66 // is already fetched and has finished initialization. |
| 81 UpdateEnterpriseInfo(); | 67 UpdateEnterpriseInfo(); |
| 82 } | 68 } |
| 83 | 69 |
| 84 // Watch for changes to the reporting flags. | 70 // Watch for changes to the reporting flags. |
| 85 for (unsigned int i = 0; i < arraysize(kReportingFlags); ++i) | 71 version_info_subscription_ = cros_settings_->AddSettingsObserver( |
| 86 cros_settings_->AddSettingsObserver(kReportingFlags[i], this); | 72 kReportDeviceVersionInfo, |
| 73 base::Bind(&VersionInfoUpdater::UpdateEnterpriseInfo, | |
|
Lei Zhang
2013/09/18 05:00:53
Can you assign this to a base::Closure variable an
Mattias Nissler (ping if slow)
2013/09/18 09:09:48
Could also keep the array and loop in that case an
Avi (use Gerrit)
2013/09/18 16:41:44
Done.
Lei Zhang
2013/09/18 18:51:07
chrome/browser/chromeos/login/existing_user_contro
Avi (use Gerrit)
2013/09/18 19:39:07
If you look at ExistingUserControllerAutoLoginTest
| |
| 74 base::Unretained(this))); | |
| 75 activity_times_subscription_ = cros_settings_->AddSettingsObserver( | |
| 76 kReportDeviceActivityTimes, | |
| 77 base::Bind(&VersionInfoUpdater::UpdateEnterpriseInfo, | |
| 78 base::Unretained(this))); | |
| 79 boot_mode_subscription_ = cros_settings_->AddSettingsObserver( | |
| 80 kReportDeviceBootMode, | |
| 81 base::Bind(&VersionInfoUpdater::UpdateEnterpriseInfo, | |
| 82 base::Unretained(this))); | |
| 83 location_subscription_ = cros_settings_->AddSettingsObserver( | |
| 84 kReportDeviceLocation, | |
| 85 base::Bind(&VersionInfoUpdater::UpdateEnterpriseInfo, | |
| 86 base::Unretained(this))); | |
| 87 } | 87 } |
| 88 | 88 |
| 89 void VersionInfoUpdater::UpdateVersionLabel() { | 89 void VersionInfoUpdater::UpdateVersionLabel() { |
| 90 if (version_text_.empty()) | 90 if (version_text_.empty()) |
| 91 return; | 91 return; |
| 92 | 92 |
| 93 chrome::VersionInfo version_info; | 93 chrome::VersionInfo version_info; |
| 94 std::string label_text = l10n_util::GetStringFUTF8( | 94 std::string label_text = l10n_util::GetStringFUTF8( |
| 95 IDS_LOGIN_VERSION_LABEL_FORMAT, | 95 IDS_LOGIN_VERSION_LABEL_FORMAT, |
| 96 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), | 96 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 127 } | 127 } |
| 128 | 128 |
| 129 void VersionInfoUpdater::OnStoreLoaded(policy::CloudPolicyStore* store) { | 129 void VersionInfoUpdater::OnStoreLoaded(policy::CloudPolicyStore* store) { |
| 130 UpdateEnterpriseInfo(); | 130 UpdateEnterpriseInfo(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void VersionInfoUpdater::OnStoreError(policy::CloudPolicyStore* store) { | 133 void VersionInfoUpdater::OnStoreError(policy::CloudPolicyStore* store) { |
| 134 UpdateEnterpriseInfo(); | 134 UpdateEnterpriseInfo(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 void VersionInfoUpdater::Observe( | |
| 138 int type, | |
| 139 const content::NotificationSource& source, | |
| 140 const content::NotificationDetails& details) { | |
| 141 if (type == chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED) | |
| 142 UpdateEnterpriseInfo(); | |
| 143 else | |
| 144 NOTREACHED(); | |
| 145 } | |
| 146 | |
| 147 } // namespace chromeos | 137 } // namespace chromeos |
| OLD | NEW |