| 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_file_syste
m.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_file_syste
m.h" |
| 6 | 6 |
| 7 #include <sys/statvfs.h> | 7 #include <sys/statvfs.h> |
| 8 | 8 |
| 9 #include "base/posix/eintr_wrapper.h" | 9 #include "base/posix/eintr_wrapper.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 #include "webkit/common/fileapi/file_system_util.h" | 38 #include "webkit/common/fileapi/file_system_util.h" |
| 39 | 39 |
| 40 using chromeos::disks::DiskMountManager; | 40 using chromeos::disks::DiskMountManager; |
| 41 using content::BrowserThread; | 41 using content::BrowserThread; |
| 42 using content::ChildProcessSecurityPolicy; | 42 using content::ChildProcessSecurityPolicy; |
| 43 using fileapi::FileSystemURL; | 43 using fileapi::FileSystemURL; |
| 44 | 44 |
| 45 namespace extensions { | 45 namespace extensions { |
| 46 namespace { | 46 namespace { |
| 47 | 47 |
| 48 // Sets permissions for the Drive mount point so Files.app can access files | |
| 49 // in the mount point directory. It's safe to call this function even if | |
| 50 // Drive is disabled by the setting (i.e. prefs::kDisableDrive is true). | |
| 51 void SetDriveMountPointPermissions( | |
| 52 Profile* profile, | |
| 53 const std::string& extension_id, | |
| 54 content::RenderViewHost* render_view_host) { | |
| 55 if (!render_view_host || | |
| 56 !render_view_host->GetSiteInstance() || !render_view_host->GetProcess()) { | |
| 57 return; | |
| 58 } | |
| 59 | |
| 60 fileapi::ExternalFileSystemBackend* backend = | |
| 61 file_manager::util::GetFileSystemContextForRenderViewHost( | |
| 62 profile, render_view_host)->external_backend(); | |
| 63 if (!backend) | |
| 64 return; | |
| 65 | |
| 66 const base::FilePath mount_point = | |
| 67 drive::util::GetDriveMountPointPath(profile); | |
| 68 // Grant R/W permissions to drive 'folder'. File API layer still | |
| 69 // expects this to be satisfied. | |
| 70 ChildProcessSecurityPolicy::GetInstance()->GrantCreateReadWriteFile( | |
| 71 render_view_host->GetProcess()->GetID(), mount_point); | |
| 72 | |
| 73 base::FilePath mount_point_virtual; | |
| 74 if (backend->GetVirtualPath(mount_point, &mount_point_virtual)) | |
| 75 backend->GrantFileAccessToExtension(extension_id, mount_point_virtual); | |
| 76 } | |
| 77 | |
| 78 // Retrieves total and remaining available size on |mount_path|. | 48 // Retrieves total and remaining available size on |mount_path|. |
| 79 void GetSizeStatsOnBlockingPool(const std::string& mount_path, | 49 void GetSizeStatsOnBlockingPool(const std::string& mount_path, |
| 80 uint64* total_size, | 50 uint64* total_size, |
| 81 uint64* remaining_size) { | 51 uint64* remaining_size) { |
| 82 struct statvfs stat = {}; // Zero-clear | 52 struct statvfs stat = {}; // Zero-clear |
| 83 if (HANDLE_EINTR(statvfs(mount_path.c_str(), &stat)) == 0) { | 53 if (HANDLE_EINTR(statvfs(mount_path.c_str(), &stat)) == 0) { |
| 84 *total_size = static_cast<uint64>(stat.f_blocks) * stat.f_frsize; | 54 *total_size = static_cast<uint64>(stat.f_blocks) * stat.f_frsize; |
| 85 *remaining_size = static_cast<uint64>(stat.f_bavail) * stat.f_frsize; | 55 *remaining_size = static_cast<uint64>(stat.f_bavail) * stat.f_frsize; |
| 86 } | 56 } |
| 87 } | 57 } |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 return false; | 268 return false; |
| 299 } | 269 } |
| 300 | 270 |
| 301 // Set permissions for the Drive mount point immediately when we kick of | 271 // Set permissions for the Drive mount point immediately when we kick of |
| 302 // first instance of file manager. The actual mount event will be sent to | 272 // first instance of file manager. The actual mount event will be sent to |
| 303 // UI only when we perform proper authentication. | 273 // UI only when we perform proper authentication. |
| 304 // | 274 // |
| 305 // Note that we call this function even when Drive is disabled by the | 275 // Note that we call this function even when Drive is disabled by the |
| 306 // setting. Otherwise, we need to call this when the setting is changed at | 276 // setting. Otherwise, we need to call this when the setting is changed at |
| 307 // a later time, which complicates the code. | 277 // a later time, which complicates the code. |
| 308 SetDriveMountPointPermissions( | 278 ChildProcessSecurityPolicy::GetInstance()->GrantCreateReadWriteFile( |
| 309 GetProfile(), extension_id(), render_view_host()); | 279 render_view_host()->GetProcess()->GetID(), |
| 280 drive::util::GetDriveMountPointPath(GetProfile())); |
| 310 | 281 |
| 311 fileapi::FileSystemInfo info = | 282 fileapi::FileSystemInfo info = |
| 312 fileapi::GetFileSystemInfoForChromeOS(source_url_.GetOrigin()); | 283 fileapi::GetFileSystemInfoForChromeOS(source_url_.GetOrigin()); |
| 313 | 284 |
| 314 base::DictionaryValue* dict = new base::DictionaryValue(); | 285 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 315 SetResult(dict); | 286 SetResult(dict); |
| 316 dict->SetString("name", info.name); | 287 dict->SetString("name", info.name); |
| 317 dict->SetString("root_url", info.root_url.spec()); | 288 dict->SetString("root_url", info.root_url.spec()); |
| 318 dict->SetInteger("error", drive::FILE_ERROR_OK); | 289 dict->SetInteger("error", drive::FILE_ERROR_OK); |
| 319 SendResponse(true); | 290 SendResponse(true); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 // We don't much take care about the result of cancellation. | 545 // We don't much take care about the result of cancellation. |
| 575 BrowserThread::PostTask( | 546 BrowserThread::PostTask( |
| 576 BrowserThread::IO, | 547 BrowserThread::IO, |
| 577 FROM_HERE, | 548 FROM_HERE, |
| 578 base::Bind(&CancelCopyOnIOThread, file_system_context, params->copy_id)); | 549 base::Bind(&CancelCopyOnIOThread, file_system_context, params->copy_id)); |
| 579 SendResponse(true); | 550 SendResponse(true); |
| 580 return true; | 551 return true; |
| 581 } | 552 } |
| 582 | 553 |
| 583 } // namespace extensions | 554 } // namespace extensions |
| OLD | NEW |