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

Side by Side Diff: tools/performondemand/performondemand.h

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « tools/performondemand/build.scons ('k') | tools/performondemand/performondemand.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2008-2009 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
17 #ifndef OMAHA_TOOLS_SRC_PERFORMONDEMAND_PERFORMONDEMAND_H_
18 #define OMAHA_TOOLS_SRC_PERFORMONDEMAND_PERFORMONDEMAND_H_
19
20 #pragma once
21 #include <windows.h>
22 #include <atlbase.h>
23 #include <atlcom.h>
24 #include "goopdate\google_update_idl.h" // NOLINT
25
26 // Keep this list syncronized with qa\client\lib\on_demand_lib.py
27 #define ON_COMPLETE_SUCCESS 0x00000001
28 #define ON_COMPLETE_SUCCESS_CLOSE_UI 0x00000002
29 #define ON_COMPLETE_ERROR 0x00000004
30 #define ON_COMPLETE_RESTART_ALL_BROWSERS 0x00000008
31 #define ON_COMPLETE_REBOOT 0x00000010
32 #define ON_SHOW 0x00000020
33 #define ON_CHECKING_FOR_UPDATES 0x00000040
34 #define ON_UPDATE_AVAILABLE 0x00000080
35 #define ON_WAITING_TO_DOWNLOAD 0x00000100
36 #define ON_DOWNLOADING 0x00000200
37 #define ON_WAITING_TO_INSTALL 0x00000400
38 #define ON_INSTALLING 0x00000800
39 #define ON_PAUSE 0x00001000
40 #define SET_EVENT_SINK 0x00002000
41 #define ON_COMPLETE_RESTART_BROWSER 0x00004000
42 #define ON_COMPLETE_RESTART_ALL_BROWSERS_NOTICE_ONLY 0x00008000
43 #define ON_COMPLETE_REBOOT_NOTICE_ONLY 0x00010000
44 #define ON_COMPLETE_RESTART_BROWSER_NOTICE_ONLY 0x00020000
45 #define ON_COMPLETE_RUN_COMMAND 0x00040000
46
47 class JobObserver
48 : public CComObjectRootEx<CComSingleThreadModel>,
49 public IJobObserver {
50 public:
51 BEGIN_COM_MAP(JobObserver)
52 COM_INTERFACE_ENTRY(IJobObserver)
53 END_COM_MAP()
54
55 // Each interaction enables a bit in observed, which is eventually returned as
56 // a return code.
57 int observed;
58
59 // Similar to observed, misbehave_modes_ and close_modes_ take on bits from
60 // the list of all events. For example, if close_modes_ | ON_DOWNLOADING
61 // is true, then when ON_DOWNLOADING is called, DoClose will be called.
62 int misbehave_modes_;
63 int close_modes_;
64 bool do_closed_called;
65
66 JobObserver()
67 : observed(0), misbehave_modes_(0), close_modes_(0),
68 do_closed_called(false) {
69 wprintf(L"JobObserver\n");
70 }
71 virtual ~JobObserver() {
72 wprintf(L"~JobObserver\n");
73 }
74
75 void Reset() {
76 observed = 0;
77 misbehave_modes_ = 0;
78 close_modes_ = 0;
79 do_closed_called = false;
80 }
81
82 void AddMisbehaveMode(int event_code) {
83 misbehave_modes_ |= event_code;
84 }
85
86 void AddCloseMode(int event_code) {
87 close_modes_ |= event_code;
88 }
89
90 HRESULT HandleEvent(int event_code) {
91 observed |= event_code;
92
93 if ((event_code & close_modes_) && !do_closed_called) {
94 wprintf(L"Calling DoClose()\n");
95 do_closed_called = true;
96 event_sink_->DoClose();
97 }
98
99 if (event_code & misbehave_modes_) {
100 wprintf(L"Misbehaving\n");
101 return E_FAIL;
102 } else {
103 return S_OK;
104 }
105 }
106
107 // JobObserver implementation.
108 STDMETHOD(OnShow)() {
109 wprintf(L"OnShow\n");
110 return HandleEvent(ON_SHOW);
111 }
112 STDMETHOD(OnCheckingForUpdate)() {
113 wprintf(L"OnCheckingForUpdate\n");
114 return HandleEvent(ON_CHECKING_FOR_UPDATES);
115 }
116 STDMETHOD(OnUpdateAvailable)(const TCHAR* version_string) {
117 wprintf(L"OnUpdateAvailable [%s]\n", version_string);
118 return HandleEvent(ON_UPDATE_AVAILABLE);
119 }
120 STDMETHOD(OnWaitingToDownload)() {
121 wprintf(L"OnWaitingToDownload\n");
122 return HandleEvent(ON_WAITING_TO_INSTALL);
123 }
124 STDMETHOD(OnDownloading)(int time_remaining_ms, int pos) {
125 wprintf(L"OnDownloading [%d][%d]\n", time_remaining_ms, pos);
126 return HandleEvent(ON_DOWNLOADING);
127 }
128 STDMETHOD(OnWaitingToInstall)() {
129 wprintf(L"OnWaitingToInstall\n");
130 return HandleEvent(ON_WAITING_TO_INSTALL);
131 }
132 STDMETHOD(OnInstalling)() {
133 wprintf(L"OnInstalling\n");
134 return HandleEvent(ON_INSTALLING);
135 }
136 STDMETHOD(OnPause)() {
137 wprintf(L"OnPause\n");
138 return HandleEvent(ON_PAUSE);
139 }
140 STDMETHOD(OnComplete)(CompletionCodes code, const TCHAR* text) {
141 wprintf(L"OnComplete [%d][%s]\n", code, text);
142 int event_code = 0;
143 switch (code) {
144 case COMPLETION_CODE_SUCCESS:
145 event_code |= ON_COMPLETE_SUCCESS;
146 break;
147 case COMPLETION_CODE_SUCCESS_CLOSE_UI:
148 event_code |= ON_COMPLETE_SUCCESS_CLOSE_UI;
149 break;
150 case COMPLETION_CODE_ERROR:
151 event_code |= ON_COMPLETE_ERROR;
152 break;
153 case COMPLETION_CODE_RESTART_ALL_BROWSERS:
154 event_code |= ON_COMPLETE_RESTART_ALL_BROWSERS;
155 break;
156 case COMPLETION_CODE_REBOOT:
157 event_code |= ON_COMPLETE_REBOOT;
158 break;
159 case COMPLETION_CODE_RESTART_BROWSER:
160 event_code |= ON_COMPLETE_RESTART_BROWSER;
161 break;
162 case COMPLETION_CODE_RESTART_ALL_BROWSERS_NOTICE_ONLY:
163 event_code |= ON_COMPLETE_RESTART_ALL_BROWSERS_NOTICE_ONLY;
164 break;
165 case COMPLETION_CODE_REBOOT_NOTICE_ONLY:
166 event_code |= ON_COMPLETE_REBOOT_NOTICE_ONLY;
167 break;
168 case COMPLETION_CODE_RESTART_BROWSER_NOTICE_ONLY:
169 event_code |= ON_COMPLETE_RESTART_BROWSER_NOTICE_ONLY;
170 break;
171 case COMPLETION_CODE_RUN_COMMAND:
172 event_code |= ON_COMPLETE_RUN_COMMAND;
173 break;
174 default:
175 break;
176 }
177 ::PostThreadMessage(::GetCurrentThreadId(), WM_QUIT, 0, 0);
178 return HandleEvent(event_code);
179 }
180 STDMETHOD(SetEventSink)(IProgressWndEvents* event_sink) {
181 wprintf(L"SetEventSink [%d]\n", event_sink);
182 event_sink_ = event_sink;
183 return HandleEvent(SET_EVENT_SINK);
184 }
185
186 CComPtr<IProgressWndEvents> event_sink_;
187 };
188
189 #endif // OMAHA_TOOLS_SRC_PERFORMONDEMAND_PERFORMONDEMAND_H_
OLDNEW
« no previous file with comments | « tools/performondemand/build.scons ('k') | tools/performondemand/performondemand.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698