| OLD | NEW |
| (Empty) |
| 1 // Copyright 2008-2010 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 | |
| 16 #ifndef OMAHA_UI_PROGRESS_WND_H_ | |
| 17 #define OMAHA_UI_PROGRESS_WND_H_ | |
| 18 | |
| 19 #include <atlbase.h> | |
| 20 #include <vector> | |
| 21 #include "base/scoped_ptr.h" | |
| 22 #include "omaha/base/scoped_any.h" | |
| 23 #include "omaha/base/time.h" | |
| 24 #include "omaha/base/wtl_atlapp_wrapper.h" | |
| 25 #include "omaha/client/install_progress_observer.h" | |
| 26 #include "omaha/ui/complete_wnd.h" | |
| 27 #include "omaha/ui/uilib/static_ex.h" | |
| 28 | |
| 29 namespace omaha { | |
| 30 | |
| 31 class HighresTimer; | |
| 32 | |
| 33 // The message is used to communicate between InstallStoppedWnd and | |
| 34 // ProgressWnd. | |
| 35 const DWORD WM_INSTALL_STOPPED = WM_APP; | |
| 36 | |
| 37 class ProgressWndEvents : public CompleteWndEvents { | |
| 38 public: | |
| 39 // Restarts the browser(s) and returns whether the browser was successfully | |
| 40 // restarted. | |
| 41 // If restart_all_browsers is true, all known browsers will be shutdown. | |
| 42 // Otherwise only one type of browser will be shutdown. The concrete class | |
| 43 // is expected to know which browser to shutdown in that case. | |
| 44 // After that, only one type of browser will be restarted with the given URLs. | |
| 45 // | |
| 46 // Major browsers that support multi-tab differ how to open multiple URLs: | |
| 47 // IExplorer (8.0): opens each URL in a separate window. | |
| 48 // Firefox (3.6): by default if there is Firefox instance running, the URLs | |
| 49 // will be opened in tabs in the same window. Otherwise each URL will | |
| 50 // have its own window. Since we shutdown browser(s) first, it is | |
| 51 // more likely to result in multiple windows. | |
| 52 // Chrome (5.0): opens each URL in a separate tab in the same window. | |
| 53 virtual bool DoRestartBrowser(bool restart_all_browsers, | |
| 54 const std::vector<CString>& urls) = 0; | |
| 55 | |
| 56 // Initiates a reboot and returns whether it was iniated successfully. | |
| 57 virtual bool DoReboot() = 0; | |
| 58 | |
| 59 // Indicates that current operation is canceled. | |
| 60 virtual void DoCancel() = 0; | |
| 61 }; | |
| 62 | |
| 63 // Implements the "Installation Stopped" window. InstallStoppedWnd is | |
| 64 // modal relative to its parent. When InstallStoppedWnd is closed it sends | |
| 65 // a user message to its parent to notify which button the user has clicked on. | |
| 66 class InstallStoppedWnd | |
| 67 : public CAxDialogImpl<InstallStoppedWnd>, | |
| 68 public CMessageFilter { | |
| 69 typedef CAxDialogImpl<InstallStoppedWnd> Base; | |
| 70 public: | |
| 71 static const int IDD = IDD_INSTALL_STOPPED; | |
| 72 | |
| 73 InstallStoppedWnd(CMessageLoop* message_loop, HWND parent); | |
| 74 ~InstallStoppedWnd(); | |
| 75 | |
| 76 // Closes the window, handling transition back to the parent window. | |
| 77 HRESULT CloseWindow(); | |
| 78 | |
| 79 BOOL PreTranslateMessage(MSG* msg) { | |
| 80 return CWindow::IsDialogMessage(msg); | |
| 81 } | |
| 82 | |
| 83 BEGIN_MSG_MAP(InstallStoppedWnd) | |
| 84 MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) | |
| 85 MESSAGE_HANDLER(WM_DESTROY, OnDestroy) | |
| 86 COMMAND_ID_HANDLER(IDOK, OnClickButton) | |
| 87 COMMAND_ID_HANDLER(IDCANCEL, OnClickButton) | |
| 88 CHAIN_MSG_MAP(Base) | |
| 89 END_MSG_MAP() | |
| 90 | |
| 91 private: | |
| 92 // Message and command handlers. | |
| 93 LRESULT OnInitDialog(UINT msg, WPARAM wparam, LPARAM lparam, BOOL& handled);
// NOLINT | |
| 94 LRESULT OnClickButton(WORD notify_code, WORD id, HWND wnd_ctl, BOOL& handled);
// NOLINT | |
| 95 LRESULT OnDestroy(UINT msg, WPARAM wparam, LPARAM lparam, BOOL& handled);
// NOLINT | |
| 96 | |
| 97 CMessageLoop* message_loop_; | |
| 98 HWND parent_; | |
| 99 | |
| 100 DISALLOW_EVIL_CONSTRUCTORS(InstallStoppedWnd); | |
| 101 }; | |
| 102 | |
| 103 | |
| 104 // Implements the UI progress window. | |
| 105 class ProgressWnd | |
| 106 : public CompleteWnd, | |
| 107 public InstallProgressObserver { | |
| 108 public: | |
| 109 ProgressWnd(CMessageLoop* message_loop, HWND parent); | |
| 110 virtual ~ProgressWnd(); | |
| 111 | |
| 112 void SetEventSink(ProgressWndEvents* ev); | |
| 113 | |
| 114 // InstallProgressObserver methods. | |
| 115 // TODO(omaha3): Update this comment. | |
| 116 // These methods are called by the job to transition the UI from | |
| 117 // one state to another. The methods are always executed by the thread | |
| 118 // that created this window. | |
| 119 virtual void OnCheckingForUpdate(); | |
| 120 virtual void OnUpdateAvailable(const CString& app_name, | |
| 121 const CString& version_string); | |
| 122 virtual void OnWaitingToDownload(const CString& app_name); | |
| 123 virtual void OnDownloading(const CString& app_name, | |
| 124 int time_remaining_ms, | |
| 125 int pos); | |
| 126 virtual void OnWaitingRetryDownload(const CString& app_name, | |
| 127 time64 next_retry_time); | |
| 128 virtual void OnWaitingToInstall(const CString& app_name, | |
| 129 bool* can_start_install); | |
| 130 virtual void OnInstalling(const CString& app_name); | |
| 131 virtual void OnPause(); | |
| 132 virtual void OnComplete(const ObserverCompletionInfo& observer_info); | |
| 133 | |
| 134 BEGIN_MSG_MAP(ProgressWnd) | |
| 135 MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) | |
| 136 MESSAGE_HANDLER(WM_INSTALL_STOPPED, OnInstallStopped) | |
| 137 COMMAND_HANDLER(IDC_BUTTON1, BN_CLICKED, OnClickedButton) | |
| 138 COMMAND_HANDLER(IDC_BUTTON2, BN_CLICKED, OnClickedButton) | |
| 139 COMMAND_HANDLER(IDC_CLOSE, BN_CLICKED, OnClickedButton) | |
| 140 CHAIN_MSG_MAP(CompleteWnd) | |
| 141 END_MSG_MAP() | |
| 142 | |
| 143 private: | |
| 144 // Message and command handlers. | |
| 145 LRESULT OnInitDialog(UINT msg, WPARAM wparam, LPARAM lparam, BOOL& handled);
// NOLINT | |
| 146 LRESULT OnInstallStopped(UINT msg, | |
| 147 WPARAM wparam, | |
| 148 LPARAM lparam, | |
| 149 BOOL& handled); // NOLINT | |
| 150 LRESULT OnClickedButton(WORD notify_code, | |
| 151 WORD id, | |
| 152 HWND wnd_ctl, | |
| 153 BOOL& handled); // NOLINT | |
| 154 | |
| 155 // Handles requests to close the window. Returns true if the window is closed. | |
| 156 virtual bool MaybeCloseWindow(); | |
| 157 | |
| 158 // Helpers. | |
| 159 HRESULT LaunchCmdLine(const AppCompletionInfo& app_info); | |
| 160 bool LaunchCmdLines(const ObserverCompletionInfo& info); | |
| 161 HRESULT ChangeControlState(); | |
| 162 HRESULT SetMarqueeMode(bool is_marquee); | |
| 163 | |
| 164 bool IsInstallStoppedWindowPresent(); | |
| 165 | |
| 166 void HandleCancelRequest(); | |
| 167 | |
| 168 // Closes the Installation Stopped window if present. Returns true if closed. | |
| 169 bool CloseInstallStoppedWindow(); | |
| 170 | |
| 171 void DeterminePostInstallUrls(const ObserverCompletionInfo& info); | |
| 172 CompletionCodes GetBundleOverallCompletionCode( | |
| 173 const ObserverCompletionInfo& info) const; | |
| 174 | |
| 175 // TODO(omaha3): These states are used to control the UI elements. Otherwise, | |
| 176 // we could have just a single "complete" state and track restart/reboot state | |
| 177 // separately. | |
| 178 // The states are used as indexes in zero-based arrays so they should | |
| 179 // start at 0. | |
| 180 enum States { | |
| 181 STATE_INIT = 0, | |
| 182 STATE_CHECKING_FOR_UPDATE, | |
| 183 STATE_WAITING_TO_DOWNLOAD, | |
| 184 STATE_DOWNLOADING, | |
| 185 STATE_WAITING_TO_INSTALL, | |
| 186 STATE_INSTALLING, | |
| 187 STATE_PAUSED, | |
| 188 STATE_COMPLETE_SUCCESS, | |
| 189 STATE_COMPLETE_ERROR, | |
| 190 // TODO(omaha): Collapse these two into one state. Controls are the same. | |
| 191 // Add another variable to remember what to do in this state. | |
| 192 STATE_COMPLETE_RESTART_BROWSER, | |
| 193 STATE_COMPLETE_RESTART_ALL_BROWSERS, | |
| 194 STATE_COMPLETE_REBOOT, | |
| 195 STATE_END, | |
| 196 }; | |
| 197 | |
| 198 scoped_ptr<HighresTimer> metrics_timer_; | |
| 199 | |
| 200 // Due to a repaint issue in StaticEx we prefer to manage their lifetime | |
| 201 // very aggressively so we contain them by reference instead of value. | |
| 202 scoped_ptr<StaticEx> pause_resume_text_; | |
| 203 | |
| 204 States cur_state_; | |
| 205 | |
| 206 scoped_ptr<InstallStoppedWnd> install_stopped_wnd_; | |
| 207 | |
| 208 ProgressWndEvents* events_sink_; | |
| 209 std::vector<CString> post_install_urls_; | |
| 210 bool is_canceled_; | |
| 211 | |
| 212 #pragma warning(disable : 4510 4610) | |
| 213 // C4510: default constructor could not be generated | |
| 214 // C4610: struct can never be instantiated - user defined constructor required | |
| 215 struct ControlState { | |
| 216 const int id_; | |
| 217 const ControlAttributes attr_[ProgressWnd::STATE_END + 1]; | |
| 218 }; | |
| 219 #pragma warning(default : 4510 4610) | |
| 220 | |
| 221 static const ControlState ctls_[]; | |
| 222 | |
| 223 // The speed by which the progress bar moves in marquee mode. | |
| 224 static const int kMarqueeModeUpdatesMs = 75; | |
| 225 | |
| 226 friend class UITest; | |
| 227 DISALLOW_EVIL_CONSTRUCTORS(ProgressWnd); | |
| 228 }; | |
| 229 | |
| 230 } // namespace omaha | |
| 231 | |
| 232 #endif // OMAHA_UI_PROGRESS_WND_H_ | |
| 233 | |
| OLD | NEW |