OLD | NEW |
| (Empty) |
1 // Copyright 2011 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/client/shutdown_events.h" | |
17 #include <atlsafe.h> | |
18 #include "base/scoped_ptr.h" | |
19 #include "omaha/base/debug.h" | |
20 #include "omaha/base/error.h" | |
21 #include "omaha/base/logging.h" | |
22 #include "omaha/base/reactor.h" | |
23 #include "omaha/base/shutdown_handler.h" | |
24 #include "omaha/base/synchronized.h" | |
25 #include "omaha/client/bundle_installer.h" | |
26 | |
27 namespace omaha { | |
28 | |
29 ShutdownEvents::ShutdownEvents(BundleInstaller* installer) | |
30 : installer_(installer) { | |
31 ASSERT1(installer); | |
32 } | |
33 | |
34 ShutdownEvents::~ShutdownEvents() { | |
35 CORE_LOG(L2, (_T("[ShutdownEvents::~ShutdownEvents]"))); | |
36 __mutexScope(lock_); | |
37 | |
38 CORE_LOG(L2, (_T("[Destroying shutdown handler]"))); | |
39 shutdown_handler_.reset(); | |
40 reactor_.reset(); | |
41 } | |
42 | |
43 HRESULT ShutdownEvents::InitializeShutdownHandler(bool is_machine) { | |
44 CORE_LOG(L3, (_T("[InitializeShutdownHandler]"))); | |
45 | |
46 reactor_.reset(new Reactor); | |
47 shutdown_handler_.reset(new ShutdownHandler); | |
48 return shutdown_handler_->Initialize(reactor_.get(), this, is_machine); | |
49 } | |
50 | |
51 // Shutdown() is called from a thread in the OS threadpool. The PostMessage | |
52 // marshals the call over to the UI thread, which is where DoClose needs to be | |
53 // (and is) called from. | |
54 HRESULT ShutdownEvents::Shutdown() { | |
55 CORE_LOG(L2, (_T("[Shutdown]"))); | |
56 | |
57 __mutexScope(lock_); | |
58 | |
59 CORE_LOG(L2, (_T("[Shutdown][IsWindow: %d]"), installer_->IsWindow())); | |
60 if (installer_->IsWindow()) { | |
61 installer_->PostMessage(WM_CLOSE, 0, 0); | |
62 } | |
63 | |
64 return S_OK; | |
65 } | |
66 | |
67 HRESULT ShutdownEvents::CreateShutdownHandler( | |
68 bool is_machine, | |
69 BundleInstaller* installer, | |
70 ShutdownCallback** shutdown_callback) { | |
71 ASSERT1(installer); | |
72 ASSERT1(shutdown_callback); | |
73 ASSERT1(!*shutdown_callback); | |
74 | |
75 scoped_ptr<ShutdownEvents> shutdown_events(new ShutdownEvents(installer)); | |
76 HRESULT hr = shutdown_events->InitializeShutdownHandler(is_machine); | |
77 if (FAILED(hr)) { | |
78 CORE_LOG(LE, (_T("[InitializeShutDownHandler failed][0x%08x]"), hr)); | |
79 return hr; | |
80 } | |
81 | |
82 *shutdown_callback = shutdown_events.release(); | |
83 return S_OK; | |
84 } | |
85 | |
86 } // namespace omaha | |
OLD | NEW |