blob: 43f63c1bcde59ca5c3f8877682d6ba962ee6cb04 [file] [log] [blame]
asanka655d1112015-03-07 05:33:411// 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
Sebastien Marchandf1349f52019-01-25 03:16:417#include "base/bind.h"
asanka655d1112015-03-07 05:33:418#include "base/files/file.h"
9#include "base/files/file_util.h"
10#include "base/logging.h"
Gabriel Charette44db1422018-08-06 11:19:3311#include "base/task/post_task.h"
asanka655d1112015-03-07 05:33:4112#include "chrome/browser/platform_util_internal.h"
Eric Seckler8652dcd52018-09-20 10:42:2813#include "content/public/browser/browser_task_traits.h"
asanka655d1112015-03-07 05:33:4114#include "content/public/browser/browser_thread.h"
15
16using content::BrowserThread;
17
18namespace platform_util {
19
20namespace {
21
22bool shell_operations_allowed = true;
23
24void VerifyAndOpenItemOnBlockingThread(const base::FilePath& path,
25 OpenItemType type,
26 const OpenOperationCallback& callback) {
27 base::File target_item(path, base::File::FLAG_OPEN | base::File::FLAG_READ);
28 if (!base::PathExists(path)) {
29 if (!callback.is_null())
Eric Seckler8652dcd52018-09-20 10:42:2830 base::PostTaskWithTraits(
31 FROM_HERE, {BrowserThread::UI},
tzik3f7781d2017-04-20 17:09:3332 base::BindOnce(callback, OPEN_FAILED_PATH_NOT_FOUND));
asanka655d1112015-03-07 05:33:4133 return;
34 }
35 if (base::DirectoryExists(path) != (type == OPEN_FOLDER)) {
36 if (!callback.is_null())
Eric Seckler8652dcd52018-09-20 10:42:2837 base::PostTaskWithTraits(
38 FROM_HERE, {BrowserThread::UI},
tzik3f7781d2017-04-20 17:09:3339 base::BindOnce(callback, OPEN_FAILED_INVALID_TYPE));
asanka655d1112015-03-07 05:33:4140 return;
41 }
42
43 if (shell_operations_allowed)
44 internal::PlatformOpenVerifiedItem(path, type);
45 if (!callback.is_null())
Eric Seckler8652dcd52018-09-20 10:42:2846 base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI},
47 base::BindOnce(callback, OPEN_SUCCEEDED));
asanka655d1112015-03-07 05:33:4148}
49
50} // namespace
51
52namespace internal {
53
54void DisableShellOperationsForTesting() {
55 shell_operations_allowed = false;
56}
57
58} // namespace internal
59
60void OpenItem(Profile* profile,
61 const base::FilePath& full_path,
62 OpenItemType item_type,
63 const OpenOperationCallback& callback) {
64 DCHECK_CURRENTLY_ON(BrowserThread::UI);
fdoray46e31b52017-02-07 15:59:3765 base::PostTaskWithTraits(FROM_HERE,
Gabriel Charetteb10aeebc2018-07-26 20:15:0066 {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
tzik3f7781d2017-04-20 17:09:3367 base::BindOnce(&VerifyAndOpenItemOnBlockingThread,
68 full_path, item_type, callback));
asanka655d1112015-03-07 05:33:4169}
70
Ivan Sandrkc8e238b62019-03-18 15:00:0271bool IsBrowserLockedFullscreen(const Browser* browser) {
72 return false;
73}
74
asanka655d1112015-03-07 05:33:4175} // namespace platform_util