| 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/chromeos/login/update_screen_handler.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/update_screen_handler.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/chromeos/login/screens/update_model.h" |
| 9 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | 10 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" |
| 10 #include "chrome/grit/chromium_strings.h" | 11 #include "chrome/grit/chromium_strings.h" |
| 11 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
| 12 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 const char kJsScreenPath[] = "login.UpdateScreen"; | 17 const char kJsScreenPath[] = "login.UpdateScreen"; |
| 17 | 18 |
| 18 } // namespace | 19 } // namespace |
| 19 | 20 |
| 20 namespace chromeos { | 21 namespace chromeos { |
| 21 | 22 |
| 22 UpdateScreenHandler::UpdateScreenHandler() | 23 UpdateScreenHandler::UpdateScreenHandler() |
| 23 : BaseScreenHandler(kJsScreenPath), | 24 : BaseScreenHandler(kJsScreenPath), model_(nullptr), show_on_init_(false) { |
| 24 screen_(NULL), | |
| 25 show_on_init_(false) { | |
| 26 } | 25 } |
| 27 | 26 |
| 28 UpdateScreenHandler::~UpdateScreenHandler() { | 27 UpdateScreenHandler::~UpdateScreenHandler() { |
| 29 if (screen_) | 28 if (model_) |
| 30 screen_->OnActorDestroyed(this); | 29 model_->OnViewDestroyed(this); |
| 31 } | 30 } |
| 32 | 31 |
| 33 void UpdateScreenHandler::DeclareLocalizedValues( | 32 void UpdateScreenHandler::DeclareLocalizedValues( |
| 34 LocalizedValuesBuilder* builder) { | 33 LocalizedValuesBuilder* builder) { |
| 35 builder->Add("checkingForUpdatesMsg", IDS_CHECKING_FOR_UPDATE_MSG); | 34 builder->Add("checkingForUpdatesMsg", IDS_CHECKING_FOR_UPDATE_MSG); |
| 36 builder->Add("installingUpdateDesc", IDS_UPDATE_MSG); | 35 builder->Add("installingUpdateDesc", IDS_UPDATE_MSG); |
| 37 builder->Add("updateScreenTitle", IDS_UPDATE_SCREEN_TITLE); | 36 builder->Add("updateScreenTitle", IDS_UPDATE_SCREEN_TITLE); |
| 38 builder->Add("updateScreenAccessibleTitle", | 37 builder->Add("updateScreenAccessibleTitle", |
| 39 IDS_UPDATE_SCREEN_ACCESSIBLE_TITLE); | 38 IDS_UPDATE_SCREEN_ACCESSIBLE_TITLE); |
| 40 builder->Add("checkingForUpdates", IDS_CHECKING_FOR_UPDATES); | 39 builder->Add("checkingForUpdates", IDS_CHECKING_FOR_UPDATES); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 55 #endif | 54 #endif |
| 56 } | 55 } |
| 57 | 56 |
| 58 void UpdateScreenHandler::Initialize() { | 57 void UpdateScreenHandler::Initialize() { |
| 59 if (show_on_init_) { | 58 if (show_on_init_) { |
| 60 Show(); | 59 Show(); |
| 61 show_on_init_ = false; | 60 show_on_init_ = false; |
| 62 } | 61 } |
| 63 } | 62 } |
| 64 | 63 |
| 65 void UpdateScreenHandler::SetDelegate(UpdateScreenActor::Delegate* screen) { | 64 void UpdateScreenHandler::PrepareToShow() { |
| 66 screen_ = screen; | |
| 67 } | 65 } |
| 68 | 66 |
| 69 void UpdateScreenHandler::Show() { | 67 void UpdateScreenHandler::Show() { |
| 70 if (!page_is_ready()) { | 68 if (!page_is_ready()) { |
| 71 show_on_init_ = true; | 69 show_on_init_ = true; |
| 72 return; | 70 return; |
| 73 } | 71 } |
| 74 ShowScreen(OobeUI::kScreenOobeUpdate, NULL); | 72 ShowScreen(OobeUI::kScreenOobeUpdate, NULL); |
| 75 #if !defined(OFFICIAL_BUILD) | |
| 76 CallJS("enableUpdateCancel"); | |
| 77 #endif | |
| 78 } | 73 } |
| 79 | 74 |
| 80 void UpdateScreenHandler::Hide() { | 75 void UpdateScreenHandler::Hide() { |
| 81 } | 76 } |
| 82 | 77 |
| 83 void UpdateScreenHandler::PrepareToShow() { | 78 void UpdateScreenHandler::Bind(UpdateModel& model) { |
| 79 model_ = &model; |
| 80 BaseScreenHandler::SetBaseScreen(model_); |
| 84 } | 81 } |
| 85 | 82 |
| 86 void UpdateScreenHandler::ShowManualRebootInfo() { | 83 void UpdateScreenHandler::Unbind() { |
| 87 CallJS("setUpdateMessage", l10n_util::GetStringUTF16(IDS_UPDATE_COMPLETED)); | 84 model_ = nullptr; |
| 88 } | 85 BaseScreenHandler::SetBaseScreen(nullptr); |
| 89 | |
| 90 void UpdateScreenHandler::SetProgress(int progress) { | |
| 91 CallJS("setUpdateProgress", progress); | |
| 92 } | |
| 93 | |
| 94 void UpdateScreenHandler::ShowEstimatedTimeLeft(bool visible) { | |
| 95 CallJS("showEstimatedTimeLeft", visible); | |
| 96 } | |
| 97 | |
| 98 void UpdateScreenHandler::SetEstimatedTimeLeft(const base::TimeDelta& time) { | |
| 99 CallJS("setEstimatedTimeLeft", time.InSecondsF()); | |
| 100 } | |
| 101 | |
| 102 void UpdateScreenHandler::ShowProgressMessage(bool visible) { | |
| 103 CallJS("showProgressMessage", visible); | |
| 104 } | |
| 105 | |
| 106 void UpdateScreenHandler::SetProgressMessage(ProgressMessage message) { | |
| 107 int ids = 0; | |
| 108 switch (message) { | |
| 109 case PROGRESS_MESSAGE_UPDATE_AVAILABLE: | |
| 110 ids = IDS_UPDATE_AVAILABLE; | |
| 111 break; | |
| 112 case PROGRESS_MESSAGE_INSTALLING_UPDATE: | |
| 113 ids = IDS_INSTALLING_UPDATE; | |
| 114 break; | |
| 115 case PROGRESS_MESSAGE_VERIFYING: | |
| 116 ids = IDS_UPDATE_VERIFYING; | |
| 117 break; | |
| 118 case PROGRESS_MESSAGE_FINALIZING: | |
| 119 ids = IDS_UPDATE_FINALIZING; | |
| 120 break; | |
| 121 default: | |
| 122 NOTREACHED(); | |
| 123 return; | |
| 124 } | |
| 125 | |
| 126 CallJS("setProgressMessage", l10n_util::GetStringUTF16(ids)); | |
| 127 } | |
| 128 | |
| 129 void UpdateScreenHandler::ShowCurtain(bool visible) { | |
| 130 CallJS("showUpdateCurtain", visible); | |
| 131 } | |
| 132 | |
| 133 void UpdateScreenHandler::RegisterMessages() { | |
| 134 #if !defined(OFFICIAL_BUILD) | |
| 135 AddCallback("cancelUpdate", &UpdateScreenHandler::HandleUpdateCancel); | |
| 136 #endif | |
| 137 } | 86 } |
| 138 | 87 |
| 139 void UpdateScreenHandler::OnConnectToNetworkRequested() { | 88 void UpdateScreenHandler::OnConnectToNetworkRequested() { |
| 140 if (screen_) | 89 if (model_) |
| 141 screen_->OnConnectToNetworkRequested(); | 90 model_->OnConnectToNetworkRequested(); |
| 142 } | 91 } |
| 143 | 92 |
| 144 #if !defined(OFFICIAL_BUILD) | |
| 145 void UpdateScreenHandler::HandleUpdateCancel() { | |
| 146 screen_->CancelUpdate(); | |
| 147 } | |
| 148 #endif | |
| 149 | |
| 150 } // namespace chromeos | 93 } // namespace chromeos |
| OLD | NEW |