OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/base/dialogs/base_shell_dialog_win.h" | 5 #include "ui/base/dialogs/base_shell_dialog_win.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
| 10 #include "base/win/scoped_com_initializer.h" |
10 | 11 |
11 namespace { | 12 namespace { |
12 | 13 |
13 // Helpers to show certain types of Windows shell dialogs in a way that doesn't | 14 // Helpers to show certain types of Windows shell dialogs in a way that doesn't |
14 // block the UI of the entire app. | 15 // block the UI of the entire app. |
15 class ShellDialogThread : public base::Thread { | 16 class ShellDialogThread : public base::Thread { |
16 public: | 17 public: |
17 ShellDialogThread() : base::Thread("Chrome_ShellDialogThread") { } | 18 ShellDialogThread() : base::Thread("Chrome_ShellDialogThread") { } |
18 ~ShellDialogThread(); | 19 ~ShellDialogThread(); |
19 | 20 |
20 protected: | 21 private: |
21 void Init(); | 22 void Init(); |
22 void CleanUp(); | 23 void CleanUp(); |
23 | 24 |
24 private: | 25 scoped_ptr<base::win::ScopedCOMInitializer> com_initializer_; |
| 26 |
25 DISALLOW_COPY_AND_ASSIGN(ShellDialogThread); | 27 DISALLOW_COPY_AND_ASSIGN(ShellDialogThread); |
26 }; | 28 }; |
27 | 29 |
28 ShellDialogThread::~ShellDialogThread() { | 30 ShellDialogThread::~ShellDialogThread() { |
29 Stop(); | 31 Stop(); |
30 } | 32 } |
31 | 33 |
32 void ShellDialogThread::Init() { | 34 void ShellDialogThread::Init() { |
33 // Initializes the COM library on the current thread. | 35 com_initializer_.reset(new base::win::ScopedCOMInitializer()); |
34 CoInitialize(NULL); | |
35 } | 36 } |
36 | 37 |
37 void ShellDialogThread::CleanUp() { | 38 void ShellDialogThread::CleanUp() { |
38 // Closes the COM library on the current thread. CoInitialize must | 39 com_initializer_.reset(); |
39 // be balanced by a corresponding call to CoUninitialize. | |
40 CoUninitialize(); | |
41 } | 40 } |
42 | 41 |
43 } // namespace | 42 } // namespace |
44 | 43 |
45 namespace ui { | 44 namespace ui { |
46 | 45 |
47 // static | 46 // static |
48 BaseShellDialogImpl::Owners BaseShellDialogImpl::owners_; | 47 BaseShellDialogImpl::Owners BaseShellDialogImpl::owners_; |
49 int BaseShellDialogImpl::instance_count_ = 0; | 48 int BaseShellDialogImpl::instance_count_ = 0; |
50 | 49 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 DCHECK(started); | 100 DCHECK(started); |
102 return thread; | 101 return thread; |
103 } | 102 } |
104 | 103 |
105 void BaseShellDialogImpl::EnableOwner(HWND owner) { | 104 void BaseShellDialogImpl::EnableOwner(HWND owner) { |
106 if (IsWindow(owner)) | 105 if (IsWindow(owner)) |
107 EnableWindow(owner, TRUE); | 106 EnableWindow(owner, TRUE); |
108 } | 107 } |
109 | 108 |
110 } // namespace ui | 109 } // namespace ui |
OLD | NEW |