| 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/drive/file_system/download_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/download_operation.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 // The file's entry should have its file specific info. | 55 // The file's entry should have its file specific info. |
| 56 DCHECK(entry->has_file_specific_info()); | 56 DCHECK(entry->has_file_specific_info()); |
| 57 | 57 |
| 58 // For a hosted document, we create a special JSON file to represent the | 58 // For a hosted document, we create a special JSON file to represent the |
| 59 // document instead of fetching the document content in one of the exported | 59 // document instead of fetching the document content in one of the exported |
| 60 // formats. The JSON file contains the edit URL and resource ID of the | 60 // formats. The JSON file contains the edit URL and resource ID of the |
| 61 // document. | 61 // document. |
| 62 if (entry->file_specific_info().is_hosted_document()) { | 62 if (entry->file_specific_info().is_hosted_document()) { |
| 63 base::FilePath gdoc_file_path; | 63 base::FilePath gdoc_file_path; |
| 64 base::PlatformFileInfo file_info; | 64 base::PlatformFileInfo file_info; |
| 65 if (!file_util::CreateTemporaryFileInDir(temporary_file_directory, | 65 if (!base::CreateTemporaryFileInDir(temporary_file_directory, |
| 66 &gdoc_file_path) || | 66 &gdoc_file_path) || |
| 67 !util::CreateGDocFile(gdoc_file_path, | 67 !util::CreateGDocFile(gdoc_file_path, |
| 68 GURL(entry->file_specific_info().alternate_url()), | 68 GURL(entry->file_specific_info().alternate_url()), |
| 69 entry->resource_id()) || | 69 entry->resource_id()) || |
| 70 !file_util::GetFileInfo(gdoc_file_path, &file_info)) | 70 !file_util::GetFileInfo(gdoc_file_path, &file_info)) |
| 71 return FILE_ERROR_FAILED; | 71 return FILE_ERROR_FAILED; |
| 72 | 72 |
| 73 *cache_file_path = gdoc_file_path; | 73 *cache_file_path = gdoc_file_path; |
| 74 SetPlatformFileInfoToResourceEntry(file_info, entry); | 74 SetPlatformFileInfoToResourceEntry(file_info, entry); |
| 75 return FILE_ERROR_OK; | 75 return FILE_ERROR_OK; |
| 76 } | 76 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 cache_file_path); | 139 cache_file_path); |
| 140 } | 140 } |
| 141 | 141 |
| 142 // Creates a file with unique name in |dir| and stores the path to |temp_file|. | 142 // Creates a file with unique name in |dir| and stores the path to |temp_file|. |
| 143 // Additionally, sets the permission of the file to allow read access from | 143 // Additionally, sets the permission of the file to allow read access from |
| 144 // others and group member users (i.e, "-rw-r--r--"). | 144 // others and group member users (i.e, "-rw-r--r--"). |
| 145 // We need this wrapper because Drive cache files may be read from other | 145 // We need this wrapper because Drive cache files may be read from other |
| 146 // processes (e.g., cros_disks for mounting zip files). | 146 // processes (e.g., cros_disks for mounting zip files). |
| 147 bool CreateTemporaryReadableFileInDir(const base::FilePath& dir, | 147 bool CreateTemporaryReadableFileInDir(const base::FilePath& dir, |
| 148 base::FilePath* temp_file) { | 148 base::FilePath* temp_file) { |
| 149 if (!file_util::CreateTemporaryFileInDir(dir, temp_file)) | 149 if (!base::CreateTemporaryFileInDir(dir, temp_file)) |
| 150 return false; | 150 return false; |
| 151 return base::SetPosixFilePermissions( | 151 return base::SetPosixFilePermissions( |
| 152 *temp_file, | 152 *temp_file, |
| 153 base::FILE_PERMISSION_READ_BY_USER | | 153 base::FILE_PERMISSION_READ_BY_USER | |
| 154 base::FILE_PERMISSION_WRITE_BY_USER | | 154 base::FILE_PERMISSION_WRITE_BY_USER | |
| 155 base::FILE_PERMISSION_READ_BY_GROUP | | 155 base::FILE_PERMISSION_READ_BY_GROUP | |
| 156 base::FILE_PERMISSION_READ_BY_OTHERS); | 156 base::FILE_PERMISSION_READ_BY_OTHERS); |
| 157 } | 157 } |
| 158 | 158 |
| 159 // Prepares for downloading the file. Allocates the enough space for the file | 159 // Prepares for downloading the file. Allocates the enough space for the file |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 observer_->OnDirectoryChangedByOperation(file_path.DirName()); | 481 observer_->OnDirectoryChangedByOperation(file_path.DirName()); |
| 482 params->OnComplete(*cache_file_path); | 482 params->OnComplete(*cache_file_path); |
| 483 } | 483 } |
| 484 | 484 |
| 485 void DownloadOperation::CancelJob(JobID job_id) { | 485 void DownloadOperation::CancelJob(JobID job_id) { |
| 486 scheduler_->CancelJob(job_id); | 486 scheduler_->CancelJob(job_id); |
| 487 } | 487 } |
| 488 | 488 |
| 489 } // namespace file_system | 489 } // namespace file_system |
| 490 } // namespace drive | 490 } // namespace drive |
| OLD | NEW |