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

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

Issue 352393002: Be explicit about target type in platform_util::OpenItem() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 5 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/platform_util.h"
6
7 #include "base/files/file_util.h"
8 #include "base/logging.h"
9 #include "chrome/browser/platform_util_internal.h"
10 #include "content/public/browser/browser_thread.h"
11
12 using content::BrowserThread;
13
14 namespace platform_util {
15
16 namespace {
17
18 bool shell_operations_allowed = true;
19
20 void VerifyAndOpenItemOnBlockingThread(const base::FilePath& path,
21 internal::OpenItemType type,
22 const OpenOperationCallback& callback) {
23 if (!base::PathExists(path)) {
24 if (!callback.is_null())
25 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
26 base::Bind(callback, OPEN_FAILED_PATH_NOT_FOUND));
27 return;
28 }
29 if (base::DirectoryExists(path) != (type == internal::OPEN_FOLDER)) {
30 if (!callback.is_null())
31 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
32 base::Bind(callback, OPEN_FAILED_INVALID_TYPE));
33 return;
34 }
35
36 if (shell_operations_allowed)
37 internal::PlatformOpenVerifiedItem(path, type);
38 if (!callback.is_null())
39 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
40 base::Bind(callback, OPEN_SUCCEEDED));
41 }
42
43 } // namespace
44
45 namespace internal {
46
47 void DisableShellOperationsForTesting() {
48 shell_operations_allowed = false;
49 }
50 }
51
52 void OpenFile(Profile* profile,
53 const base::FilePath& full_path,
54 const OpenOperationCallback& callback) {
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
56 BrowserThread::PostBlockingPoolTask(
57 FROM_HERE, base::Bind(&VerifyAndOpenItemOnBlockingThread, full_path,
58 internal::OPEN_FILE, callback));
59 }
60
61 void OpenFolder(Profile* profile,
62 const base::FilePath& full_path,
63 const OpenOperationCallback& callback) {
64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
65 BrowserThread::PostBlockingPoolTask(
66 FROM_HERE, base::Bind(&VerifyAndOpenItemOnBlockingThread, full_path,
67 internal::OPEN_FOLDER, callback));
68 }
69
70 } // namespace platform_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698