| 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/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
| 10 #include "chrome/browser/chromeos/cros/cros_library.h" | 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 // Considering 10px shadow from each side. | 33 // Considering 10px shadow from each side. |
| 34 const int kUpdateScreenWidth = 580; | 34 const int kUpdateScreenWidth = 580; |
| 35 const int kUpdateScreenHeight = 305; | 35 const int kUpdateScreenHeight = 305; |
| 36 | 36 |
| 37 const char kUpdateDeadlineFile[] = "/tmp/update-check-response-deadline"; | 37 const char kUpdateDeadlineFile[] = "/tmp/update-check-response-deadline"; |
| 38 | 38 |
| 39 // Invoked from call to RequestUpdateCheck upon completion of the DBus call. | 39 // Invoked from call to RequestUpdateCheck upon completion of the DBus call. |
| 40 void StartUpdateCallback(void* user_data, | 40 void StartUpdateCallback(void* user_data, |
| 41 UpdateResult result, | 41 UpdateResult result, |
| 42 const char* msg) { | 42 const char* msg) { |
| 43 if (result != chromeos::UPDATE_RESULT_SUCCESS) { | 43 VLOG(1) << "Callback from RequestUpdateCheck, result " << result; |
| 44 DCHECK(user_data); | 44 DCHECK(user_data); |
| 45 UpdateScreen* screen = static_cast<UpdateScreen*>(user_data); | 45 UpdateScreen* screen = static_cast<UpdateScreen*>(user_data); |
| 46 if (UpdateScreen::HasInstance(screen)) | 46 if (UpdateScreen::HasInstance(screen)) { |
| 47 if (result == chromeos::UPDATE_RESULT_SUCCESS) |
| 48 screen->SetIgnoreIdleStatus(false); |
| 49 else |
| 47 screen->ExitUpdate(UpdateScreen::REASON_UPDATE_INIT_FAILED); | 50 screen->ExitUpdate(UpdateScreen::REASON_UPDATE_INIT_FAILED); |
| 48 } | 51 } |
| 49 } | 52 } |
| 50 | 53 |
| 51 } // anonymous namespace | 54 } // anonymous namespace |
| 52 | 55 |
| 53 // static | 56 // static |
| 54 UpdateScreen::InstanceSet& UpdateScreen::GetInstanceSet() { | 57 UpdateScreen::InstanceSet& UpdateScreen::GetInstanceSet() { |
| 55 static std::set<UpdateScreen*> instance_set; | 58 static std::set<UpdateScreen*> instance_set; |
| 56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); // not threadsafe. | 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); // not threadsafe. |
| 57 return instance_set; | 60 return instance_set; |
| 58 } | 61 } |
| 59 | 62 |
| 60 // static | 63 // static |
| 61 bool UpdateScreen::HasInstance(UpdateScreen* inst) { | 64 bool UpdateScreen::HasInstance(UpdateScreen* inst) { |
| 62 InstanceSet& instance_set = GetInstanceSet(); | 65 InstanceSet& instance_set = GetInstanceSet(); |
| 63 InstanceSet::iterator found = instance_set.find(inst); | 66 InstanceSet::iterator found = instance_set.find(inst); |
| 64 return (found != instance_set.end()); | 67 return (found != instance_set.end()); |
| 65 } | 68 } |
| 66 | 69 |
| 67 | |
| 68 UpdateScreen::UpdateScreen(ScreenObserver* screen_observer, | 70 UpdateScreen::UpdateScreen(ScreenObserver* screen_observer, |
| 69 UpdateScreenActor* actor) | 71 UpdateScreenActor* actor) |
| 70 : WizardScreen(screen_observer), | 72 : WizardScreen(screen_observer), |
| 71 reboot_check_delay_(0), | 73 reboot_check_delay_(0), |
| 72 is_checking_for_update_(true), | 74 is_checking_for_update_(true), |
| 73 is_downloading_update_(false), | 75 is_downloading_update_(false), |
| 74 is_ignore_update_deadlines_(false), | 76 is_ignore_update_deadlines_(false), |
| 75 is_shown_(false), | 77 is_shown_(false), |
| 78 ignore_idle_status_(true), |
| 76 actor_(actor) { | 79 actor_(actor) { |
| 77 GetInstanceSet().insert(this); | 80 GetInstanceSet().insert(this); |
| 78 } | 81 } |
| 79 | 82 |
| 80 UpdateScreen::~UpdateScreen() { | 83 UpdateScreen::~UpdateScreen() { |
| 81 CrosLibrary::Get()->GetUpdateLibrary()->RemoveObserver(this); | 84 CrosLibrary::Get()->GetUpdateLibrary()->RemoveObserver(this); |
| 82 GetInstanceSet().erase(this); | 85 GetInstanceSet().erase(this); |
| 83 } | 86 } |
| 84 | 87 |
| 85 void UpdateScreen::UpdateStatusChanged(UpdateLibrary* library) { | 88 void UpdateScreen::UpdateStatusChanged(UpdateLibrary* library) { |
| 86 UpdateStatusOperation status = library->status().status; | 89 UpdateStatusOperation status = library->status().status; |
| 87 if (is_checking_for_update_ && status > UPDATE_STATUS_CHECKING_FOR_UPDATE) { | 90 if (is_checking_for_update_ && status > UPDATE_STATUS_CHECKING_FOR_UPDATE) { |
| 88 is_checking_for_update_ = false; | 91 is_checking_for_update_ = false; |
| 89 } | 92 } |
| 93 if (ignore_idle_status_ && status > UPDATE_STATUS_IDLE) { |
| 94 ignore_idle_status_ = false; |
| 95 } |
| 90 | 96 |
| 91 switch (status) { | 97 switch (status) { |
| 92 case UPDATE_STATUS_CHECKING_FOR_UPDATE: | 98 case UPDATE_STATUS_CHECKING_FOR_UPDATE: |
| 93 // Do nothing in these cases, we don't want to notify the user of the | 99 // Do nothing in these cases, we don't want to notify the user of the |
| 94 // check unless there is an update. | 100 // check unless there is an update. |
| 95 break; | 101 break; |
| 96 case UPDATE_STATUS_UPDATE_AVAILABLE: | 102 case UPDATE_STATUS_UPDATE_AVAILABLE: |
| 97 MakeSureScreenIsShown(); | 103 MakeSureScreenIsShown(); |
| 98 actor_->SetProgress(kBeforeDownloadProgress); | 104 actor_->SetProgress(kBeforeDownloadProgress); |
| 99 if (!HasCriticalUpdate()) { | 105 if (!HasCriticalUpdate()) { |
| 100 LOG(INFO) << "Noncritical update available: " | 106 LOG(INFO) << "Noncritical update available: " |
| 101 << library->status().new_version; | 107 << library->status().new_version; |
| 102 ExitUpdate(REASON_UPDATE_NON_CRITICAL); | 108 ExitUpdate(REASON_UPDATE_NON_CRITICAL); |
| 103 } else { | 109 } else { |
| 104 LOG(INFO) << "Critical update available: " | 110 LOG(INFO) << "Critical update available: " |
| 105 << library->status().new_version; | 111 << library->status().new_version; |
| 112 actor_->ShowPreparingUpdatesInfo(true); |
| 113 actor_->ShowCurtain(false); |
| 106 } | 114 } |
| 107 break; | 115 break; |
| 108 case UPDATE_STATUS_DOWNLOADING: | 116 case UPDATE_STATUS_DOWNLOADING: |
| 109 { | 117 { |
| 110 MakeSureScreenIsShown(); | 118 MakeSureScreenIsShown(); |
| 111 if (!is_downloading_update_) { | 119 if (!is_downloading_update_) { |
| 112 // Because update engine doesn't send UPDATE_STATUS_UPDATE_AVAILABLE | 120 // Because update engine doesn't send UPDATE_STATUS_UPDATE_AVAILABLE |
| 113 // we need to is update critical on first downloading notification. | 121 // we need to is update critical on first downloading notification. |
| 114 is_downloading_update_ = true; | 122 is_downloading_update_ = true; |
| 115 if (!HasCriticalUpdate()) { | 123 if (!HasCriticalUpdate()) { |
| 116 LOG(INFO) << "Non-critical update available: " | 124 LOG(INFO) << "Non-critical update available: " |
| 117 << library->status().new_version; | 125 << library->status().new_version; |
| 118 ExitUpdate(REASON_UPDATE_NON_CRITICAL); | 126 ExitUpdate(REASON_UPDATE_NON_CRITICAL); |
| 119 } else { | 127 } else { |
| 120 LOG(INFO) << "Critical update available: " | 128 LOG(INFO) << "Critical update available: " |
| 121 << library->status().new_version; | 129 << library->status().new_version; |
| 130 actor_->ShowPreparingUpdatesInfo(false); |
| 131 actor_->ShowCurtain(false); |
| 122 } | 132 } |
| 123 } | 133 } |
| 124 actor_->ShowCurtain(false); | |
| 125 int download_progress = static_cast<int>( | 134 int download_progress = static_cast<int>( |
| 126 library->status().download_progress * kDownloadProgressIncrement); | 135 library->status().download_progress * kDownloadProgressIncrement); |
| 127 actor_->SetProgress(kBeforeDownloadProgress + download_progress); | 136 actor_->SetProgress(kBeforeDownloadProgress + download_progress); |
| 128 } | 137 } |
| 129 break; | 138 break; |
| 130 case UPDATE_STATUS_VERIFYING: | 139 case UPDATE_STATUS_VERIFYING: |
| 131 MakeSureScreenIsShown(); | 140 MakeSureScreenIsShown(); |
| 132 actor_->SetProgress(kBeforeVerifyingProgress); | 141 actor_->SetProgress(kBeforeVerifyingProgress); |
| 133 break; | 142 break; |
| 134 case UPDATE_STATUS_FINALIZING: | 143 case UPDATE_STATUS_FINALIZING: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 145 VLOG(1) << "Initiate reboot after update"; | 154 VLOG(1) << "Initiate reboot after update"; |
| 146 CrosLibrary::Get()->GetUpdateLibrary()->RebootAfterUpdate(); | 155 CrosLibrary::Get()->GetUpdateLibrary()->RebootAfterUpdate(); |
| 147 reboot_timer_.Start(base::TimeDelta::FromSeconds(reboot_check_delay_), | 156 reboot_timer_.Start(base::TimeDelta::FromSeconds(reboot_check_delay_), |
| 148 this, | 157 this, |
| 149 &UpdateScreen::OnWaitForRebootTimeElapsed); | 158 &UpdateScreen::OnWaitForRebootTimeElapsed); |
| 150 } else { | 159 } else { |
| 151 ExitUpdate(REASON_UPDATE_NON_CRITICAL); | 160 ExitUpdate(REASON_UPDATE_NON_CRITICAL); |
| 152 } | 161 } |
| 153 break; | 162 break; |
| 154 case UPDATE_STATUS_IDLE: | 163 case UPDATE_STATUS_IDLE: |
| 164 if (ignore_idle_status_) { |
| 165 // It is first IDLE status that is sent before we initiated the check. |
| 166 break; |
| 167 } |
| 168 // else no break |
| 169 |
| 155 case UPDATE_STATUS_ERROR: | 170 case UPDATE_STATUS_ERROR: |
| 156 case UPDATE_STATUS_REPORTING_ERROR_EVENT: | 171 case UPDATE_STATUS_REPORTING_ERROR_EVENT: |
| 157 ExitUpdate(REASON_UPDATE_ENDED); | 172 ExitUpdate(REASON_UPDATE_ENDED); |
| 158 break; | 173 break; |
| 159 default: | 174 default: |
| 160 NOTREACHED(); | 175 NOTREACHED(); |
| 161 break; | 176 break; |
| 162 } | 177 } |
| 163 } | 178 } |
| 164 | 179 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 get_screen_observer()->ShowCurrentScreen(); | 263 get_screen_observer()->ShowCurrentScreen(); |
| 249 } | 264 } |
| 250 | 265 |
| 251 void UpdateScreen::SetRebootCheckDelay(int seconds) { | 266 void UpdateScreen::SetRebootCheckDelay(int seconds) { |
| 252 if (seconds <= 0) | 267 if (seconds <= 0) |
| 253 reboot_timer_.Stop(); | 268 reboot_timer_.Stop(); |
| 254 DCHECK(!reboot_timer_.IsRunning()); | 269 DCHECK(!reboot_timer_.IsRunning()); |
| 255 reboot_check_delay_ = seconds; | 270 reboot_check_delay_ = seconds; |
| 256 } | 271 } |
| 257 | 272 |
| 273 void UpdateScreen::SetIgnoreIdleStatus(bool ignore_idle_status) { |
| 274 ignore_idle_status_ = ignore_idle_status; |
| 275 } |
| 276 |
| 258 bool UpdateScreen::HasCriticalUpdate() { | 277 bool UpdateScreen::HasCriticalUpdate() { |
| 259 if (is_ignore_update_deadlines_) | 278 if (is_ignore_update_deadlines_) |
| 260 return true; | 279 return true; |
| 261 | 280 |
| 262 std::string deadline; | 281 std::string deadline; |
| 263 // Checking for update flag file causes us to do blocking IO on UI thread. | 282 // Checking for update flag file causes us to do blocking IO on UI thread. |
| 264 // Temporarily allow it until we fix http://crosbug.com/11106 | 283 // Temporarily allow it until we fix http://crosbug.com/11106 |
| 265 base::ThreadRestrictions::ScopedAllowIO allow_io; | 284 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 266 FilePath update_deadline_file_path(kUpdateDeadlineFile); | 285 FilePath update_deadline_file_path(kUpdateDeadlineFile); |
| 267 if (!file_util::ReadFileToString(update_deadline_file_path, &deadline) || | 286 if (!file_util::ReadFileToString(update_deadline_file_path, &deadline) || |
| 268 deadline.empty()) { | 287 deadline.empty()) { |
| 269 return false; | 288 return false; |
| 270 } | 289 } |
| 271 | 290 |
| 272 // TODO(dpolukhin): Analyze file content. Now we can just assume that | 291 // TODO(dpolukhin): Analyze file content. Now we can just assume that |
| 273 // if the file exists and not empty, there is critical update. | 292 // if the file exists and not empty, there is critical update. |
| 274 return true; | 293 return true; |
| 275 } | 294 } |
| 276 | 295 |
| 277 } // namespace chromeos | 296 } // namespace chromeos |
| OLD | NEW |