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

Side by Side Diff: chrome/utility/shell_handler_impl_win.cc

Issue 2122303002: Revive experiment to isolate shell operations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/utility/shell_handler_impl_win.h" 5 #include "chrome/utility/shell_handler_impl_win.h"
6 6
7 #include <shldisp.h> 7 #include <shldisp.h>
8 8
9 #include "base/files/file_enumerator.h" 9 #include "base/files/file_enumerator.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/scoped_native_library.h" 12 #include "base/scoped_native_library.h"
13 #include "base/win/scoped_bstr.h" 13 #include "base/win/scoped_bstr.h"
14 #include "base/win/scoped_com_initializer.h" 14 #include "base/win/scoped_com_initializer.h"
15 #include "base/win/scoped_comptr.h" 15 #include "base/win/scoped_comptr.h"
16 #include "base/win/scoped_variant.h" 16 #include "base/win/scoped_variant.h"
17 #include "base/win/shortcut.h" 17 #include "base/win/shortcut.h"
18 #include "chrome/installer/util/install_util.h" 18 #include "chrome/installer/util/install_util.h"
19 #include "content/public/utility/utility_thread.h" 19 #include "content/public/utility/utility_thread.h"
20 #include "ui/base/win/open_file_name_win.h"
20 21
21 namespace { 22 namespace {
22 23
23 // This class checks if the current executable is pinned to the taskbar. It also 24 // This class checks if the current executable is pinned to the taskbar. It also
24 // keeps track of the errors that occurs that prevents it from getting a result. 25 // keeps track of the errors that occurs that prevents it from getting a result.
25 class IsPinnedToTaskbarHelper { 26 class IsPinnedToTaskbarHelper {
26 public: 27 public:
27 IsPinnedToTaskbarHelper() = default; 28 IsPinnedToTaskbarHelper() = default;
28 29
29 // Returns true if the current executable is pinned to the taskbar. 30 // Returns true if the current executable is pinned to the taskbar.
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 : binding_(this, std::move(request)) {} 216 : binding_(this, std::move(request)) {}
216 217
217 ShellHandlerImpl::~ShellHandlerImpl() = default; 218 ShellHandlerImpl::~ShellHandlerImpl() = default;
218 219
219 void ShellHandlerImpl::IsPinnedToTaskbar( 220 void ShellHandlerImpl::IsPinnedToTaskbar(
220 const IsPinnedToTaskbarCallback& callback) { 221 const IsPinnedToTaskbarCallback& callback) {
221 IsPinnedToTaskbarHelper helper; 222 IsPinnedToTaskbarHelper helper;
222 bool is_pinned_to_taskbar = helper.GetResult(); 223 bool is_pinned_to_taskbar = helper.GetResult();
223 callback.Run(!helper.error_occured(), is_pinned_to_taskbar); 224 callback.Run(!helper.error_occured(), is_pinned_to_taskbar);
224 } 225 }
226
227 void ShellHandlerImpl::DoGetOpenFileName(
228 uint64_t owner,
229 uint32_t flags,
230 const std::vector<std::tuple<base::string16, base::string16>>& filters,
231 const base::FilePath& initial_directory,
232 const base::FilePath& filename,
233 const DoGetOpenFileNameCallback& callback) {
234 ui::win::OpenFileName open_file_name(reinterpret_cast<HWND>(owner), flags);
235 open_file_name.SetInitialSelection(initial_directory, filename);
236 open_file_name.SetFilters(filters);
237
238 base::FilePath directory;
239 std::vector<base::FilePath> filenames;
240
241 if (::GetOpenFileName(open_file_name.GetOPENFILENAME()))
242 open_file_name.GetResult(&directory, &filenames);
243
244 if (filenames.size()) {
sky 2016/07/08 15:28:21 nit: no {}, also !empty()
Patrick Monette 2016/07/08 19:36:10 Done.
245 callback.Run(directory, filenames);
246 } else {
247 callback.Run(base::FilePath(), std::vector<base::FilePath>());
248 }
249 }
250
251 void ShellHandlerImpl::DoGetSaveFileName(
252 uint64_t owner,
253 uint32_t flags,
254 const std::vector<std::tuple<base::string16, base::string16>>& filters,
255 uint32_t one_based_filter_index,
256 const base::FilePath& initial_directory,
257 const base::FilePath& suggested_filename,
258 const base::FilePath& default_extension,
259 const DoGetSaveFileNameCallback& callback) {
260 ui::win::OpenFileName open_file_name(reinterpret_cast<HWND>(owner), flags);
261 open_file_name.SetInitialSelection(initial_directory, suggested_filename);
262 open_file_name.SetFilters(filters);
263 open_file_name.GetOPENFILENAME()->nFilterIndex = one_based_filter_index;
264 open_file_name.GetOPENFILENAME()->lpstrDefExt =
265 default_extension.value().c_str();
266
267 if (::GetSaveFileName(open_file_name.GetOPENFILENAME())) {
268 callback.Run(base::FilePath(open_file_name.GetOPENFILENAME()->lpstrFile),
269 open_file_name.GetOPENFILENAME()->nFilterIndex);
270 return;
271 }
272
273 // Zero means the dialog was closed, otherwise we had an error.
274 DWORD error_code = ::CommDlgExtendedError();
275 if (error_code != 0)
276 NOTREACHED() << "GetSaveFileName failed with code: " << error_code;
277
278 callback.Run(base::FilePath(), 0);
279 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698