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 #include "omaha/base/debug.h" | |
17 #include "omaha/base/error.h" | |
18 #include "omaha/base/logging.h" | |
19 #include "omaha/base/synchronized.h" | |
20 #include "omaha/goopdate/job_observer.h" | |
21 | |
22 namespace omaha { | |
23 | |
24 JobObserverCOMDecorator::JobObserverCOMDecorator() | |
25 : job_observer_(NULL), | |
26 on_demand_events_(NULL), | |
27 worker_job_thread_id_(::GetCurrentThreadId()) { | |
28 } | |
29 | |
30 JobObserverCOMDecorator::~JobObserverCOMDecorator() { | |
31 Uninitialize(); | |
32 } | |
33 | |
34 void JobObserverCOMDecorator::Initialize(IJobObserver* job_observer) { | |
35 ASSERT1(job_observer); | |
36 | |
37 job_observer_ = job_observer; | |
38 job_observer->SetEventSink(this); | |
39 } | |
40 | |
41 void JobObserverCOMDecorator::Uninitialize() { | |
42 } | |
43 | |
44 void JobObserverCOMDecorator::OnCheckingForUpdate() { | |
45 ASSERT1(job_observer_); | |
46 ASSERT1(worker_job_thread_id_ == ::GetCurrentThreadId()); | |
47 | |
48 job_observer_->OnCheckingForUpdate(); | |
49 } | |
50 | |
51 void JobObserverCOMDecorator::OnUpdateAvailable(const CString& app_name, | |
52 const CString& version_string) { | |
53 UNREFERENCED_PARAMETER(app_name); | |
54 ASSERT1(job_observer_); | |
55 ASSERT1(worker_job_thread_id_ == ::GetCurrentThreadId()); | |
56 | |
57 job_observer_->OnUpdateAvailable(version_string); | |
58 } | |
59 | |
60 void JobObserverCOMDecorator::OnWaitingToDownload(const CString& app_name) { | |
61 UNREFERENCED_PARAMETER(app_name); | |
62 ASSERT1(job_observer_); | |
63 ASSERT1(worker_job_thread_id_ == ::GetCurrentThreadId()); | |
64 | |
65 job_observer_->OnWaitingToDownload(); | |
66 } | |
67 | |
68 void JobObserverCOMDecorator::OnDownloading(const CString& app_name, | |
69 int time_remaining_ms, | |
70 int pos) { | |
71 UNREFERENCED_PARAMETER(app_name); | |
72 ASSERT1(job_observer_); | |
73 ASSERT1(worker_job_thread_id_ == ::GetCurrentThreadId()); | |
74 | |
75 job_observer_->OnDownloading(time_remaining_ms, pos); | |
76 } | |
77 | |
78 void JobObserverCOMDecorator::OnWaitingRetryDownload(const CString& app_name, | |
79 time64 next_retry_time) { | |
80 UNREFERENCED_PARAMETER(app_name); | |
81 UNREFERENCED_PARAMETER(next_retry_time); | |
82 } | |
83 | |
84 void JobObserverCOMDecorator::OnWaitingToInstall(const CString& app_name, | |
85 bool* can_start_install) { | |
86 UNREFERENCED_PARAMETER(app_name); | |
87 ASSERT1(job_observer_); | |
88 ASSERT1(worker_job_thread_id_ == ::GetCurrentThreadId()); | |
89 | |
90 job_observer_->OnWaitingToInstall(); | |
91 *can_start_install = true; | |
92 } | |
93 | |
94 void JobObserverCOMDecorator::OnInstalling(const CString& app_name) { | |
95 UNREFERENCED_PARAMETER(app_name); | |
96 ASSERT1(job_observer_); | |
97 ASSERT1(worker_job_thread_id_ == ::GetCurrentThreadId()); | |
98 | |
99 job_observer_->OnInstalling(); | |
100 } | |
101 | |
102 void JobObserverCOMDecorator::OnPause() { | |
103 ASSERT1(job_observer_); | |
104 ASSERT1(worker_job_thread_id_ == ::GetCurrentThreadId()); | |
105 | |
106 job_observer_->OnPause(); | |
107 } | |
108 | |
109 void JobObserverCOMDecorator::OnComplete(const ObserverCompletionInfo& info) { | |
110 if (job_observer_) { | |
111 ASSERT1(worker_job_thread_id_ == ::GetCurrentThreadId()); | |
112 | |
113 LegacyCompletionCodes completion_code = | |
114 static_cast<LegacyCompletionCodes>(info.completion_code); | |
115 | |
116 // We do not want to send Omaha strings to the application, so pass an empty | |
117 // string instead. | |
118 job_observer_->OnComplete(completion_code, L""); | |
119 job_observer_ = NULL; | |
120 } | |
121 | |
122 OnDemandEventsInterface* on_demand_events(on_demand_events()); | |
123 if (on_demand_events) { | |
124 on_demand_events->DoExit(); | |
125 SetEventSink(NULL); | |
126 } | |
127 | |
128 // The message loop for OnDemand is on a separate thread, which needs to be | |
129 // signaled to exit. | |
130 ::PostQuitMessage(0); | |
131 } | |
132 | |
133 void JobObserverCOMDecorator::SetEventSink( | |
134 OnDemandEventsInterface* event_sink) { | |
135 set_job_events(event_sink); | |
136 } | |
137 | |
138 // TODO(omaha): Need to add a DoPause() to OnDemandEventsInterface. We never | |
139 // expect these to be used since Chrome never did. | |
140 STDMETHODIMP JobObserverCOMDecorator::DoPause() { | |
141 OnDemandEventsInterface* on_demand_events(on_demand_events()); | |
142 if (!on_demand_events) { | |
143 return GOOPDATE_E_OBSERVER_PROGRESS_WND_EVENTS_NULL; | |
144 } | |
145 | |
146 return E_NOTIMPL; | |
147 } | |
148 | |
149 // TODO(omaha): Need to add a DoResume() to OnDemandEventsInterface. | |
150 STDMETHODIMP JobObserverCOMDecorator::DoResume() { | |
151 OnDemandEventsInterface* on_demand_events(on_demand_events()); | |
152 if (!on_demand_events) { | |
153 return GOOPDATE_E_OBSERVER_PROGRESS_WND_EVENTS_NULL; | |
154 } | |
155 | |
156 return E_NOTIMPL; | |
157 } | |
158 | |
159 STDMETHODIMP JobObserverCOMDecorator::DoClose() { | |
160 OnDemandEventsInterface* on_demand_events(on_demand_events()); | |
161 if (!on_demand_events) { | |
162 return GOOPDATE_E_OBSERVER_PROGRESS_WND_EVENTS_NULL; | |
163 } | |
164 | |
165 on_demand_events->DoClose(); | |
166 return S_OK; | |
167 } | |
168 | |
169 // TODO(omaha): Reconcile IJobObserver::DoRestartBrowsers() with | |
170 // OnDemandEventsInterface::DoRestartBrowser(). | |
171 STDMETHODIMP JobObserverCOMDecorator::DoRestartBrowsers() { | |
172 OnDemandEventsInterface* on_demand_events(on_demand_events()); | |
173 if (!on_demand_events) { | |
174 return GOOPDATE_E_OBSERVER_PROGRESS_WND_EVENTS_NULL; | |
175 } | |
176 | |
177 return E_NOTIMPL; | |
178 } | |
179 | |
180 STDMETHODIMP JobObserverCOMDecorator::DoReboot() { | |
181 OnDemandEventsInterface* on_demand_events(on_demand_events()); | |
182 if (!on_demand_events) { | |
183 return GOOPDATE_E_OBSERVER_PROGRESS_WND_EVENTS_NULL; | |
184 } | |
185 | |
186 return E_NOTIMPL; | |
187 } | |
188 | |
189 STDMETHODIMP JobObserverCOMDecorator::DoLaunchBrowser(const WCHAR* url) { | |
190 UNREFERENCED_PARAMETER(url); | |
191 OnDemandEventsInterface* on_demand_events(on_demand_events()); | |
192 if (!on_demand_events) { | |
193 return GOOPDATE_E_OBSERVER_PROGRESS_WND_EVENTS_NULL; | |
194 } | |
195 | |
196 return E_NOTIMPL; | |
197 } | |
198 | |
199 } // namespace omaha | |
OLD | NEW |