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