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

Side by Side Diff: chrome/browser/extensions/api/file_handlers/directory_util.cc

Issue 2666763005: API delegate for non-native file systems (Closed)
Patch Set: rebase Created 3 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/extensions/api/file_handlers/directory_util.h" 5 #include "chrome/browser/extensions/api/file_handlers/directory_util.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "net/base/filename_util.h" 12 #include "net/base/filename_util.h"
13 #include "storage/browser/fileapi/file_system_url.h" 13 #include "storage/browser/fileapi/file_system_url.h"
14 14
15 #if defined(OS_CHROMEOS) 15 #if defined(OS_CHROMEOS)
16 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h" 16 #include "extensions/browser/api/extensions_api_client.h"
17 #include "extensions/browser/api/file_handlers/non_native_file_system_delegate.h "
17 #endif 18 #endif
18 19
19 namespace extensions { 20 namespace extensions {
20 namespace app_file_handler_util { 21 namespace app_file_handler_util {
21 22
22 namespace { 23 namespace {
23 24
24 void GetIsDirectoryFromFileInfo(const base::FilePath& path, 25 void GetIsDirectoryFromFileInfo(const base::FilePath& path,
25 bool* is_directory) { 26 bool* is_directory) {
26 base::File::Info file_info; 27 base::File::Info file_info;
27 *is_directory = GetFileInfo(path, &file_info) && file_info.is_directory; 28 *is_directory = GetFileInfo(path, &file_info) && file_info.is_directory;
28 } 29 }
29 30
30 void OnGetIsDirectoryFromFileInfoCompleted( 31 void OnGetIsDirectoryFromFileInfoCompleted(
31 std::unique_ptr<bool> is_directory, 32 std::unique_ptr<bool> is_directory,
32 const base::Callback<void(bool)>& callback) { 33 const base::Callback<void(bool)>& callback) {
33 callback.Run(*is_directory); 34 callback.Run(*is_directory);
34 } 35 }
35 36
36 // The callback parameter contains the result and is required to support 37 // The callback parameter contains the result and is required to support
37 // both native local directories to avoid UI thread and non native local 38 // both native local directories to avoid UI thread and non native local
38 // path directories for the IsNonNativeLocalPathDirectory API. 39 // path directories for the IsNonNativeLocalPathDirectory API.
39 void EntryIsDirectory(Profile* profile, 40 void EntryIsDirectory(Profile* profile,
40 const base::FilePath& path, 41 const base::FilePath& path,
41 const base::Callback<void(bool)>& callback) { 42 const base::Callback<void(bool)>& callback) {
42 #if defined(OS_CHROMEOS) 43 #if defined(OS_CHROMEOS)
43 if (file_manager::util::IsUnderNonNativeLocalPath(profile, path)) { 44 NonNativeFileSystemDelegate* delegate =
44 file_manager::util::IsNonNativeLocalPathDirectory(profile, path, callback); 45 ExtensionsAPIClient::Get()->GetNonNativeFileSystemDelegate();
46 if (delegate && delegate->IsUnderNonNativeLocalPath(profile, path)) {
47 delegate->IsNonNativeLocalPathDirectory(profile, path, callback);
45 return; 48 return;
46 } 49 }
47 #endif 50 #endif
48 51
49 std::unique_ptr<bool> is_directory(new bool); 52 std::unique_ptr<bool> is_directory(new bool);
50 bool* const is_directory_ptr = is_directory.get(); 53 bool* const is_directory_ptr = is_directory.get();
51 54
52 content::BrowserThread::PostBlockingPoolTaskAndReply( 55 content::BrowserThread::PostBlockingPoolTaskAndReply(
53 FROM_HERE, 56 FROM_HERE,
54 base::Bind(&GetIsDirectoryFromFileInfo, path, is_directory_ptr), 57 base::Bind(&GetIsDirectoryFromFileInfo, path, is_directory_ptr),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 FROM_HERE, base::Bind(callback_, base::Passed(&result_))); 101 FROM_HERE, base::Bind(callback_, base::Passed(&result_)));
99 // Release the callback to avoid a circullar reference in case an instance 102 // Release the callback to avoid a circullar reference in case an instance
100 // of this class is a member of a ref counted class, which instance is bound 103 // of this class is a member of a ref counted class, which instance is bound
101 // to this callback. 104 // to this callback.
102 callback_ = CompletionCallback(); 105 callback_ = CompletionCallback();
103 } 106 }
104 } 107 }
105 108
106 } // namespace app_file_handler_util 109 } // namespace app_file_handler_util
107 } // namespace extensions 110 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698