OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chrome_select_file_dialog_factory_win.h" | 5 #include "chrome/browser/chrome_select_file_dialog_factory_win.h" |
6 | 6 |
7 #include <Windows.h> | 7 #include <Windows.h> |
8 #include <commdlg.h> | 8 #include <commdlg.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 // Returns the selected directory. | 44 // Returns the selected directory. |
45 const base::FilePath& directory() const { return directory_; } | 45 const base::FilePath& directory() const { return directory_; } |
46 | 46 |
47 // Returns the list of selected filenames. Each should be interpreted as a | 47 // Returns the list of selected filenames. Each should be interpreted as a |
48 // child of directory(). | 48 // child of directory(). |
49 const std::vector<base::FilePath>& filenames() const { return filenames_; } | 49 const std::vector<base::FilePath>& filenames() const { return filenames_; } |
50 | 50 |
51 // UtilityProcessHostClient implementation | 51 // UtilityProcessHostClient implementation |
52 void OnProcessCrashed(int exit_code) override; | 52 void OnProcessCrashed(int exit_code) override; |
53 void OnProcessLaunchFailed() override; | 53 void OnProcessLaunchFailed(int error_code) override; |
54 bool OnMessageReceived(const IPC::Message& message) override; | 54 bool OnMessageReceived(const IPC::Message& message) override; |
55 | 55 |
56 protected: | 56 protected: |
57 ~GetOpenFileNameClient() override; | 57 ~GetOpenFileNameClient() override; |
58 | 58 |
59 private: | 59 private: |
60 void OnResult(const base::FilePath& directory, | 60 void OnResult(const base::FilePath& directory, |
61 const std::vector<base::FilePath>& filenames); | 61 const std::vector<base::FilePath>& filenames); |
62 void OnFailure(); | 62 void OnFailure(); |
63 | 63 |
64 base::FilePath directory_; | 64 base::FilePath directory_; |
65 std::vector<base::FilePath> filenames_; | 65 std::vector<base::FilePath> filenames_; |
66 base::WaitableEvent event_; | 66 base::WaitableEvent event_; |
67 | 67 |
68 DISALLOW_COPY_AND_ASSIGN(GetOpenFileNameClient); | 68 DISALLOW_COPY_AND_ASSIGN(GetOpenFileNameClient); |
69 }; | 69 }; |
70 | 70 |
71 GetOpenFileNameClient::GetOpenFileNameClient() : event_(true, false) { | 71 GetOpenFileNameClient::GetOpenFileNameClient() : event_(true, false) { |
72 } | 72 } |
73 | 73 |
74 void GetOpenFileNameClient::WaitForCompletion() { | 74 void GetOpenFileNameClient::WaitForCompletion() { |
75 event_.Wait(); | 75 event_.Wait(); |
76 } | 76 } |
77 | 77 |
78 void GetOpenFileNameClient::OnProcessCrashed(int exit_code) { | 78 void GetOpenFileNameClient::OnProcessCrashed(int exit_code) { |
79 event_.Signal(); | 79 event_.Signal(); |
80 } | 80 } |
81 | 81 |
82 void GetOpenFileNameClient::OnProcessLaunchFailed() { | 82 void GetOpenFileNameClient::OnProcessLaunchFailed(int error_code) { |
83 event_.Signal(); | 83 event_.Signal(); |
84 } | 84 } |
85 | 85 |
86 bool GetOpenFileNameClient::OnMessageReceived(const IPC::Message& message) { | 86 bool GetOpenFileNameClient::OnMessageReceived(const IPC::Message& message) { |
87 bool handled = true; | 87 bool handled = true; |
88 IPC_BEGIN_MESSAGE_MAP(GetOpenFileNameClient, message) | 88 IPC_BEGIN_MESSAGE_MAP(GetOpenFileNameClient, message) |
89 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GetOpenFileName_Failed, | 89 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GetOpenFileName_Failed, |
90 OnFailure) | 90 OnFailure) |
91 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GetOpenFileName_Result, | 91 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GetOpenFileName_Result, |
92 OnResult) | 92 OnResult) |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 void WaitForCompletion(); | 173 void WaitForCompletion(); |
174 | 174 |
175 // Returns the selected path. | 175 // Returns the selected path. |
176 const base::FilePath& path() const { return path_; } | 176 const base::FilePath& path() const { return path_; } |
177 | 177 |
178 // Returns the index of the user-selected filter. | 178 // Returns the index of the user-selected filter. |
179 int one_based_filter_index() const { return one_based_filter_index_; } | 179 int one_based_filter_index() const { return one_based_filter_index_; } |
180 | 180 |
181 // UtilityProcessHostClient implementation | 181 // UtilityProcessHostClient implementation |
182 void OnProcessCrashed(int exit_code) override; | 182 void OnProcessCrashed(int exit_code) override; |
183 void OnProcessLaunchFailed() override; | 183 void OnProcessLaunchFailed(int error_code) override; |
184 bool OnMessageReceived(const IPC::Message& message) override; | 184 bool OnMessageReceived(const IPC::Message& message) override; |
185 | 185 |
186 protected: | 186 protected: |
187 ~GetSaveFileNameClient() override; | 187 ~GetSaveFileNameClient() override; |
188 | 188 |
189 private: | 189 private: |
190 void OnResult(const base::FilePath& path, int one_based_filter_index); | 190 void OnResult(const base::FilePath& path, int one_based_filter_index); |
191 void OnFailure(); | 191 void OnFailure(); |
192 | 192 |
193 base::FilePath path_; | 193 base::FilePath path_; |
194 int one_based_filter_index_; | 194 int one_based_filter_index_; |
195 base::WaitableEvent event_; | 195 base::WaitableEvent event_; |
196 | 196 |
197 DISALLOW_COPY_AND_ASSIGN(GetSaveFileNameClient); | 197 DISALLOW_COPY_AND_ASSIGN(GetSaveFileNameClient); |
198 }; | 198 }; |
199 | 199 |
200 GetSaveFileNameClient::GetSaveFileNameClient() | 200 GetSaveFileNameClient::GetSaveFileNameClient() |
201 : one_based_filter_index_(0), event_(true, false) { | 201 : one_based_filter_index_(0), event_(true, false) { |
202 } | 202 } |
203 | 203 |
204 void GetSaveFileNameClient::WaitForCompletion() { | 204 void GetSaveFileNameClient::WaitForCompletion() { |
205 event_.Wait(); | 205 event_.Wait(); |
206 } | 206 } |
207 | 207 |
208 void GetSaveFileNameClient::OnProcessCrashed(int exit_code) { | 208 void GetSaveFileNameClient::OnProcessCrashed(int exit_code) { |
209 event_.Signal(); | 209 event_.Signal(); |
210 } | 210 } |
211 | 211 |
212 void GetSaveFileNameClient::OnProcessLaunchFailed() { | 212 void GetSaveFileNameClient::OnProcessLaunchFailed(int error_code) { |
213 event_.Signal(); | 213 event_.Signal(); |
214 } | 214 } |
215 | 215 |
216 bool GetSaveFileNameClient::OnMessageReceived(const IPC::Message& message) { | 216 bool GetSaveFileNameClient::OnMessageReceived(const IPC::Message& message) { |
217 bool handled = true; | 217 bool handled = true; |
218 IPC_BEGIN_MESSAGE_MAP(GetSaveFileNameClient, message) | 218 IPC_BEGIN_MESSAGE_MAP(GetSaveFileNameClient, message) |
219 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GetSaveFileName_Failed, | 219 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GetSaveFileName_Failed, |
220 OnFailure) | 220 OnFailure) |
221 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GetSaveFileName_Result, | 221 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GetSaveFileName_Result, |
222 OnResult) | 222 OnResult) |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 311 |
312 ui::SelectFileDialog* ChromeSelectFileDialogFactory::Create( | 312 ui::SelectFileDialog* ChromeSelectFileDialogFactory::Create( |
313 ui::SelectFileDialog::Listener* listener, | 313 ui::SelectFileDialog::Listener* listener, |
314 ui::SelectFilePolicy* policy) { | 314 ui::SelectFilePolicy* policy) { |
315 return ui::CreateWinSelectFileDialog( | 315 return ui::CreateWinSelectFileDialog( |
316 listener, | 316 listener, |
317 policy, | 317 policy, |
318 base::Bind(GetOpenFileNameImpl, blocking_task_runner_), | 318 base::Bind(GetOpenFileNameImpl, blocking_task_runner_), |
319 base::Bind(GetSaveFileNameImpl, blocking_task_runner_)); | 319 base::Bind(GetSaveFileNameImpl, blocking_task_runner_)); |
320 } | 320 } |
OLD | NEW |