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 <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/chromeos/chromeos_version.h" | 12 #include "base/chromeos/chromeos_version.h" |
13 #include "base/string16.h" | 13 #include "base/string16.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/chromeos/cros/cros_library.h" | 18 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 19 #include "chrome/browser/chromeos/cros_settings.h" |
| 20 #include "chrome/browser/chromeos/cros_settings_names.h" |
19 #include "chrome/browser/policy/browser_policy_connector.h" | 21 #include "chrome/browser/policy/browser_policy_connector.h" |
20 #include "chrome/browser/profiles/profile_manager.h" | 22 #include "chrome/browser/profiles/profile_manager.h" |
| 23 #include "chrome/common/chrome_notification_types.h" |
21 #include "chrome/common/chrome_version_info.h" | 24 #include "chrome/common/chrome_version_info.h" |
22 #include "googleurl/src/gurl.h" | 25 #include "googleurl/src/gurl.h" |
23 #include "grit/chromium_strings.h" | 26 #include "grit/chromium_strings.h" |
24 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
25 #include "grit/theme_resources.h" | 28 #include "grit/theme_resources.h" |
26 #include "third_party/cros_system_api/window_manager/chromeos_wm_ipc_enums.h" | 29 #include "third_party/cros_system_api/window_manager/chromeos_wm_ipc_enums.h" |
27 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
28 #include "ui/base/resource/resource_bundle.h" | 31 #include "ui/base/resource/resource_bundle.h" |
29 | 32 |
30 namespace chromeos { | 33 namespace chromeos { |
31 | 34 |
| 35 namespace { |
| 36 |
| 37 const char* kReportingFlags[] = { |
| 38 chromeos::kReportDeviceVersionInfo, |
| 39 chromeos::kReportDeviceActivityTimes, |
| 40 chromeos::kReportDeviceBootMode, |
| 41 }; |
| 42 |
| 43 } |
| 44 |
32 /////////////////////////////////////////////////////////////////////////////// | 45 /////////////////////////////////////////////////////////////////////////////// |
33 // VersionInfoUpdater public: | 46 // VersionInfoUpdater public: |
34 | 47 |
35 VersionInfoUpdater::VersionInfoUpdater(Delegate* delegate) | 48 VersionInfoUpdater::VersionInfoUpdater(Delegate* delegate) |
36 : delegate_(delegate) { | 49 : enterprise_reporting_hint_(false), |
| 50 cros_settings_(chromeos::CrosSettings::Get()), |
| 51 delegate_(delegate) { |
37 } | 52 } |
38 | 53 |
39 VersionInfoUpdater::~VersionInfoUpdater() { | 54 VersionInfoUpdater::~VersionInfoUpdater() { |
40 } | 55 } |
41 | 56 |
42 void VersionInfoUpdater::StartUpdate(bool is_official_build) { | 57 void VersionInfoUpdater::StartUpdate(bool is_official_build) { |
43 if (base::chromeos::IsRunningOnChromeOS()) { | 58 if (base::chromeos::IsRunningOnChromeOS()) { |
44 version_loader_.GetVersion( | 59 version_loader_.GetVersion( |
45 &version_consumer_, | 60 &version_consumer_, |
46 base::Bind(&VersionInfoUpdater::OnVersion, base::Unretained(this)), | 61 base::Bind(&VersionInfoUpdater::OnVersion, base::Unretained(this)), |
(...skipping 18 matching lines...) Expand all Loading... |
65 // of adding existing observer. | 80 // of adding existing observer. |
66 cloud_policy_registrar_.reset(); | 81 cloud_policy_registrar_.reset(); |
67 cloud_policy_registrar_.reset( | 82 cloud_policy_registrar_.reset( |
68 new policy::CloudPolicySubsystem::ObserverRegistrar( | 83 new policy::CloudPolicySubsystem::ObserverRegistrar( |
69 cloud_policy, this)); | 84 cloud_policy, this)); |
70 | 85 |
71 // Ensure that we have up-to-date enterprise info in case enterprise policy | 86 // Ensure that we have up-to-date enterprise info in case enterprise policy |
72 // is already fetched and has finished initialization. | 87 // is already fetched and has finished initialization. |
73 UpdateEnterpriseInfo(); | 88 UpdateEnterpriseInfo(); |
74 } | 89 } |
| 90 |
| 91 // Watch for changes to the reporting flags. |
| 92 for (unsigned int i = 0; i < arraysize(kReportingFlags); ++i) |
| 93 cros_settings_->AddSettingsObserver(kReportingFlags[i], this); |
75 } | 94 } |
76 | 95 |
77 void VersionInfoUpdater::UpdateVersionLabel() { | 96 void VersionInfoUpdater::UpdateVersionLabel() { |
78 if (!base::chromeos::IsRunningOnChromeOS()) { | 97 if (!base::chromeos::IsRunningOnChromeOS()) { |
79 if (delegate_) { | 98 if (delegate_) { |
80 delegate_->OnOSVersionLabelTextUpdated( | 99 delegate_->OnOSVersionLabelTextUpdated( |
81 CrosLibrary::Get()->load_error_string()); | 100 CrosLibrary::Get()->load_error_string()); |
82 } | 101 } |
83 return; | 102 return; |
84 } | 103 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 case policy::CloudPolicySubsystem::NETWORK_ERROR: | 156 case policy::CloudPolicySubsystem::NETWORK_ERROR: |
138 status_text = l10n_util::GetStringUTF8( | 157 status_text = l10n_util::GetStringUTF8( |
139 IDS_LOGIN_MANAGED_BY_STATUS_NETWORK_ERROR); | 158 IDS_LOGIN_MANAGED_BY_STATUS_NETWORK_ERROR); |
140 break; | 159 break; |
141 case policy::CloudPolicySubsystem::TOKEN_FETCHED: | 160 case policy::CloudPolicySubsystem::TOKEN_FETCHED: |
142 case policy::CloudPolicySubsystem::SUCCESS: | 161 case policy::CloudPolicySubsystem::SUCCESS: |
143 break; | 162 break; |
144 } | 163 } |
145 } | 164 } |
146 | 165 |
147 SetEnterpriseInfo(policy_connector->GetEnterpriseDomain(), status_text); | 166 bool reporting_hint = false; |
| 167 for (unsigned int i = 0; i < arraysize(kReportingFlags); ++i) { |
| 168 bool enabled = false; |
| 169 if (cros_settings_->GetBoolean(kReportingFlags[i], &enabled) && enabled) { |
| 170 reporting_hint = true; |
| 171 break; |
| 172 } |
| 173 } |
| 174 |
| 175 SetEnterpriseInfo(policy_connector->GetEnterpriseDomain(), |
| 176 status_text, |
| 177 reporting_hint); |
148 } | 178 } |
149 | 179 |
150 void VersionInfoUpdater::SetEnterpriseInfo(const std::string& domain_name, | 180 void VersionInfoUpdater::SetEnterpriseInfo(const std::string& domain_name, |
151 const std::string& status_text) { | 181 const std::string& status_text, |
| 182 bool reporting_hint) { |
152 if (domain_name != enterprise_domain_text_ || | 183 if (domain_name != enterprise_domain_text_ || |
153 status_text != enterprise_status_text_) { | 184 status_text != enterprise_status_text_ || |
| 185 reporting_hint != enterprise_reporting_hint_) { |
154 enterprise_domain_text_ = domain_name; | 186 enterprise_domain_text_ = domain_name; |
155 enterprise_status_text_ = status_text; | 187 enterprise_status_text_ = status_text; |
| 188 enterprise_reporting_hint_ = enterprise_reporting_hint_; |
156 UpdateVersionLabel(); | 189 UpdateVersionLabel(); |
157 | 190 |
158 // Update the notification about device status reporting. | 191 // Update the notification about device status reporting. |
159 if (delegate_) { | 192 if (delegate_) { |
160 std::string enterprise_info; | 193 std::string enterprise_info; |
161 if (!domain_name.empty()) { | 194 if (!domain_name.empty()) { |
162 enterprise_info = l10n_util::GetStringFUTF8( | 195 enterprise_info = l10n_util::GetStringFUTF8( |
163 IDS_LOGIN_MANAGED_BY_NOTICE, | 196 IDS_LOGIN_MANAGED_BY_NOTICE, |
164 UTF8ToUTF16(enterprise_domain_text_)); | 197 UTF8ToUTF16(enterprise_domain_text_)); |
165 delegate_->OnEnterpriseInfoUpdated(enterprise_info); | 198 delegate_->OnEnterpriseInfoUpdated(enterprise_info, reporting_hint); |
166 } | 199 } |
167 } | 200 } |
168 } | 201 } |
169 } | 202 } |
170 | 203 |
171 void VersionInfoUpdater::OnVersion( | 204 void VersionInfoUpdater::OnVersion( |
172 VersionLoader::Handle handle, std::string version) { | 205 VersionLoader::Handle handle, std::string version) { |
173 version_text_.swap(version); | 206 version_text_.swap(version); |
174 UpdateVersionLabel(); | 207 UpdateVersionLabel(); |
175 } | 208 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 if (delegate_) | 240 if (delegate_) |
208 delegate_->OnBootTimesLabelTextUpdated(boot_times_text); | 241 delegate_->OnBootTimesLabelTextUpdated(boot_times_text); |
209 } | 242 } |
210 | 243 |
211 void VersionInfoUpdater::OnPolicyStateChanged( | 244 void VersionInfoUpdater::OnPolicyStateChanged( |
212 policy::CloudPolicySubsystem::PolicySubsystemState state, | 245 policy::CloudPolicySubsystem::PolicySubsystemState state, |
213 policy::CloudPolicySubsystem::ErrorDetails error_details) { | 246 policy::CloudPolicySubsystem::ErrorDetails error_details) { |
214 UpdateEnterpriseInfo(); | 247 UpdateEnterpriseInfo(); |
215 } | 248 } |
216 | 249 |
| 250 void VersionInfoUpdater::Observe( |
| 251 int type, |
| 252 const content::NotificationSource& source, |
| 253 const content::NotificationDetails& details) { |
| 254 if (type == chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED) |
| 255 UpdateEnterpriseInfo(); |
| 256 else |
| 257 NOTREACHED(); |
| 258 } |
| 259 |
217 } // namespace chromeos | 260 } // namespace chromeos |
OLD | NEW |