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" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get(); | 65 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get(); |
66 if (!settings) | 66 if (!settings) |
67 return update_disabled; | 67 return update_disabled; |
68 const base::Value* update_disabled_value = | 68 const base::Value* update_disabled_value = |
69 settings->GetPref(chromeos::kUpdateDisabled); | 69 settings->GetPref(chromeos::kUpdateDisabled); |
70 if (update_disabled_value) | 70 if (update_disabled_value) |
71 CHECK(update_disabled_value->GetAsBoolean(&update_disabled)); | 71 CHECK(update_disabled_value->GetAsBoolean(&update_disabled)); |
72 return update_disabled; | 72 return update_disabled; |
73 } | 73 } |
74 | 74 |
75 // Returns whether an update is allowed. If not, it calls the callback with | |
76 // the appropriate status. | |
77 bool EnsureCanUpdate(const VersionUpdater::StatusCallback& callback) { | |
78 if (IsAutoUpdateDisabled()) { | |
79 callback.Run(VersionUpdater::FAILED, 0, | |
80 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY)); | |
81 return false; | |
82 } | |
83 | |
84 chromeos::NetworkStateHandler* network_state_handler = | |
85 chromeos::NetworkHandler::Get()->network_state_handler(); | |
86 const chromeos::NetworkState* network = | |
87 network_state_handler->DefaultNetwork(); | |
88 | |
89 // Don't allow an update if we're currently offline or connected | |
90 // to a network for which updates are disallowed. | |
91 NetworkStatus status = GetNetworkStatus(network); | |
92 if (status == NETWORK_STATUS_OFFLINE) { | |
93 callback.Run(VersionUpdater::FAILED_OFFLINE, 0, | |
94 l10n_util::GetStringUTF16(IDS_UPGRADE_OFFLINE)); | |
95 return false; | |
96 } else if (status == NETWORK_STATUS_DISALLOWED) { | |
97 base::string16 message = | |
98 l10n_util::GetStringFUTF16( | |
99 IDS_UPGRADE_DISALLOWED, | |
100 help_utils_chromeos::GetConnectionTypeAsUTF16(network->type())); | |
101 callback.Run(VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED, 0, message); | |
102 return false; | |
103 } | |
104 | |
105 return true; | |
106 } | |
107 | |
108 } // namespace | 75 } // namespace |
109 | 76 |
110 VersionUpdater* VersionUpdater::Create() { | 77 VersionUpdater* VersionUpdater::Create() { |
111 return new VersionUpdaterCros; | 78 return new VersionUpdaterCros; |
112 } | 79 } |
113 | 80 |
114 void VersionUpdaterCros::GetUpdateStatus(const StatusCallback& callback) { | 81 void VersionUpdaterCros::GetUpdateStatus(const StatusCallback& callback) { |
115 callback_ = callback; | 82 callback_ = callback; |
116 if (!EnsureCanUpdate(callback)) | 83 if (!EnsureCanUpdate(callback)) |
James Hawkins
2014/09/22 20:23:08
this->EnsureCanUpdate, right?
ygorshenin1
2014/09/23 10:23:16
Could you please explain a difference between a di
| |
117 return; | 84 return; |
118 | 85 |
119 UpdateEngineClient* update_engine_client = | 86 UpdateEngineClient* update_engine_client = |
120 DBusThreadManager::Get()->GetUpdateEngineClient(); | 87 DBusThreadManager::Get()->GetUpdateEngineClient(); |
121 if (!update_engine_client->HasObserver(this)) | 88 if (!update_engine_client->HasObserver(this)) |
122 update_engine_client->AddObserver(this); | 89 update_engine_client->AddObserver(this); |
123 | 90 |
124 this->UpdateStatusChanged( | 91 this->UpdateStatusChanged( |
125 DBusThreadManager::Get()->GetUpdateEngineClient()->GetLastStatus()); | 92 DBusThreadManager::Get()->GetUpdateEngineClient()->GetLastStatus()); |
126 } | 93 } |
127 | 94 |
128 void VersionUpdaterCros::CheckForUpdate(const StatusCallback& callback) { | 95 void VersionUpdaterCros::CheckForUpdate(const StatusCallback& callback) { |
129 callback_ = callback; | 96 callback_ = callback; |
130 | 97 |
131 if (!EnsureCanUpdate(callback)) | 98 if (!EnsureCanUpdate(callback)) |
132 return; | 99 return; |
133 | 100 |
134 UpdateEngineClient* update_engine_client = | 101 UpdateEngineClient* update_engine_client = |
135 DBusThreadManager::Get()->GetUpdateEngineClient(); | 102 DBusThreadManager::Get()->GetUpdateEngineClient(); |
136 if (!update_engine_client->HasObserver(this)) | 103 if (!update_engine_client->HasObserver(this)) |
137 update_engine_client->AddObserver(this); | 104 update_engine_client->AddObserver(this); |
138 | 105 |
106 if (update_engine_client->GetLastStatus().status != | |
107 UpdateEngineClient::UPDATE_STATUS_IDLE) { | |
108 check_for_update_when_idle_ = true; | |
109 return; | |
110 } | |
111 check_for_update_when_idle_ = false; | |
112 | |
139 // Make sure that libcros is loaded and OOBE is complete. | 113 // Make sure that libcros is loaded and OOBE is complete. |
140 if (!WizardController::default_controller() || | 114 if (!WizardController::default_controller() || |
141 chromeos::StartupUtils::IsDeviceRegistered()) { | 115 chromeos::StartupUtils::IsDeviceRegistered()) { |
142 update_engine_client->RequestUpdateCheck( | 116 update_engine_client->RequestUpdateCheck(base::Bind( |
143 base::Bind(&VersionUpdaterCros::OnUpdateCheck, | 117 &VersionUpdaterCros::OnUpdateCheck, weak_ptr_factory_.GetWeakPtr())); |
144 weak_ptr_factory_.GetWeakPtr())); | |
145 } | 118 } |
146 } | 119 } |
147 | 120 |
148 void VersionUpdaterCros::RelaunchBrowser() const { | 121 void VersionUpdaterCros::RelaunchBrowser() const { |
149 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); | 122 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); |
150 } | 123 } |
151 | 124 |
152 void VersionUpdaterCros::SetChannel(const std::string& channel, | 125 void VersionUpdaterCros::SetChannel(const std::string& channel, |
153 bool is_powerwash_allowed) { | 126 bool is_powerwash_allowed) { |
154 if (user_manager::UserManager::Get()->IsCurrentUserOwner()) { | 127 if (user_manager::UserManager::Get()->IsCurrentUserOwner()) { |
155 // For local owner set the field in the policy blob. | 128 // For local owner set the field in the policy blob. |
156 CrosSettings::Get()->SetString(chromeos::kReleaseChannel, channel); | 129 CrosSettings::Get()->SetString(chromeos::kReleaseChannel, channel); |
157 } | 130 } |
158 DBusThreadManager::Get()->GetUpdateEngineClient()-> | 131 DBusThreadManager::Get()->GetUpdateEngineClient()-> |
159 SetChannel(channel, is_powerwash_allowed); | 132 SetChannel(channel, is_powerwash_allowed); |
160 } | 133 } |
161 | 134 |
162 void VersionUpdaterCros::GetChannel(bool get_current_channel, | 135 void VersionUpdaterCros::GetChannel(bool get_current_channel, |
163 const ChannelCallback& cb) { | 136 const ChannelCallback& cb) { |
164 UpdateEngineClient* update_engine_client = | 137 UpdateEngineClient* update_engine_client = |
165 DBusThreadManager::Get()->GetUpdateEngineClient(); | 138 DBusThreadManager::Get()->GetUpdateEngineClient(); |
166 | 139 |
167 // Request the channel information. | 140 // Request the channel information. |
168 update_engine_client->GetChannel(get_current_channel, cb); | 141 update_engine_client->GetChannel(get_current_channel, cb); |
169 } | 142 } |
170 | 143 |
171 VersionUpdaterCros::VersionUpdaterCros() | 144 VersionUpdaterCros::VersionUpdaterCros() |
172 : last_operation_(UpdateEngineClient::UPDATE_STATUS_IDLE), | 145 : last_operation_(UpdateEngineClient::UPDATE_STATUS_IDLE), |
146 check_for_update_when_idle_(false), | |
173 weak_ptr_factory_(this) { | 147 weak_ptr_factory_(this) { |
174 } | 148 } |
175 | 149 |
176 VersionUpdaterCros::~VersionUpdaterCros() { | 150 VersionUpdaterCros::~VersionUpdaterCros() { |
177 UpdateEngineClient* update_engine_client = | 151 UpdateEngineClient* update_engine_client = |
178 DBusThreadManager::Get()->GetUpdateEngineClient(); | 152 DBusThreadManager::Get()->GetUpdateEngineClient(); |
179 update_engine_client->RemoveObserver(this); | 153 update_engine_client->RemoveObserver(this); |
180 } | 154 } |
181 | 155 |
156 bool VersionUpdaterCros::EnsureCanUpdate(const StatusCallback& callback) { | |
157 if (IsAutoUpdateDisabled()) { | |
158 callback.Run(VersionUpdater::FAILED, 0, | |
159 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY)); | |
160 return false; | |
161 } | |
162 | |
163 chromeos::NetworkStateHandler* network_state_handler = | |
164 chromeos::NetworkHandler::Get()->network_state_handler(); | |
165 const chromeos::NetworkState* network = | |
166 network_state_handler->DefaultNetwork(); | |
167 | |
168 // Don't allow an update if we're currently offline or connected | |
169 // to a network for which updates are disallowed. | |
170 NetworkStatus status = GetNetworkStatus(network); | |
171 if (status == NETWORK_STATUS_OFFLINE) { | |
172 callback.Run(VersionUpdater::FAILED_OFFLINE, 0, | |
173 l10n_util::GetStringUTF16(IDS_UPGRADE_OFFLINE)); | |
174 return false; | |
175 } else if (status == NETWORK_STATUS_DISALLOWED) { | |
176 base::string16 message = | |
177 l10n_util::GetStringFUTF16( | |
178 IDS_UPGRADE_DISALLOWED, | |
179 help_utils_chromeos::GetConnectionTypeAsUTF16(network->type())); | |
180 callback.Run(VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED, 0, message); | |
181 return false; | |
182 } | |
183 | |
184 return true; | |
185 } | |
186 | |
182 void VersionUpdaterCros::UpdateStatusChanged( | 187 void VersionUpdaterCros::UpdateStatusChanged( |
183 const UpdateEngineClient::Status& status) { | 188 const UpdateEngineClient::Status& status) { |
184 Status my_status = UPDATED; | 189 Status my_status = UPDATED; |
185 int progress = 0; | 190 int progress = 0; |
186 base::string16 message; | 191 base::string16 message; |
187 | 192 |
188 // If the updater is currently idle, just show the last operation (unless it | 193 // If the updater is currently idle, just show the last operation (unless it |
189 // was previously checking for an update -- in that case, the system is | 194 // was previously checking for an update -- in that case, the system is |
190 // up-to-date now). See http://crbug.com/120063 for details. | 195 // up-to-date now). See http://crbug.com/120063 for details. |
191 UpdateEngineClient::UpdateStatusOperation operation_to_show = status.status; | 196 UpdateEngineClient::UpdateStatusOperation operation_to_show = status.status; |
(...skipping 30 matching lines...) Expand all Loading... | |
222 break; | 227 break; |
223 case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT: | 228 case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT: |
224 my_status = NEARLY_UPDATED; | 229 my_status = NEARLY_UPDATED; |
225 break; | 230 break; |
226 default: | 231 default: |
227 break; | 232 break; |
228 } | 233 } |
229 | 234 |
230 callback_.Run(my_status, progress, message); | 235 callback_.Run(my_status, progress, message); |
231 last_operation_ = status.status; | 236 last_operation_ = status.status; |
237 | |
238 if (check_for_update_when_idle_ && | |
239 status.status == UpdateEngineClient::UPDATE_STATUS_IDLE) { | |
240 CheckForUpdate(callback_); | |
241 } | |
232 } | 242 } |
233 | 243 |
234 void VersionUpdaterCros::OnUpdateCheck( | 244 void VersionUpdaterCros::OnUpdateCheck( |
235 UpdateEngineClient::UpdateCheckResult result) { | 245 UpdateEngineClient::UpdateCheckResult result) { |
236 // If version updating is not implemented, this binary is the most up-to-date | 246 // If version updating is not implemented, this binary is the most up-to-date |
237 // possible with respect to automatic updating. | 247 // possible with respect to automatic updating. |
238 if (result == UpdateEngineClient::UPDATE_RESULT_NOTIMPLEMENTED) | 248 if (result == UpdateEngineClient::UPDATE_RESULT_NOTIMPLEMENTED) |
239 callback_.Run(UPDATED, 0, base::string16()); | 249 callback_.Run(UPDATED, 0, base::string16()); |
240 } | 250 } |
OLD | NEW |