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 delegate_(delegate) { | |
51 cros_settings_ = chromeos::CrosSettings::Get(); | |
52 | |
53 // Watch for changes to the reporting flags. | |
54 for (unsigned int i = 0; i < arraysize(kReportingFlags); ++i) | |
55 cros_settings_->AddSettingsObserver(kReportingFlags[i], this); | |
37 } | 56 } |
38 | 57 |
39 VersionInfoUpdater::~VersionInfoUpdater() { | 58 VersionInfoUpdater::~VersionInfoUpdater() { |
40 } | 59 } |
41 | 60 |
42 void VersionInfoUpdater::StartUpdate(bool is_official_build) { | 61 void VersionInfoUpdater::StartUpdate(bool is_official_build) { |
43 if (base::chromeos::IsRunningOnChromeOS()) { | 62 if (base::chromeos::IsRunningOnChromeOS()) { |
44 version_loader_.GetVersion( | 63 version_loader_.GetVersion( |
45 &version_consumer_, | 64 &version_consumer_, |
46 base::Bind(&VersionInfoUpdater::OnVersion, base::Unretained(this)), | 65 base::Bind(&VersionInfoUpdater::OnVersion, base::Unretained(this)), |
(...skipping 90 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)) | |
Patrick Dubroy
2012/03/26 08:28:20
Why not just "="? Using bitwise OR on a boolean se
Mattias Nissler (ping if slow)
2012/03/26 13:08:26
Done.
| |
170 reporting_hint |= enabled; | |
171 } | |
172 | |
173 SetEnterpriseInfo(policy_connector->GetEnterpriseDomain(), | |
174 status_text, | |
175 reporting_hint); | |
148 } | 176 } |
149 | 177 |
150 void VersionInfoUpdater::SetEnterpriseInfo(const std::string& domain_name, | 178 void VersionInfoUpdater::SetEnterpriseInfo(const std::string& domain_name, |
151 const std::string& status_text) { | 179 const std::string& status_text, |
180 bool reporting_hint) { | |
152 if (domain_name != enterprise_domain_text_ || | 181 if (domain_name != enterprise_domain_text_ || |
153 status_text != enterprise_status_text_) { | 182 status_text != enterprise_status_text_ || |
183 reporting_hint != enterprise_reporting_hint_) { | |
154 enterprise_domain_text_ = domain_name; | 184 enterprise_domain_text_ = domain_name; |
155 enterprise_status_text_ = status_text; | 185 enterprise_status_text_ = status_text; |
186 enterprise_reporting_hint_ = enterprise_reporting_hint_; | |
156 UpdateVersionLabel(); | 187 UpdateVersionLabel(); |
157 | 188 |
158 // Update the notification about device status reporting. | 189 // Update the notification about device status reporting. |
159 if (delegate_) { | 190 if (delegate_) { |
160 std::string enterprise_info; | 191 std::string enterprise_info; |
161 if (!domain_name.empty()) { | 192 if (!domain_name.empty()) { |
162 enterprise_info = l10n_util::GetStringFUTF8( | 193 enterprise_info = l10n_util::GetStringFUTF8( |
163 IDS_LOGIN_MANAGED_BY_NOTICE, | 194 IDS_LOGIN_MANAGED_BY_NOTICE, |
164 UTF8ToUTF16(enterprise_domain_text_)); | 195 UTF8ToUTF16(enterprise_domain_text_)); |
165 delegate_->OnEnterpriseInfoUpdated(enterprise_info); | 196 delegate_->OnEnterpriseInfoUpdated(enterprise_info, reporting_hint); |
166 } | 197 } |
167 } | 198 } |
168 } | 199 } |
169 } | 200 } |
170 | 201 |
171 void VersionInfoUpdater::OnVersion( | 202 void VersionInfoUpdater::OnVersion( |
172 VersionLoader::Handle handle, std::string version) { | 203 VersionLoader::Handle handle, std::string version) { |
173 version_text_.swap(version); | 204 version_text_.swap(version); |
174 UpdateVersionLabel(); | 205 UpdateVersionLabel(); |
175 } | 206 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 if (delegate_) | 238 if (delegate_) |
208 delegate_->OnBootTimesLabelTextUpdated(boot_times_text); | 239 delegate_->OnBootTimesLabelTextUpdated(boot_times_text); |
209 } | 240 } |
210 | 241 |
211 void VersionInfoUpdater::OnPolicyStateChanged( | 242 void VersionInfoUpdater::OnPolicyStateChanged( |
212 policy::CloudPolicySubsystem::PolicySubsystemState state, | 243 policy::CloudPolicySubsystem::PolicySubsystemState state, |
213 policy::CloudPolicySubsystem::ErrorDetails error_details) { | 244 policy::CloudPolicySubsystem::ErrorDetails error_details) { |
214 UpdateEnterpriseInfo(); | 245 UpdateEnterpriseInfo(); |
215 } | 246 } |
216 | 247 |
248 void VersionInfoUpdater::Observe( | |
249 int type, | |
250 const content::NotificationSource& source, | |
251 const content::NotificationDetails& details) { | |
252 if (type == chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED) | |
253 UpdateEnterpriseInfo(); | |
254 else | |
255 NOTREACHED(); | |
256 } | |
257 | |
217 } // namespace chromeos | 258 } // namespace chromeos |
OLD | NEW |