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/ui/webui/help/version_updater_chromeos.h" | 5 #include "chrome/browser/ui/webui/help/version_updater_chromeos.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
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 "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/chromeos/login/startup_utils.h" | 12 #include "chrome/browser/chromeos/login/startup_utils.h" |
13 #include "chrome/browser/chromeos/login/wizard_controller.h" | 13 #include "chrome/browser/chromeos/login/wizard_controller.h" |
14 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" | |
15 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact
ory.h" | |
16 #include "chrome/browser/chromeos/settings/cros_settings.h" | 14 #include "chrome/browser/chromeos/settings/cros_settings.h" |
17 #include "chrome/browser/ui/webui/help/help_utils_chromeos.h" | 15 #include "chrome/browser/ui/webui/help/help_utils_chromeos.h" |
18 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
19 #include "chromeos/dbus/dbus_thread_manager.h" | 17 #include "chromeos/dbus/dbus_thread_manager.h" |
20 #include "chromeos/dbus/power_manager_client.h" | 18 #include "chromeos/dbus/power_manager_client.h" |
21 #include "chromeos/network/network_handler.h" | 19 #include "chromeos/network/network_handler.h" |
22 #include "chromeos/network/network_state.h" | 20 #include "chromeos/network/network_state.h" |
23 #include "chromeos/network/network_state_handler.h" | 21 #include "chromeos/network/network_state_handler.h" |
24 #include "chromeos/settings/cros_settings_names.h" | 22 #include "chromeos/settings/cros_settings_names.h" |
| 23 #include "components/user_manager/user_manager.h" |
25 #include "third_party/cros_system_api/dbus/service_constants.h" | 24 #include "third_party/cros_system_api/dbus/service_constants.h" |
26 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
27 | 26 |
28 using chromeos::CrosSettings; | 27 using chromeos::CrosSettings; |
29 using chromeos::DBusThreadManager; | 28 using chromeos::DBusThreadManager; |
30 using chromeos::OwnerSettingsServiceChromeOS; | |
31 using chromeos::OwnerSettingsServiceChromeOSFactory; | |
32 using chromeos::UpdateEngineClient; | 29 using chromeos::UpdateEngineClient; |
| 30 using user_manager::UserManager; |
33 using chromeos::WizardController; | 31 using chromeos::WizardController; |
34 | 32 |
35 namespace { | 33 namespace { |
36 | 34 |
37 // Network status in the context of device update. | 35 // Network status in the context of device update. |
38 enum NetworkStatus { | 36 enum NetworkStatus { |
39 // It's allowed in device policy to use current network for update. | 37 // It's allowed in device policy to use current network for update. |
40 NETWORK_STATUS_ALLOWED = 0, | 38 NETWORK_STATUS_ALLOWED = 0, |
41 // It's disallowed in device policy to use current network for update. | 39 // It's disallowed in device policy to use current network for update. |
42 NETWORK_STATUS_DISALLOWED, | 40 NETWORK_STATUS_DISALLOWED, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 help_utils_chromeos::GetConnectionTypeAsUTF16(network->type())); | 100 help_utils_chromeos::GetConnectionTypeAsUTF16(network->type())); |
103 callback.Run(VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED, 0, message); | 101 callback.Run(VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED, 0, message); |
104 return false; | 102 return false; |
105 } | 103 } |
106 | 104 |
107 return true; | 105 return true; |
108 } | 106 } |
109 | 107 |
110 } // namespace | 108 } // namespace |
111 | 109 |
112 VersionUpdater* VersionUpdater::Create(content::BrowserContext* context) { | 110 VersionUpdater* VersionUpdater::Create() { |
113 return new VersionUpdaterCros(context); | 111 return new VersionUpdaterCros; |
114 } | 112 } |
115 | 113 |
116 void VersionUpdaterCros::GetUpdateStatus(const StatusCallback& callback) { | 114 void VersionUpdaterCros::GetUpdateStatus(const StatusCallback& callback) { |
117 callback_ = callback; | 115 callback_ = callback; |
118 | 116 |
119 if (!EnsureCanUpdate(callback)) | 117 if (!EnsureCanUpdate(callback)) |
120 return; | 118 return; |
121 | 119 |
122 UpdateEngineClient* update_engine_client = | 120 UpdateEngineClient* update_engine_client = |
123 DBusThreadManager::Get()->GetUpdateEngineClient(); | 121 DBusThreadManager::Get()->GetUpdateEngineClient(); |
(...skipping 29 matching lines...) Expand all Loading... |
153 &VersionUpdaterCros::OnUpdateCheck, weak_ptr_factory_.GetWeakPtr())); | 151 &VersionUpdaterCros::OnUpdateCheck, weak_ptr_factory_.GetWeakPtr())); |
154 } | 152 } |
155 } | 153 } |
156 | 154 |
157 void VersionUpdaterCros::RelaunchBrowser() const { | 155 void VersionUpdaterCros::RelaunchBrowser() const { |
158 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); | 156 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); |
159 } | 157 } |
160 | 158 |
161 void VersionUpdaterCros::SetChannel(const std::string& channel, | 159 void VersionUpdaterCros::SetChannel(const std::string& channel, |
162 bool is_powerwash_allowed) { | 160 bool is_powerwash_allowed) { |
163 OwnerSettingsServiceChromeOS* service = | 161 if (user_manager::UserManager::Get()->IsCurrentUserOwner()) { |
164 context_ | 162 // For local owner set the field in the policy blob. |
165 ? OwnerSettingsServiceChromeOSFactory::GetInstance() | 163 CrosSettings::Get()->SetString(chromeos::kReleaseChannel, channel); |
166 ->GetForBrowserContext(context_) | 164 } |
167 : nullptr; | |
168 // For local owner set the field in the policy blob. | |
169 if (service) | |
170 service->SetString(chromeos::kReleaseChannel, channel); | |
171 DBusThreadManager::Get()->GetUpdateEngineClient()-> | 165 DBusThreadManager::Get()->GetUpdateEngineClient()-> |
172 SetChannel(channel, is_powerwash_allowed); | 166 SetChannel(channel, is_powerwash_allowed); |
173 } | 167 } |
174 | 168 |
175 void VersionUpdaterCros::GetChannel(bool get_current_channel, | 169 void VersionUpdaterCros::GetChannel(bool get_current_channel, |
176 const ChannelCallback& cb) { | 170 const ChannelCallback& cb) { |
177 UpdateEngineClient* update_engine_client = | 171 UpdateEngineClient* update_engine_client = |
178 DBusThreadManager::Get()->GetUpdateEngineClient(); | 172 DBusThreadManager::Get()->GetUpdateEngineClient(); |
179 | 173 |
180 // Request the channel information. | 174 // Request the channel information. |
181 update_engine_client->GetChannel(get_current_channel, cb); | 175 update_engine_client->GetChannel(get_current_channel, cb); |
182 } | 176 } |
183 | 177 |
184 VersionUpdaterCros::VersionUpdaterCros(content::BrowserContext* context) | 178 VersionUpdaterCros::VersionUpdaterCros() |
185 : context_(context), | 179 : last_operation_(UpdateEngineClient::UPDATE_STATUS_IDLE), |
186 last_operation_(UpdateEngineClient::UPDATE_STATUS_IDLE), | |
187 check_for_update_when_idle_(false), | 180 check_for_update_when_idle_(false), |
188 weak_ptr_factory_(this) { | 181 weak_ptr_factory_(this) { |
189 } | 182 } |
190 | 183 |
191 VersionUpdaterCros::~VersionUpdaterCros() { | 184 VersionUpdaterCros::~VersionUpdaterCros() { |
192 UpdateEngineClient* update_engine_client = | 185 UpdateEngineClient* update_engine_client = |
193 DBusThreadManager::Get()->GetUpdateEngineClient(); | 186 DBusThreadManager::Get()->GetUpdateEngineClient(); |
194 update_engine_client->RemoveObserver(this); | 187 update_engine_client->RemoveObserver(this); |
195 } | 188 } |
196 | 189 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 } | 244 } |
252 } | 245 } |
253 | 246 |
254 void VersionUpdaterCros::OnUpdateCheck( | 247 void VersionUpdaterCros::OnUpdateCheck( |
255 UpdateEngineClient::UpdateCheckResult result) { | 248 UpdateEngineClient::UpdateCheckResult result) { |
256 // If version updating is not implemented, this binary is the most up-to-date | 249 // If version updating is not implemented, this binary is the most up-to-date |
257 // possible with respect to automatic updating. | 250 // possible with respect to automatic updating. |
258 if (result == UpdateEngineClient::UPDATE_RESULT_NOTIMPLEMENTED) | 251 if (result == UpdateEngineClient::UPDATE_RESULT_NOTIMPLEMENTED) |
259 callback_.Run(UPDATED, 0, base::string16()); | 252 callback_.Run(UPDATED, 0, base::string16()); |
260 } | 253 } |
OLD | NEW |