1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_UPDATER_WIN_INSTALL_PROGRESS_OBSERVER_H_
6 #define CHROME_UPDATER_WIN_INSTALL_PROGRESS_OBSERVER_H_
7
8 #include <vector>
9
10 #include "base/notreached.h"
11 #include "base/strings/string16.h"
12
13 namespace base {
14 class Time;
15 } // namespace base
16
17 // The data structures defined in this file are similar to those defined
18 // defined in Omaha. Keep them as they are for now for documentation purposes
19 // until https://crbug.com/1014630 has been fixed.
20 namespace updater {
21
22 enum class CompletionCodes {
23 COMPLETION_CODE_SUCCESS = 1,
24 COMPLETION_CODE_EXIT_SILENTLY,
25 COMPLETION_CODE_ERROR = COMPLETION_CODE_SUCCESS + 2,
26 COMPLETION_CODE_RESTART_ALL_BROWSERS,
27 COMPLETION_CODE_REBOOT,
28 COMPLETION_CODE_RESTART_BROWSER,
29 COMPLETION_CODE_RESTART_ALL_BROWSERS_NOTICE_ONLY,
30 COMPLETION_CODE_REBOOT_NOTICE_ONLY,
31 COMPLETION_CODE_RESTART_BROWSER_NOTICE_ONLY,
32 COMPLETION_CODE_LAUNCH_COMMAND,
33 COMPLETION_CODE_EXIT_SILENTLY_ON_LAUNCH_COMMAND,
34 COMPLETION_CODE_INSTALL_FINISHED_BEFORE_CANCEL,
35 };
36
IsCompletionCodeSuccess(CompletionCodes completion_code)37 inline bool IsCompletionCodeSuccess(CompletionCodes completion_code) {
38 switch (completion_code) {
39 case CompletionCodes::COMPLETION_CODE_SUCCESS:
40 case CompletionCodes::COMPLETION_CODE_EXIT_SILENTLY:
41 case CompletionCodes::COMPLETION_CODE_RESTART_ALL_BROWSERS:
42 case CompletionCodes::COMPLETION_CODE_REBOOT:
43 case CompletionCodes::COMPLETION_CODE_RESTART_BROWSER:
44 case CompletionCodes::COMPLETION_CODE_RESTART_ALL_BROWSERS_NOTICE_ONLY:
45 case CompletionCodes::COMPLETION_CODE_REBOOT_NOTICE_ONLY:
46 case CompletionCodes::COMPLETION_CODE_RESTART_BROWSER_NOTICE_ONLY:
47 case CompletionCodes::COMPLETION_CODE_LAUNCH_COMMAND:
48 case CompletionCodes::COMPLETION_CODE_EXIT_SILENTLY_ON_LAUNCH_COMMAND:
49 case CompletionCodes::COMPLETION_CODE_INSTALL_FINISHED_BEFORE_CANCEL:
50 return true;
51
52 case CompletionCodes::COMPLETION_CODE_ERROR:
53 return false;
54
55 default:
56 NOTREACHED();
57 return false;
58 }
59 }
60
61 struct AppCompletionInfo {
62 base::string16 display_name;
63 base::string16 app_id;
64 base::string16 completion_message;
65 CompletionCodes completion_code;
66 int error_code = 0;
67 int extra_code1 = 0;
68 uint32_t installer_result_code = 0;
69 bool is_canceled = false;
70 bool is_noupdate = false; // |noupdate| response from server.
71 base::string16 post_install_launch_command_line;
72 base::string16 post_install_url;
73
74 AppCompletionInfo();
75 AppCompletionInfo(const AppCompletionInfo&);
76 ~AppCompletionInfo();
77 };
78
79 struct ObserverCompletionInfo {
80 CompletionCodes completion_code = CompletionCodes::COMPLETION_CODE_SUCCESS;
81 base::string16 completion_text;
82 base::string16 help_url;
83 std::vector<AppCompletionInfo> apps_info;
84
85 ObserverCompletionInfo();
86 ~ObserverCompletionInfo();
87 };
88
89 // Defines an interface for observing install progress. This interface is
90 // typically implemented by a progress window.
91 class InstallProgressObserver {
92 public:
93 virtual ~InstallProgressObserver() = default;
94 virtual void OnCheckingForUpdate() = 0;
95 virtual void OnUpdateAvailable(const base::string16& app_id,
96 const base::string16& app_name,
97 const base::string16& version_string) = 0;
98 virtual void OnWaitingToDownload(const base::string16& app_id,
99 const base::string16& app_name) = 0;
100 virtual void OnDownloading(const base::string16& app_id,
101 const base::string16& app_name,
102 int time_remaining_ms,
103 int pos) = 0;
104 virtual void OnWaitingRetryDownload(const base::string16& app_id,
105 const base::string16& app_name,
106 const base::Time& next_retry_time) = 0;
107 virtual void OnWaitingToInstall(const base::string16& app_id,
108 const base::string16& app_name,
109 bool* can_start_install) = 0;
110 virtual void OnInstalling(const base::string16& app_id,
111 const base::string16& app_name,
112 int time_remaining_ms,
113 int pos) = 0;
114 virtual void OnPause() = 0;
115 virtual void OnComplete(const ObserverCompletionInfo& observer_info) = 0;
116 };
117
118 } // namespace updater
119
120 #endif // CHROME_UPDATER_WIN_INSTALL_PROGRESS_OBSERVER_H_
121