OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chromeos/extensions/file_manager/private_api_mount.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_mount.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/task_scheduler/post_task.h" |
13 #include "chrome/browser/chromeos/drive/file_system_util.h" | 14 #include "chrome/browser/chromeos/drive/file_system_util.h" |
14 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" | 15 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" |
15 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" | 16 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
16 #include "chrome/browser/chromeos/file_manager/volume_manager.h" | 17 #include "chrome/browser/chromeos/file_manager/volume_manager.h" |
17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/common/extensions/api/file_manager_private.h" | 19 #include "chrome/common/extensions/api/file_manager_private.h" |
19 #include "chromeos/disks/disk_mount_manager.h" | 20 #include "chromeos/disks/disk_mount_manager.h" |
20 #include "components/drive/chromeos/file_system_interface.h" | 21 #include "components/drive/chromeos/file_system_interface.h" |
21 #include "components/drive/event_logger.h" | 22 #include "components/drive/event_logger.h" |
22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
23 #include "google_apis/drive/task_util.h" | 24 #include "google_apis/drive/task_util.h" |
24 #include "ui/shell_dialogs/selected_file_info.h" | 25 #include "ui/shell_dialogs/selected_file_info.h" |
25 | 26 |
26 using chromeos::disks::DiskMountManager; | 27 using chromeos::disks::DiskMountManager; |
27 using content::BrowserThread; | 28 using content::BrowserThread; |
28 namespace file_manager_private = extensions::api::file_manager_private; | 29 namespace file_manager_private = extensions::api::file_manager_private; |
29 | 30 |
30 namespace extensions { | 31 namespace extensions { |
31 | 32 |
32 namespace { | 33 namespace { |
33 | 34 |
34 // Does chmod o+r for the given path to ensure the file is readable from avfs. | 35 // Does chmod o+r for the given path to ensure the file is readable from avfs. |
35 void EnsureReadableFilePermissionOnBlockingPool( | 36 void EnsureReadableFilePermissionAsync( |
36 const base::FilePath& path, | 37 const base::FilePath& path, |
37 const base::Callback<void(drive::FileError, const base::FilePath&)>& | 38 const base::Callback<void(drive::FileError, const base::FilePath&)>& |
38 callback) { | 39 callback) { |
39 int mode = 0; | 40 int mode = 0; |
40 if (!base::GetPosixFilePermissions(path, &mode) || | 41 if (!base::GetPosixFilePermissions(path, &mode) || |
41 !base::SetPosixFilePermissions(path, mode | S_IROTH)) { | 42 !base::SetPosixFilePermissions(path, mode | S_IROTH)) { |
42 callback.Run(drive::FILE_ERROR_ACCESS_DENIED, base::FilePath()); | 43 callback.Run(drive::FILE_ERROR_ACCESS_DENIED, base::FilePath()); |
43 return; | 44 return; |
44 } | 45 } |
45 callback.Run(drive::FILE_ERROR_OK, path); | 46 callback.Run(drive::FILE_ERROR_OK, path); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 if (volume->type() == file_manager::VOLUME_TYPE_DOWNLOADS_DIRECTORY && | 93 if (volume->type() == file_manager::VOLUME_TYPE_DOWNLOADS_DIRECTORY && |
93 volume->mount_path().IsParent(path)) { | 94 volume->mount_path().IsParent(path)) { |
94 is_under_downloads = true; | 95 is_under_downloads = true; |
95 break; | 96 break; |
96 } | 97 } |
97 } | 98 } |
98 | 99 |
99 if (is_under_downloads) { | 100 if (is_under_downloads) { |
100 // For files under downloads, change the file permission and make it | 101 // For files under downloads, change the file permission and make it |
101 // readable from avfs/fuse if needed. | 102 // readable from avfs/fuse if needed. |
102 BrowserThread::PostBlockingPoolTask( | 103 base::PostTaskWithTraits( |
103 FROM_HERE, | 104 FROM_HERE, base::TaskTraits().MayBlock().WithPriority( |
104 base::Bind(&EnsureReadableFilePermissionOnBlockingPool, | 105 base::TaskPriority::USER_BLOCKING), |
105 path, | 106 base::Bind(&EnsureReadableFilePermissionAsync, path, |
106 google_apis::CreateRelayCallback( | 107 google_apis::CreateRelayCallback( |
107 base::Bind(&FileManagerPrivateAddMountFunction:: | 108 base::Bind(&FileManagerPrivateAddMountFunction:: |
108 RunAfterMarkCacheFileAsMounted, | 109 RunAfterMarkCacheFileAsMounted, |
109 this, | 110 this, path.BaseName())))); |
110 path.BaseName())))); | |
111 } else { | 111 } else { |
112 RunAfterMarkCacheFileAsMounted( | 112 RunAfterMarkCacheFileAsMounted( |
113 path.BaseName(), drive::FILE_ERROR_OK, path); | 113 path.BaseName(), drive::FILE_ERROR_OK, path); |
114 } | 114 } |
115 } | 115 } |
116 return true; | 116 return true; |
117 } | 117 } |
118 | 118 |
119 void FileManagerPrivateAddMountFunction::RunAfterGetDriveFile( | 119 void FileManagerPrivateAddMountFunction::RunAfterGetDriveFile( |
120 const base::FilePath& drive_path, | 120 const base::FilePath& drive_path, |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 name(), request_id(), log_string.c_str(), result.size()); | 246 name(), request_id(), log_string.c_str(), result.size()); |
247 } | 247 } |
248 | 248 |
249 results_ = | 249 results_ = |
250 file_manager_private::GetVolumeMetadataList::Results::Create(result); | 250 file_manager_private::GetVolumeMetadataList::Results::Create(result); |
251 SendResponse(true); | 251 SendResponse(true); |
252 return true; | 252 return true; |
253 } | 253 } |
254 | 254 |
255 } // namespace extensions | 255 } // namespace extensions |
OLD | NEW |