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

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

Issue 2828663002: Rewrite base::Bind to base::BindOnce with base_bind_rewriters in //chrome/browser/{i,l,m,n,p,r}* (Closed)
Patch Set: Created 3 years, 8 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 2015 The Chromium Authors. All rights reserved. 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 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/browser/platform_util.h" 5 #include "chrome/browser/platform_util.h"
6 6
7 #include "base/files/file.h" 7 #include "base/files/file.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/task_scheduler/post_task.h" 10 #include "base/task_scheduler/post_task.h"
11 #include "chrome/browser/platform_util_internal.h" 11 #include "chrome/browser/platform_util_internal.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 13
14 using content::BrowserThread; 14 using content::BrowserThread;
15 15
16 namespace platform_util { 16 namespace platform_util {
17 17
18 namespace { 18 namespace {
19 19
20 bool shell_operations_allowed = true; 20 bool shell_operations_allowed = true;
21 21
22 void VerifyAndOpenItemOnBlockingThread(const base::FilePath& path, 22 void VerifyAndOpenItemOnBlockingThread(const base::FilePath& path,
23 OpenItemType type, 23 OpenItemType type,
24 const OpenOperationCallback& callback) { 24 const OpenOperationCallback& callback) {
25 base::File target_item(path, base::File::FLAG_OPEN | base::File::FLAG_READ); 25 base::File target_item(path, base::File::FLAG_OPEN | base::File::FLAG_READ);
26 if (!base::PathExists(path)) { 26 if (!base::PathExists(path)) {
27 if (!callback.is_null()) 27 if (!callback.is_null())
28 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 28 BrowserThread::PostTask(
29 base::Bind(callback, OPEN_FAILED_PATH_NOT_FOUND)); 29 BrowserThread::UI, FROM_HERE,
30 base::BindOnce(callback, OPEN_FAILED_PATH_NOT_FOUND));
30 return; 31 return;
31 } 32 }
32 if (base::DirectoryExists(path) != (type == OPEN_FOLDER)) { 33 if (base::DirectoryExists(path) != (type == OPEN_FOLDER)) {
33 if (!callback.is_null()) 34 if (!callback.is_null())
34 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 35 BrowserThread::PostTask(
35 base::Bind(callback, OPEN_FAILED_INVALID_TYPE)); 36 BrowserThread::UI, FROM_HERE,
37 base::BindOnce(callback, OPEN_FAILED_INVALID_TYPE));
36 return; 38 return;
37 } 39 }
38 40
39 if (shell_operations_allowed) 41 if (shell_operations_allowed)
40 internal::PlatformOpenVerifiedItem(path, type); 42 internal::PlatformOpenVerifiedItem(path, type);
41 if (!callback.is_null()) 43 if (!callback.is_null())
42 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 44 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
43 base::Bind(callback, OPEN_SUCCEEDED)); 45 base::BindOnce(callback, OPEN_SUCCEEDED));
44 } 46 }
45 47
46 } // namespace 48 } // namespace
47 49
48 namespace internal { 50 namespace internal {
49 51
50 void DisableShellOperationsForTesting() { 52 void DisableShellOperationsForTesting() {
51 shell_operations_allowed = false; 53 shell_operations_allowed = false;
52 } 54 }
53 55
54 } // namespace internal 56 } // namespace internal
55 57
56 void OpenItem(Profile* profile, 58 void OpenItem(Profile* profile,
57 const base::FilePath& full_path, 59 const base::FilePath& full_path,
58 OpenItemType item_type, 60 OpenItemType item_type,
59 const OpenOperationCallback& callback) { 61 const OpenOperationCallback& callback) {
60 DCHECK_CURRENTLY_ON(BrowserThread::UI); 62 DCHECK_CURRENTLY_ON(BrowserThread::UI);
61 base::PostTaskWithTraits(FROM_HERE, 63 base::PostTaskWithTraits(FROM_HERE,
62 base::TaskTraits().MayBlock().WithPriority( 64 base::TaskTraits().MayBlock().WithPriority(
63 base::TaskPriority::BACKGROUND), 65 base::TaskPriority::BACKGROUND),
64 base::Bind(&VerifyAndOpenItemOnBlockingThread, 66 base::BindOnce(&VerifyAndOpenItemOnBlockingThread,
65 full_path, item_type, callback)); 67 full_path, item_type, callback));
66 } 68 }
67 69
68 } // namespace platform_util 70 } // namespace platform_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698