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

Side by Side Diff: chrome/browser/chrome_select_file_dialog_factory_win.cc

Issue 1581473002: Remove base/win/metro.{cc|h} and some associated code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 4 years, 11 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
OLDNEW
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"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/metrics/field_trial.h" 16 #include "base/metrics/field_trial.h"
17 #include "base/strings/string16.h" 17 #include "base/strings/string16.h"
18 #include "base/synchronization/waitable_event.h" 18 #include "base/synchronization/waitable_event.h"
19 #include "base/win/metro.h"
20 #include "chrome/common/chrome_utility_messages.h" 19 #include "chrome/common/chrome_utility_messages.h"
21 #include "chrome/grit/generated_resources.h" 20 #include "chrome/grit/generated_resources.h"
22 #include "content/public/browser/utility_process_host.h" 21 #include "content/public/browser/utility_process_host.h"
23 #include "content/public/browser/utility_process_host_client.h" 22 #include "content/public/browser/utility_process_host_client.h"
24 #include "ipc/ipc_message_macros.h" 23 #include "ipc/ipc_message_macros.h"
25 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/base/win/open_file_name_win.h" 25 #include "ui/base/win/open_file_name_win.h"
27 #include "ui/shell_dialogs/select_file_dialog_win.h" 26 #include "ui/shell_dialogs/select_file_dialog_win.h"
28 27
29 namespace { 28 namespace {
30 29
31 bool CallMetroOPENFILENAMEMethod(const char* method_name, OPENFILENAME* ofn) {
32 typedef BOOL (*MetroOPENFILENAMEMethod)(OPENFILENAME*);
33 MetroOPENFILENAMEMethod metro_method = NULL;
34 HMODULE metro_module = base::win::GetMetroModule();
35
36 if (metro_module != NULL) {
37 metro_method = reinterpret_cast<MetroOPENFILENAMEMethod>(
38 ::GetProcAddress(metro_module, method_name));
39 }
40
41 if (metro_method != NULL)
42 return metro_method(ofn) == TRUE;
43
44 NOTREACHED();
45
46 return false;
47 }
48
49 bool ShouldIsolateShellOperations() { 30 bool ShouldIsolateShellOperations() {
50 return base::FieldTrialList::FindFullName("IsolateShellOperations") == 31 return base::FieldTrialList::FindFullName("IsolateShellOperations") ==
51 "Enabled"; 32 "Enabled";
52 } 33 }
53 34
54 // Receives the GetOpenFileName result from the utility process. 35 // Receives the GetOpenFileName result from the utility process.
55 class GetOpenFileNameClient : public content::UtilityProcessHostClient { 36 class GetOpenFileNameClient : public content::UtilityProcessHostClient {
56 public: 37 public:
57 GetOpenFileNameClient(); 38 GetOpenFileNameClient();
58 39
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 client->WaitForCompletion(); 146 client->WaitForCompletion();
166 147
167 if (!client->filenames().size()) 148 if (!client->filenames().size())
168 return false; 149 return false;
169 150
170 ui::win::OpenFileName::SetResult( 151 ui::win::OpenFileName::SetResult(
171 client->directory(), client->filenames(), ofn); 152 client->directory(), client->filenames(), ofn);
172 return true; 153 return true;
173 } 154 }
174 155
175 // Implements GetOpenFileName for CreateWinSelectFileDialog by delegating either 156 // Implements GetOpenFileName for CreateWinSelectFileDialog by delegating to a
176 // to Metro or a utility process. 157 // utility process.
177 bool GetOpenFileNameImpl( 158 bool GetOpenFileNameImpl(
178 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner, 159 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner,
179 OPENFILENAME* ofn) { 160 OPENFILENAME* ofn) {
180 if (base::win::IsMetroProcess())
181 return CallMetroOPENFILENAMEMethod("MetroGetOpenFileName", ofn);
182
183 if (ShouldIsolateShellOperations()) 161 if (ShouldIsolateShellOperations())
184 return GetOpenFileNameInUtilityProcess(blocking_task_runner, ofn); 162 return GetOpenFileNameInUtilityProcess(blocking_task_runner, ofn);
185 163
186 return ::GetOpenFileName(ofn) == TRUE; 164 return ::GetOpenFileName(ofn) == TRUE;
187 } 165 }
188 166
189 class GetSaveFileNameClient : public content::UtilityProcessHostClient { 167 class GetSaveFileNameClient : public content::UtilityProcessHostClient {
190 public: 168 public:
191 GetSaveFileNameClient(); 169 GetSaveFileNameClient();
192 170
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 282
305 if (client->path().empty()) 283 if (client->path().empty())
306 return false; 284 return false;
307 285
308 base::wcslcpy(ofn->lpstrFile, client->path().value().c_str(), ofn->nMaxFile); 286 base::wcslcpy(ofn->lpstrFile, client->path().value().c_str(), ofn->nMaxFile);
309 ofn->nFilterIndex = client->one_based_filter_index(); 287 ofn->nFilterIndex = client->one_based_filter_index();
310 288
311 return true; 289 return true;
312 } 290 }
313 291
314 // Implements GetSaveFileName for CreateWinSelectFileDialog by delegating either 292 // Implements GetSaveFileName for CreateWinSelectFileDialog by delegating to a
315 // to Metro or a utility process. 293 // utility process.
316 bool GetSaveFileNameImpl( 294 bool GetSaveFileNameImpl(
317 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner, 295 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner,
318 OPENFILENAME* ofn) { 296 OPENFILENAME* ofn) {
319 if (base::win::IsMetroProcess())
320 return CallMetroOPENFILENAMEMethod("MetroGetSaveFileName", ofn);
321
322 if (ShouldIsolateShellOperations()) 297 if (ShouldIsolateShellOperations())
323 return GetSaveFileNameInUtilityProcess(blocking_task_runner, ofn); 298 return GetSaveFileNameInUtilityProcess(blocking_task_runner, ofn);
324 299
325 return ::GetSaveFileName(ofn) == TRUE; 300 return ::GetSaveFileName(ofn) == TRUE;
326 } 301 }
327 302
328 } // namespace 303 } // namespace
329 304
330 ChromeSelectFileDialogFactory::ChromeSelectFileDialogFactory( 305 ChromeSelectFileDialogFactory::ChromeSelectFileDialogFactory(
331 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) 306 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner)
332 : blocking_task_runner_(blocking_task_runner) { 307 : blocking_task_runner_(blocking_task_runner) {
333 } 308 }
334 309
335 ChromeSelectFileDialogFactory::~ChromeSelectFileDialogFactory() {} 310 ChromeSelectFileDialogFactory::~ChromeSelectFileDialogFactory() {}
336 311
337 ui::SelectFileDialog* ChromeSelectFileDialogFactory::Create( 312 ui::SelectFileDialog* ChromeSelectFileDialogFactory::Create(
338 ui::SelectFileDialog::Listener* listener, 313 ui::SelectFileDialog::Listener* listener,
339 ui::SelectFilePolicy* policy) { 314 ui::SelectFilePolicy* policy) {
340 return ui::CreateWinSelectFileDialog( 315 return ui::CreateWinSelectFileDialog(
341 listener, 316 listener,
342 policy, 317 policy,
343 base::Bind(GetOpenFileNameImpl, blocking_task_runner_), 318 base::Bind(GetOpenFileNameImpl, blocking_task_runner_),
344 base::Bind(GetSaveFileNameImpl, blocking_task_runner_)); 319 base::Bind(GetSaveFileNameImpl, blocking_task_runner_));
345 } 320 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698