OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/update_screen.h" | 5 #include "chrome/browser/chromeos/login/update_screen.h" |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "base/file_util.h" | 8 #include "base/file_util.h" |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
9 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
10 #include "chrome/browser/chromeos/cros/cros_library.h" | 11 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
11 #include "chrome/browser/chromeos/login/screen_observer.h" | 12 #include "chrome/browser/chromeos/login/screen_observer.h" |
12 #include "chrome/browser/chromeos/login/update_screen_actor.h" | 13 #include "chrome/browser/chromeos/login/update_screen_actor.h" |
13 #include "chrome/browser/chromeos/login/wizard_controller.h" | 14 #include "chrome/browser/chromeos/login/wizard_controller.h" |
14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
15 | 16 |
16 using content::BrowserThread; | 17 using content::BrowserThread; |
17 | 18 |
18 namespace chromeos { | 19 namespace chromeos { |
19 | 20 |
20 namespace { | 21 namespace { |
(...skipping 11 matching lines...) Expand all Loading... |
32 // Defines what part of update progress does download part takes. | 33 // Defines what part of update progress does download part takes. |
33 const int kDownloadProgressIncrement = 60; | 34 const int kDownloadProgressIncrement = 60; |
34 | 35 |
35 // Considering 10px shadow from each side. | 36 // Considering 10px shadow from each side. |
36 const int kUpdateScreenWidth = 580; | 37 const int kUpdateScreenWidth = 580; |
37 const int kUpdateScreenHeight = 305; | 38 const int kUpdateScreenHeight = 305; |
38 | 39 |
39 const char kUpdateDeadlineFile[] = "/tmp/update-check-response-deadline"; | 40 const char kUpdateDeadlineFile[] = "/tmp/update-check-response-deadline"; |
40 | 41 |
41 // Invoked from call to RequestUpdateCheck upon completion of the DBus call. | 42 // Invoked from call to RequestUpdateCheck upon completion of the DBus call. |
42 void StartUpdateCallback(void* user_data, | 43 void StartUpdateCallback(UpdateScreen* screen, |
43 UpdateResult result, | 44 UpdateEngineClient::UpdateCheckResult result) { |
44 const char* msg) { | |
45 VLOG(1) << "Callback from RequestUpdateCheck, result " << result; | 45 VLOG(1) << "Callback from RequestUpdateCheck, result " << result; |
46 DCHECK(user_data); | |
47 UpdateScreen* screen = static_cast<UpdateScreen*>(user_data); | |
48 if (UpdateScreen::HasInstance(screen)) { | 46 if (UpdateScreen::HasInstance(screen)) { |
49 if (result == chromeos::UPDATE_RESULT_SUCCESS) | 47 if (result == UpdateEngineClient::UPDATE_RESULT_SUCCESS) |
50 screen->SetIgnoreIdleStatus(false); | 48 screen->SetIgnoreIdleStatus(false); |
51 else | 49 else |
52 screen->ExitUpdate(UpdateScreen::REASON_UPDATE_INIT_FAILED); | 50 screen->ExitUpdate(UpdateScreen::REASON_UPDATE_INIT_FAILED); |
53 } | 51 } |
54 } | 52 } |
55 | 53 |
56 } // anonymous namespace | 54 } // anonymous namespace |
57 | 55 |
58 // static | 56 // static |
59 UpdateScreen::InstanceSet& UpdateScreen::GetInstanceSet() { | 57 UpdateScreen::InstanceSet& UpdateScreen::GetInstanceSet() { |
(...skipping 17 matching lines...) Expand all Loading... |
77 is_downloading_update_(false), | 75 is_downloading_update_(false), |
78 is_ignore_update_deadlines_(false), | 76 is_ignore_update_deadlines_(false), |
79 is_shown_(false), | 77 is_shown_(false), |
80 ignore_idle_status_(true), | 78 ignore_idle_status_(true), |
81 actor_(actor) { | 79 actor_(actor) { |
82 actor_->SetDelegate(this); | 80 actor_->SetDelegate(this); |
83 GetInstanceSet().insert(this); | 81 GetInstanceSet().insert(this); |
84 } | 82 } |
85 | 83 |
86 UpdateScreen::~UpdateScreen() { | 84 UpdateScreen::~UpdateScreen() { |
87 CrosLibrary::Get()->GetUpdateLibrary()->RemoveObserver(this); | 85 DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver(this); |
88 GetInstanceSet().erase(this); | 86 GetInstanceSet().erase(this); |
89 if (actor_) | 87 if (actor_) |
90 actor_->SetDelegate(NULL); | 88 actor_->SetDelegate(NULL); |
91 } | 89 } |
92 | 90 |
93 void UpdateScreen::UpdateStatusChanged(const UpdateLibrary::Status& status) { | 91 void UpdateScreen::UpdateStatusChanged( |
| 92 const UpdateEngineClient::Status& status) { |
94 if (is_checking_for_update_ && | 93 if (is_checking_for_update_ && |
95 status.status > UPDATE_STATUS_CHECKING_FOR_UPDATE) { | 94 status.status > UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE) { |
96 is_checking_for_update_ = false; | 95 is_checking_for_update_ = false; |
97 } | 96 } |
98 if (ignore_idle_status_ && status.status > UPDATE_STATUS_IDLE) { | 97 if (ignore_idle_status_ && status.status > |
| 98 UpdateEngineClient::UPDATE_STATUS_IDLE) { |
99 ignore_idle_status_ = false; | 99 ignore_idle_status_ = false; |
100 } | 100 } |
101 | 101 |
102 switch (status.status) { | 102 switch (status.status) { |
103 case UPDATE_STATUS_CHECKING_FOR_UPDATE: | 103 case UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE: |
104 // Do nothing in these cases, we don't want to notify the user of the | 104 // Do nothing in these cases, we don't want to notify the user of the |
105 // check unless there is an update. | 105 // check unless there is an update. |
106 break; | 106 break; |
107 case UPDATE_STATUS_UPDATE_AVAILABLE: | 107 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE: |
108 MakeSureScreenIsShown(); | 108 MakeSureScreenIsShown(); |
109 actor_->SetProgress(kBeforeDownloadProgress); | 109 actor_->SetProgress(kBeforeDownloadProgress); |
110 if (!HasCriticalUpdate()) { | 110 if (!HasCriticalUpdate()) { |
111 LOG(INFO) << "Noncritical update available: " | 111 LOG(INFO) << "Noncritical update available: " |
112 << status.new_version; | 112 << status.new_version; |
113 ExitUpdate(REASON_UPDATE_NON_CRITICAL); | 113 ExitUpdate(REASON_UPDATE_NON_CRITICAL); |
114 } else { | 114 } else { |
115 LOG(INFO) << "Critical update available: " | 115 LOG(INFO) << "Critical update available: " |
116 << status.new_version; | 116 << status.new_version; |
117 actor_->ShowPreparingUpdatesInfo(true); | 117 actor_->ShowPreparingUpdatesInfo(true); |
118 actor_->ShowCurtain(false); | 118 actor_->ShowCurtain(false); |
119 } | 119 } |
120 break; | 120 break; |
121 case UPDATE_STATUS_DOWNLOADING: | 121 case UpdateEngineClient::UPDATE_STATUS_DOWNLOADING: |
122 { | 122 { |
123 MakeSureScreenIsShown(); | 123 MakeSureScreenIsShown(); |
124 if (!is_downloading_update_) { | 124 if (!is_downloading_update_) { |
125 // Because update engine doesn't send UPDATE_STATUS_UPDATE_AVAILABLE | 125 // Because update engine doesn't send UPDATE_STATUS_UPDATE_AVAILABLE |
126 // we need to is update critical on first downloading notification. | 126 // we need to is update critical on first downloading notification. |
127 is_downloading_update_ = true; | 127 is_downloading_update_ = true; |
128 if (!HasCriticalUpdate()) { | 128 if (!HasCriticalUpdate()) { |
129 LOG(INFO) << "Non-critical update available: " | 129 LOG(INFO) << "Non-critical update available: " |
130 << status.new_version; | 130 << status.new_version; |
131 ExitUpdate(REASON_UPDATE_NON_CRITICAL); | 131 ExitUpdate(REASON_UPDATE_NON_CRITICAL); |
132 } else { | 132 } else { |
133 LOG(INFO) << "Critical update available: " | 133 LOG(INFO) << "Critical update available: " |
134 << status.new_version; | 134 << status.new_version; |
135 actor_->ShowPreparingUpdatesInfo(false); | 135 actor_->ShowPreparingUpdatesInfo(false); |
136 actor_->ShowCurtain(false); | 136 actor_->ShowCurtain(false); |
137 } | 137 } |
138 } | 138 } |
139 int download_progress = static_cast<int>( | 139 int download_progress = static_cast<int>( |
140 status.download_progress * kDownloadProgressIncrement); | 140 status.download_progress * kDownloadProgressIncrement); |
141 actor_->SetProgress(kBeforeDownloadProgress + download_progress); | 141 actor_->SetProgress(kBeforeDownloadProgress + download_progress); |
142 } | 142 } |
143 break; | 143 break; |
144 case UPDATE_STATUS_VERIFYING: | 144 case UpdateEngineClient::UPDATE_STATUS_VERIFYING: |
145 MakeSureScreenIsShown(); | 145 MakeSureScreenIsShown(); |
146 actor_->SetProgress(kBeforeVerifyingProgress); | 146 actor_->SetProgress(kBeforeVerifyingProgress); |
147 break; | 147 break; |
148 case UPDATE_STATUS_FINALIZING: | 148 case UpdateEngineClient::UPDATE_STATUS_FINALIZING: |
149 MakeSureScreenIsShown(); | 149 MakeSureScreenIsShown(); |
150 actor_->SetProgress(kBeforeFinalizingProgress); | 150 actor_->SetProgress(kBeforeFinalizingProgress); |
151 break; | 151 break; |
152 case UPDATE_STATUS_UPDATED_NEED_REBOOT: | 152 case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT: |
153 MakeSureScreenIsShown(); | 153 MakeSureScreenIsShown(); |
154 // Make sure that first OOBE stage won't be shown after reboot. | 154 // Make sure that first OOBE stage won't be shown after reboot. |
155 WizardController::MarkOobeCompleted(); | 155 WizardController::MarkOobeCompleted(); |
156 actor_->SetProgress(kProgressComplete); | 156 actor_->SetProgress(kProgressComplete); |
157 if (HasCriticalUpdate()) { | 157 if (HasCriticalUpdate()) { |
158 actor_->ShowCurtain(false); | 158 actor_->ShowCurtain(false); |
159 VLOG(1) << "Initiate reboot after update"; | 159 VLOG(1) << "Initiate reboot after update"; |
160 CrosLibrary::Get()->GetUpdateLibrary()->RebootAfterUpdate(); | 160 DBusThreadManager::Get()->GetUpdateEngineClient()->RebootAfterUpdate(); |
161 reboot_timer_.Start(FROM_HERE, | 161 reboot_timer_.Start(FROM_HERE, |
162 base::TimeDelta::FromSeconds(reboot_check_delay_), | 162 base::TimeDelta::FromSeconds(reboot_check_delay_), |
163 this, | 163 this, |
164 &UpdateScreen::OnWaitForRebootTimeElapsed); | 164 &UpdateScreen::OnWaitForRebootTimeElapsed); |
165 } else { | 165 } else { |
166 ExitUpdate(REASON_UPDATE_NON_CRITICAL); | 166 ExitUpdate(REASON_UPDATE_NON_CRITICAL); |
167 } | 167 } |
168 break; | 168 break; |
169 case UPDATE_STATUS_IDLE: | 169 case UpdateEngineClient::UPDATE_STATUS_IDLE: |
170 if (ignore_idle_status_) { | 170 if (ignore_idle_status_) { |
171 // It is first IDLE status that is sent before we initiated the check. | 171 // It is first IDLE status that is sent before we initiated the check. |
172 break; | 172 break; |
173 } | 173 } |
174 // else no break | 174 // else no break |
175 | 175 |
176 case UPDATE_STATUS_ERROR: | 176 case UpdateEngineClient::UPDATE_STATUS_ERROR: |
177 case UPDATE_STATUS_REPORTING_ERROR_EVENT: | 177 case UpdateEngineClient::UPDATE_STATUS_REPORTING_ERROR_EVENT: |
178 ExitUpdate(REASON_UPDATE_ENDED); | 178 ExitUpdate(REASON_UPDATE_ENDED); |
179 break; | 179 break; |
180 default: | 180 default: |
181 NOTREACHED(); | 181 NOTREACHED(); |
182 break; | 182 break; |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 void UpdateScreen::StartUpdate() { | 186 void UpdateScreen::StartUpdate() { |
187 CrosLibrary::Get()->GetUpdateLibrary()->AddObserver(this); | 187 DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver(this); |
188 VLOG(1) << "Initiate update check"; | 188 VLOG(1) << "Initiate update check"; |
189 CrosLibrary::Get()->GetUpdateLibrary()->RequestUpdateCheck( | 189 DBusThreadManager::Get()->GetUpdateEngineClient()->RequestUpdateCheck( |
190 StartUpdateCallback, this); | 190 base::Bind(StartUpdateCallback, this)); |
191 } | 191 } |
192 | 192 |
193 void UpdateScreen::CancelUpdate() { | 193 void UpdateScreen::CancelUpdate() { |
194 VLOG(1) << "Forced update cancel"; | 194 VLOG(1) << "Forced update cancel"; |
195 ExitUpdate(REASON_UPDATE_CANCELED); | 195 ExitUpdate(REASON_UPDATE_CANCELED); |
196 } | 196 } |
197 | 197 |
198 void UpdateScreen::Show() { | 198 void UpdateScreen::Show() { |
199 is_shown_ = true; | 199 is_shown_ = true; |
200 actor_->Show(); | 200 actor_->Show(); |
201 actor_->SetProgress(kBeforeUpdateCheckProgress); | 201 actor_->SetProgress(kBeforeUpdateCheckProgress); |
202 } | 202 } |
203 | 203 |
204 void UpdateScreen::Hide() { | 204 void UpdateScreen::Hide() { |
205 actor_->Hide(); | 205 actor_->Hide(); |
206 is_shown_ = false; | 206 is_shown_ = false; |
207 } | 207 } |
208 | 208 |
209 void UpdateScreen::PrepareToShow() { | 209 void UpdateScreen::PrepareToShow() { |
210 actor_->PrepareToShow(); | 210 actor_->PrepareToShow(); |
211 } | 211 } |
212 | 212 |
213 void UpdateScreen::ExitUpdate(UpdateScreen::ExitReason reason) { | 213 void UpdateScreen::ExitUpdate(UpdateScreen::ExitReason reason) { |
214 CrosLibrary::Get()->GetUpdateLibrary()->RemoveObserver(this); | 214 DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver(this); |
215 | 215 |
216 switch (reason) { | 216 switch (reason) { |
217 case REASON_UPDATE_CANCELED: | 217 case REASON_UPDATE_CANCELED: |
218 get_screen_observer()->OnExit(ScreenObserver::UPDATE_NOUPDATE); | 218 get_screen_observer()->OnExit(ScreenObserver::UPDATE_NOUPDATE); |
219 break; | 219 break; |
220 case REASON_UPDATE_INIT_FAILED: | 220 case REASON_UPDATE_INIT_FAILED: |
221 get_screen_observer()->OnExit( | 221 get_screen_observer()->OnExit( |
222 ScreenObserver::UPDATE_ERROR_CHECKING_FOR_UPDATE); | 222 ScreenObserver::UPDATE_ERROR_CHECKING_FOR_UPDATE); |
223 break; | 223 break; |
224 case REASON_UPDATE_NON_CRITICAL: | 224 case REASON_UPDATE_NON_CRITICAL: |
225 case REASON_UPDATE_ENDED: | 225 case REASON_UPDATE_ENDED: |
226 { | 226 { |
227 UpdateLibrary* update_library = CrosLibrary::Get()->GetUpdateLibrary(); | 227 UpdateEngineClient* update_engine_client = |
228 switch (update_library->status().status) { | 228 DBusThreadManager::Get()->GetUpdateEngineClient(); |
229 case UPDATE_STATUS_UPDATE_AVAILABLE: | 229 switch (update_engine_client->GetLastStatus().status) { |
230 case UPDATE_STATUS_UPDATED_NEED_REBOOT: | 230 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE: |
231 case UPDATE_STATUS_DOWNLOADING: | 231 case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT: |
232 case UPDATE_STATUS_FINALIZING: | 232 case UpdateEngineClient::UPDATE_STATUS_DOWNLOADING: |
233 case UPDATE_STATUS_VERIFYING: | 233 case UpdateEngineClient::UPDATE_STATUS_FINALIZING: |
| 234 case UpdateEngineClient::UPDATE_STATUS_VERIFYING: |
234 DCHECK(!HasCriticalUpdate()); | 235 DCHECK(!HasCriticalUpdate()); |
235 // Noncritical update, just exit screen as if there is no update. | 236 // Noncritical update, just exit screen as if there is no update. |
236 // no break | 237 // no break |
237 case UPDATE_STATUS_IDLE: | 238 case UpdateEngineClient::UPDATE_STATUS_IDLE: |
238 get_screen_observer()->OnExit(ScreenObserver::UPDATE_NOUPDATE); | 239 get_screen_observer()->OnExit(ScreenObserver::UPDATE_NOUPDATE); |
239 break; | 240 break; |
240 case UPDATE_STATUS_ERROR: | 241 case UpdateEngineClient::UPDATE_STATUS_ERROR: |
241 case UPDATE_STATUS_REPORTING_ERROR_EVENT: | 242 case UpdateEngineClient::UPDATE_STATUS_REPORTING_ERROR_EVENT: |
242 get_screen_observer()->OnExit(is_checking_for_update_ ? | 243 get_screen_observer()->OnExit(is_checking_for_update_ ? |
243 ScreenObserver::UPDATE_ERROR_CHECKING_FOR_UPDATE : | 244 ScreenObserver::UPDATE_ERROR_CHECKING_FOR_UPDATE : |
244 ScreenObserver::UPDATE_ERROR_UPDATING); | 245 ScreenObserver::UPDATE_ERROR_UPDATING); |
245 break; | 246 break; |
246 default: | 247 default: |
247 NOTREACHED(); | 248 NOTREACHED(); |
248 } | 249 } |
249 } | 250 } |
250 break; | 251 break; |
251 default: | 252 default: |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 // if the file exists and not empty, there is critical update. | 294 // if the file exists and not empty, there is critical update. |
294 return true; | 295 return true; |
295 } | 296 } |
296 | 297 |
297 void UpdateScreen::OnActorDestroyed(UpdateScreenActor* actor) { | 298 void UpdateScreen::OnActorDestroyed(UpdateScreenActor* actor) { |
298 if (actor_ == actor) | 299 if (actor_ == actor) |
299 actor_ = NULL; | 300 actor_ = NULL; |
300 } | 301 } |
301 | 302 |
302 } // namespace chromeos | 303 } // namespace chromeos |
OLD | NEW |