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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/private_api_mount.cc

Issue 323783002: Files.app: Explicitly add o+r permission to mounted zip archives under Downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/file_util.h"
9 #include "base/format_macros.h" 10 #include "base/format_macros.h"
10 #include "chrome/browser/chromeos/drive/file_system_interface.h" 11 #include "chrome/browser/chromeos/drive/file_system_interface.h"
11 #include "chrome/browser/chromeos/drive/file_system_util.h" 12 #include "chrome/browser/chromeos/drive/file_system_util.h"
12 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" 13 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h"
13 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" 14 #include "chrome/browser/chromeos/file_manager/fileapi_util.h"
14 #include "chrome/browser/chromeos/file_manager/volume_manager.h" 15 #include "chrome/browser/chromeos/file_manager/volume_manager.h"
15 #include "chrome/browser/drive/event_logger.h" 16 #include "chrome/browser/drive/event_logger.h"
16 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/extensions/api/file_browser_private.h" 18 #include "chrome/common/extensions/api/file_browser_private.h"
18 #include "chromeos/disks/disk_mount_manager.h" 19 #include "chromeos/disks/disk_mount_manager.h"
19 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 #include "google_apis/drive/task_util.h"
20 #include "ui/shell_dialogs/selected_file_info.h" 22 #include "ui/shell_dialogs/selected_file_info.h"
21 23
22 using chromeos::disks::DiskMountManager; 24 using chromeos::disks::DiskMountManager;
23 using content::BrowserThread; 25 using content::BrowserThread;
24 namespace file_browser_private = extensions::api::file_browser_private; 26 namespace file_browser_private = extensions::api::file_browser_private;
25 27
26 namespace extensions { 28 namespace extensions {
27 29
30 namespace {
31
32 // Does chmod o+r for the given path to ensure the file is readable from avfs.
33 void EnsureReadableFilePermissionOnBlockingPool(
34 const base::FilePath& path,
35 const base::Callback<void(drive::FileError, const base::FilePath&)>&
36 callback) {
37 int mode = 0;
38 if (!base::GetPosixFilePermissions(path, &mode) ||
39 !base::SetPosixFilePermissions(path, mode | S_IROTH)) {
40 callback.Run(drive::FILE_ERROR_ACCESS_DENIED, base::FilePath());
41 return;
42 }
43 callback.Run(drive::FILE_ERROR_OK, path);
44 }
45
46 } // namespace
47
28 bool FileBrowserPrivateAddMountFunction::RunAsync() { 48 bool FileBrowserPrivateAddMountFunction::RunAsync() {
29 using file_browser_private::AddMount::Params; 49 using file_browser_private::AddMount::Params;
30 const scoped_ptr<Params> params(Params::Create(*args_)); 50 const scoped_ptr<Params> params(Params::Create(*args_));
31 EXTENSION_FUNCTION_VALIDATE(params); 51 EXTENSION_FUNCTION_VALIDATE(params);
32 52
33 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile()); 53 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile());
34 if (logger) { 54 if (logger) {
35 logger->Log(logging::LOG_INFO, 55 logger->Log(logging::LOG_INFO,
36 "%s[%d] called. (source: '%s')", 56 "%s[%d] called. (source: '%s')",
37 name().c_str(), 57 name().c_str(),
(...skipping 14 matching lines...) Expand all
52 drive::util::GetFileSystemByProfile(GetProfile()); 72 drive::util::GetFileSystemByProfile(GetProfile());
53 if (!file_system) 73 if (!file_system)
54 return false; 74 return false;
55 75
56 file_system->MarkCacheFileAsMounted( 76 file_system->MarkCacheFileAsMounted(
57 drive::util::ExtractDrivePath(path), 77 drive::util::ExtractDrivePath(path),
58 base::Bind( 78 base::Bind(
59 &FileBrowserPrivateAddMountFunction::RunAfterMarkCacheFileAsMounted, 79 &FileBrowserPrivateAddMountFunction::RunAfterMarkCacheFileAsMounted,
60 this, path.BaseName())); 80 this, path.BaseName()));
61 } else { 81 } else {
62 RunAfterMarkCacheFileAsMounted( 82 file_manager::VolumeManager* volume_manager =
63 path.BaseName(), drive::FILE_ERROR_OK, path); 83 file_manager::VolumeManager::Get(GetProfile());
84 DCHECK(volume_manager);
85
86 bool is_under_downloads = false;
87 const std::vector<file_manager::VolumeInfo> volumes =
88 volume_manager->GetVolumeInfoList();
89 for (size_t i = 0; i < volumes.size(); ++i) {
90 if (volumes[i].type == file_manager::VOLUME_TYPE_DOWNLOADS_DIRECTORY &&
91 volumes[i].mount_path.IsParent(path)) {
92 is_under_downloads = true;
93 break;
94 }
95 }
96
97 if (is_under_downloads) {
98 // For files under downloads, change the file permission and make it
99 // readable from avfs/fuse if needed.
100 BrowserThread::PostBlockingPoolTask(
101 FROM_HERE,
102 base::Bind(&EnsureReadableFilePermissionOnBlockingPool,
103 path,
104 google_apis::CreateRelayCallback(
105 base::Bind(&FileBrowserPrivateAddMountFunction::
106 RunAfterMarkCacheFileAsMounted,
107 this,
108 path.BaseName()))));
109 } else {
110 RunAfterMarkCacheFileAsMounted(
111 path.BaseName(), drive::FILE_ERROR_OK, path);
112 }
64 } 113 }
65 return true; 114 return true;
66 } 115 }
67 116
68 void FileBrowserPrivateAddMountFunction::RunAfterMarkCacheFileAsMounted( 117 void FileBrowserPrivateAddMountFunction::RunAfterMarkCacheFileAsMounted(
69 const base::FilePath& display_name, 118 const base::FilePath& display_name,
70 drive::FileError error, 119 drive::FileError error,
71 const base::FilePath& file_path) { 120 const base::FilePath& file_path) {
72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
73 122
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 result.size()); 222 result.size());
174 } 223 }
175 224
176 results_ = 225 results_ =
177 file_browser_private::GetVolumeMetadataList::Results::Create(result); 226 file_browser_private::GetVolumeMetadataList::Results::Create(result);
178 SendResponse(true); 227 SendResponse(true);
179 return true; 228 return true;
180 } 229 }
181 230
182 } // namespace extensions 231 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698