Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: chrome/browser/chromeos/login/update_screen.cc

Issue 6648009: Modify UpdateLibrary to use async RequestUpdateCheck call (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nits Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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"
11 #include "chrome/browser/chromeos/login/screen_observer.h" 11 #include "chrome/browser/chromeos/login/screen_observer.h"
12 #include "chrome/browser/chromeos/login/update_view.h" 12 #include "chrome/browser/chromeos/login/update_view.h"
13 #include "chrome/browser/chromeos/login/wizard_controller.h" 13 #include "chrome/browser/chromeos/login/wizard_controller.h"
14 #include "content/browser/browser_thread.h"
14 15
15 namespace { 16 namespace {
16 17
17 // Progress bar stages. Each represents progress bar value 18 // Progress bar stages. Each represents progress bar value
18 // at the beginning of each stage. 19 // at the beginning of each stage.
19 // TODO(nkostylev): Base stage progress values on approximate time. 20 // TODO(nkostylev): Base stage progress values on approximate time.
20 // TODO(nkostylev): Animate progress during each state. 21 // TODO(nkostylev): Animate progress during each state.
21 const int kBeforeUpdateCheckProgress = 7; 22 const int kBeforeUpdateCheckProgress = 7;
22 const int kBeforeDownloadProgress = 14; 23 const int kBeforeDownloadProgress = 14;
23 const int kBeforeVerifyingProgress = 74; 24 const int kBeforeVerifyingProgress = 74;
24 const int kBeforeFinalizingProgress = 81; 25 const int kBeforeFinalizingProgress = 81;
25 const int kProgressComplete = 100; 26 const int kProgressComplete = 100;
26 27
27 // Defines what part of update progress does download part takes. 28 // Defines what part of update progress does download part takes.
28 const int kDownloadProgressIncrement = 60; 29 const int kDownloadProgressIncrement = 60;
29 30
30 // Considering 10px shadow from each side. 31 // Considering 10px shadow from each side.
31 const int kUpdateScreenWidth = 580; 32 const int kUpdateScreenWidth = 580;
32 const int kUpdateScreenHeight = 305; 33 const int kUpdateScreenHeight = 305;
33 34
34 const char kUpdateDeadlineFile[] = "/tmp/update-check-response-deadline"; 35 const char kUpdateDeadlineFile[] = "/tmp/update-check-response-deadline";
35 36
36 } // anonymous namespace 37 } // anonymous namespace
37 38
38 namespace chromeos { 39 namespace chromeos {
39 40
41
42 // static
43 UpdateScreen::InstanceSet& UpdateScreen::GetInstanceSet() {
44 static std::set<UpdateScreen*> instance_set;
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); // not threadsafe.
46 return instance_set;
47 }
48
49 // static
50 bool UpdateScreen::HasInstance(UpdateScreen* inst) {
51 InstanceSet& instance_set = GetInstanceSet();
52 InstanceSet::iterator found = instance_set.find(inst);
53 return (found != instance_set.end());
54 }
55
40 UpdateScreen::UpdateScreen(WizardScreenDelegate* delegate) 56 UpdateScreen::UpdateScreen(WizardScreenDelegate* delegate)
41 : DefaultViewScreen<chromeos::UpdateView>(delegate, 57 : DefaultViewScreen<chromeos::UpdateView>(delegate,
42 kUpdateScreenWidth, 58 kUpdateScreenWidth,
43 kUpdateScreenHeight), 59 kUpdateScreenHeight),
44 checking_for_update_(true), 60 checking_for_update_(true),
45 reboot_check_delay_(0), 61 reboot_check_delay_(0),
46 is_downloading_update_(false), 62 is_downloading_update_(false),
47 is_all_updates_critical_(false) { 63 is_all_updates_critical_(false) {
64 GetInstanceSet().insert(this);
48 } 65 }
49 66
50 UpdateScreen::~UpdateScreen() { 67 UpdateScreen::~UpdateScreen() {
51 // Remove pointer to this object from view. 68 // Remove pointer to this object from view.
52 if (view()) 69 if (view())
53 view()->set_controller(NULL); 70 view()->set_controller(NULL);
54 CrosLibrary::Get()->GetUpdateLibrary()->RemoveObserver(this); 71 CrosLibrary::Get()->GetUpdateLibrary()->RemoveObserver(this);
72 GetInstanceSet().erase(this);
55 } 73 }
56 74
57 void UpdateScreen::UpdateStatusChanged(UpdateLibrary* library) { 75 void UpdateScreen::UpdateStatusChanged(UpdateLibrary* library) {
58 UpdateStatusOperation status = library->status().status; 76 UpdateStatusOperation status = library->status().status;
59 if (checking_for_update_ && status > UPDATE_STATUS_CHECKING_FOR_UPDATE) { 77 if (checking_for_update_ && status > UPDATE_STATUS_CHECKING_FOR_UPDATE) {
60 checking_for_update_ = false; 78 checking_for_update_ = false;
61 } 79 }
62 80
63 switch (status) { 81 switch (status) {
64 case UPDATE_STATUS_CHECKING_FOR_UPDATE: 82 case UPDATE_STATUS_CHECKING_FOR_UPDATE:
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 case UPDATE_STATUS_ERROR: 145 case UPDATE_STATUS_ERROR:
128 case UPDATE_STATUS_REPORTING_ERROR_EVENT: 146 case UPDATE_STATUS_REPORTING_ERROR_EVENT:
129 ExitUpdate(REASON_UPDATE_ENDED); 147 ExitUpdate(REASON_UPDATE_ENDED);
130 break; 148 break;
131 default: 149 default:
132 NOTREACHED(); 150 NOTREACHED();
133 break; 151 break;
134 } 152 }
135 } 153 }
136 154
155 namespace {
156 // Invoked from call to RequestUpdateCheck upon completion of the DBus call.
157 void StartUpdateCallback(void* user_data,
158 UpdateResult result,
159 const char* msg) {
160 if (result != UPDATE_RESULT_SUCCESS) {
161 DCHECK(user_data);
162 UpdateScreen* screen = static_cast<UpdateScreen*>(user_data);
163 if (UpdateScreen::HasInstance(screen))
164 screen->ExitUpdate(UpdateScreen::REASON_UPDATE_INIT_FAILED);
165 }
166 }
167 } // namespace
168
137 void UpdateScreen::StartUpdate() { 169 void UpdateScreen::StartUpdate() {
138 // Reset view if view was created. 170 // Reset view if view was created.
139 if (view()) { 171 if (view()) {
140 view()->Reset(); 172 view()->Reset();
141 view()->set_controller(this); 173 view()->set_controller(this);
142 is_downloading_update_ = false; 174 is_downloading_update_ = false;
143 view()->SetProgress(kBeforeUpdateCheckProgress); 175 view()->SetProgress(kBeforeUpdateCheckProgress);
144 } 176 }
145 177
146 if (!CrosLibrary::Get()->EnsureLoaded()) { 178 if (!CrosLibrary::Get()->EnsureLoaded()) {
147 LOG(ERROR) << "Error loading CrosLibrary"; 179 LOG(ERROR) << "Error loading CrosLibrary";
148 ExitUpdate(REASON_UPDATE_INIT_FAILED); 180 ExitUpdate(REASON_UPDATE_INIT_FAILED);
149 } else { 181 } else {
150 CrosLibrary::Get()->GetUpdateLibrary()->AddObserver(this); 182 CrosLibrary::Get()->GetUpdateLibrary()->AddObserver(this);
151 VLOG(1) << "Initiate update check"; 183 VLOG(1) << "Initiate update check";
152 if (!CrosLibrary::Get()->GetUpdateLibrary()->CheckForUpdate()) { 184 CrosLibrary::Get()->GetUpdateLibrary()->RequestUpdateCheck(
153 ExitUpdate(REASON_UPDATE_INIT_FAILED); 185 StartUpdateCallback, this);
154 }
155 } 186 }
156 } 187 }
157 188
158 void UpdateScreen::CancelUpdate() { 189 void UpdateScreen::CancelUpdate() {
159 // Screen has longer lifetime than it's view. 190 // Screen has longer lifetime than it's view.
160 // View is deleted after wizard proceeds to the next screen. 191 // View is deleted after wizard proceeds to the next screen.
161 if (view()) 192 if (view())
162 ExitUpdate(REASON_UPDATE_CANCELED); 193 ExitUpdate(REASON_UPDATE_CANCELED);
163 } 194 }
164 195
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 // TODO(dpolukhin): Analyze file content. Now we can just assume that 280 // TODO(dpolukhin): Analyze file content. Now we can just assume that
250 // if the file exists and not empty, there is critical update. 281 // if the file exists and not empty, there is critical update.
251 return true; 282 return true;
252 } 283 }
253 284
254 void UpdateScreen::SetAllUpdatesCritical(bool is_critical) { 285 void UpdateScreen::SetAllUpdatesCritical(bool is_critical) {
255 is_all_updates_critical_ = is_critical; 286 is_all_updates_critical_ = is_critical;
256 } 287 }
257 288
258 } // namespace chromeos 289 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/update_screen.h ('k') | chrome/browser/chromeos/login/update_screen_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698