[M85 Dev][EFL] Fix errors to generate ninja files
[platform/framework/web/chromium-efl.git] / chrome / browser / platform_util.cc
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/bind.h"
8 #include "base/check_op.h"
9 #include "base/files/file.h"
10 #include "base/files/file_util.h"
11 #include "base/task/thread_pool.h"
12 #include "chrome/browser/platform_util_internal.h"
13 #include "content/public/browser/browser_task_traits.h"
14 #include "content/public/browser/browser_thread.h"
15
16 using content::BrowserThread;
17
18 namespace platform_util {
19
20 namespace {
21
22 bool shell_operations_allowed = true;
23
24 void 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())
30       content::GetUIThreadTaskRunner({})->PostTask(
31           FROM_HERE, base::BindOnce(callback, OPEN_FAILED_PATH_NOT_FOUND));
32     return;
33   }
34   if (base::DirectoryExists(path) != (type == OPEN_FOLDER)) {
35     if (!callback.is_null())
36       content::GetUIThreadTaskRunner({})->PostTask(
37           FROM_HERE, base::BindOnce(callback, OPEN_FAILED_INVALID_TYPE));
38     return;
39   }
40
41   if (shell_operations_allowed)
42     internal::PlatformOpenVerifiedItem(path, type);
43   if (!callback.is_null())
44     content::GetUIThreadTaskRunner({})->PostTask(
45         FROM_HERE, base::BindOnce(callback, OPEN_SUCCEEDED));
46 }
47
48 }  // namespace
49
50 namespace internal {
51
52 void DisableShellOperationsForTesting() {
53   shell_operations_allowed = false;
54 }
55
56 }  // namespace internal
57
58 void OpenItem(Profile* profile,
59               const base::FilePath& full_path,
60               OpenItemType item_type,
61               const OpenOperationCallback& callback) {
62   DCHECK_CURRENTLY_ON(BrowserThread::UI);
63   // TaskPriority::USER_BLOCKING because this is usually opened as a result of a
64   // user action (e.g. open-downloaded-file or show-item-in-folder).
65   // TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN because this doesn't need global
66   // state and can hang shutdown without this trait as it may result in an
67   // interactive dialog.
68   base::ThreadPool::PostTask(
69       FROM_HERE,
70       {base::MayBlock(), base::TaskPriority::USER_BLOCKING,
71        base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
72       base::BindOnce(&VerifyAndOpenItemOnBlockingThread, full_path, item_type,
73                      callback));
74 }
75
76 bool IsBrowserLockedFullscreen(const Browser* browser) {
77   return false;
78 }
79
80 }  // namespace platform_util