OLD | NEW |
---|---|
(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.h" | |
8 #include "base/files/file_util.h" | |
9 #include "base/logging.h" | |
10 #include "chrome/browser/platform_util_internal.h" | |
11 #include "content/public/browser/browser_thread.h" | |
12 | |
13 using content::BrowserThread; | |
14 | |
15 namespace platform_util { | |
16 | |
17 namespace { | |
18 | |
19 bool shell_operations_allowed = true; | |
20 | |
21 void VerifyAndOpenItemOnBlockingThread(const base::FilePath& path, | |
22 OpenItemType type, | |
23 const OpenOperationCallback& callback) { | |
24 base::File target_item(path, base::File::FLAG_OPEN | base::File::FLAG_READ); | |
25 if (!base::PathExists(path)) { | |
26 if (!callback.is_null()) | |
27 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
28 base::Bind(callback, OPEN_FAILED_PATH_NOT_FOUND)); | |
29 return; | |
30 } | |
31 if (base::DirectoryExists(path) != (type == OPEN_FOLDER)) { | |
32 if (!callback.is_null()) | |
33 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
34 base::Bind(callback, OPEN_FAILED_INVALID_TYPE)); | |
35 return; | |
36 } | |
37 | |
38 if (shell_operations_allowed) | |
39 internal::PlatformOpenVerifiedItem(path, type); | |
40 if (!callback.is_null()) | |
41 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
42 base::Bind(callback, OPEN_SUCCEEDED)); | |
43 } | |
44 | |
45 } // namespace | |
46 | |
47 namespace internal { | |
48 | |
49 void DisableShellOperationsForTesting() { | |
50 shell_operations_allowed = false; | |
51 } | |
52 } | |
mtomasz
2015/03/06 07:05:49
nit: // namespace
nit: Add \n in #51 or remove in
asanka
2015/03/06 21:09:40
Done.
| |
53 | |
54 void OpenItem(Profile* profile, | |
55 const base::FilePath& full_path, | |
56 OpenItemType item_type, | |
57 const OpenOperationCallback& callback) { | |
58 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
59 BrowserThread::PostBlockingPoolTask( | |
60 FROM_HERE, base::Bind(&VerifyAndOpenItemOnBlockingThread, full_path, | |
61 item_type, callback)); | |
62 } | |
63 | |
64 } // namespace platform_util | |
OLD | NEW |