| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/file_manager/snapshot_manager.h" | 5 #include "chrome/browser/chromeos/file_manager/snapshot_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/sys_info.h" | 8 #include "base/sys_info.h" |
| 9 #include "chrome/browser/chromeos/file_manager/app_id.h" | 9 #include "chrome/browser/chromeos/file_manager/app_id.h" |
| 10 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" | 10 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "google_apis/drive/task_util.h" | 13 #include "google_apis/drive/task_util.h" |
| 14 #include "storage/browser/blob/shareable_file_reference.h" | 14 #include "storage/browser/blob/shareable_file_reference.h" |
| 15 #include "storage/browser/fileapi/file_system_context.h" | 15 #include "storage/browser/fileapi/file_system_context.h" |
| 16 #include "third_party/cros_system_api/constants/cryptohome.h" | 16 #include "third_party/cros_system_api/constants/cryptohome.h" |
| 17 | 17 |
| 18 namespace file_manager { | 18 namespace file_manager { |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 typedef base::Callback<void(int64)> GetNecessaryFreeSpaceCallback; | 21 typedef base::Callback<void(int64_t)> GetNecessaryFreeSpaceCallback; |
| 22 | 22 |
| 23 // Part of ComputeSpaceNeedToBeFreed. | 23 // Part of ComputeSpaceNeedToBeFreed. |
| 24 int64 ComputeSpaceNeedToBeFreedAfterGetMetadataOnBlockingPool( | 24 int64_t ComputeSpaceNeedToBeFreedAfterGetMetadataOnBlockingPool( |
| 25 const base::FilePath& path, | 25 const base::FilePath& path, |
| 26 int64 snapshot_size) { | 26 int64_t snapshot_size) { |
| 27 int64 free_size = base::SysInfo::AmountOfFreeDiskSpace(path); | 27 int64_t free_size = base::SysInfo::AmountOfFreeDiskSpace(path); |
| 28 if (free_size < 0) | 28 if (free_size < 0) |
| 29 return -1; | 29 return -1; |
| 30 | 30 |
| 31 // We need to keep cryptohome::kMinFreeSpaceInBytes free space even after | 31 // We need to keep cryptohome::kMinFreeSpaceInBytes free space even after |
| 32 // |snapshot_size| is occupied. | 32 // |snapshot_size| is occupied. |
| 33 free_size -= snapshot_size + cryptohome::kMinFreeSpaceInBytes; | 33 free_size -= snapshot_size + cryptohome::kMinFreeSpaceInBytes; |
| 34 return (free_size < 0 ? -free_size : 0); | 34 return (free_size < 0 ? -free_size : 0); |
| 35 } | 35 } |
| 36 | 36 |
| 37 // Part of ComputeSpaceNeedToBeFreed. | 37 // Part of ComputeSpaceNeedToBeFreed. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 // Bind callback should destruct the bound argument. | 95 // Bind callback should destruct the bound argument. |
| 96 void FreeReferenceOnIOThread( | 96 void FreeReferenceOnIOThread( |
| 97 const std::deque<SnapshotManager::FileReferenceWithSizeInfo>& file_refs) { | 97 const std::deque<SnapshotManager::FileReferenceWithSizeInfo>& file_refs) { |
| 98 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 98 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 99 } | 99 } |
| 100 | 100 |
| 101 } // namespace | 101 } // namespace |
| 102 | 102 |
| 103 SnapshotManager::FileReferenceWithSizeInfo::FileReferenceWithSizeInfo( | 103 SnapshotManager::FileReferenceWithSizeInfo::FileReferenceWithSizeInfo( |
| 104 scoped_refptr<storage::ShareableFileReference> ref, | 104 scoped_refptr<storage::ShareableFileReference> ref, |
| 105 int64 size) | 105 int64_t size) |
| 106 : file_ref(ref), file_size(size) { | 106 : file_ref(ref), file_size(size) {} |
| 107 } | |
| 108 | 107 |
| 109 SnapshotManager::FileReferenceWithSizeInfo::~FileReferenceWithSizeInfo() { | 108 SnapshotManager::FileReferenceWithSizeInfo::~FileReferenceWithSizeInfo() { |
| 110 } | 109 } |
| 111 | 110 |
| 112 SnapshotManager::SnapshotManager(Profile* profile) | 111 SnapshotManager::SnapshotManager(Profile* profile) |
| 113 : profile_(profile), weak_ptr_factory_(this) { | 112 : profile_(profile), weak_ptr_factory_(this) { |
| 114 } | 113 } |
| 115 | 114 |
| 116 SnapshotManager::~SnapshotManager() { | 115 SnapshotManager::~SnapshotManager() { |
| 117 if (!file_refs_.empty()) { | 116 if (!file_refs_.empty()) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 141 ComputeSpaceNeedToBeFreed(profile_, context, filesystem_url, | 140 ComputeSpaceNeedToBeFreed(profile_, context, filesystem_url, |
| 142 base::Bind(&SnapshotManager::CreateManagedSnapshotAfterSpaceComputed, | 141 base::Bind(&SnapshotManager::CreateManagedSnapshotAfterSpaceComputed, |
| 143 weak_ptr_factory_.GetWeakPtr(), | 142 weak_ptr_factory_.GetWeakPtr(), |
| 144 filesystem_url, | 143 filesystem_url, |
| 145 callback)); | 144 callback)); |
| 146 } | 145 } |
| 147 | 146 |
| 148 void SnapshotManager::CreateManagedSnapshotAfterSpaceComputed( | 147 void SnapshotManager::CreateManagedSnapshotAfterSpaceComputed( |
| 149 const storage::FileSystemURL& filesystem_url, | 148 const storage::FileSystemURL& filesystem_url, |
| 150 const LocalPathCallback& callback, | 149 const LocalPathCallback& callback, |
| 151 int64 needed_space) { | 150 int64_t needed_space) { |
| 152 scoped_refptr<storage::FileSystemContext> context( | 151 scoped_refptr<storage::FileSystemContext> context( |
| 153 util::GetFileSystemContextForExtensionId(profile_, kFileManagerAppId)); | 152 util::GetFileSystemContextForExtensionId(profile_, kFileManagerAppId)); |
| 154 DCHECK(context.get()); | 153 DCHECK(context.get()); |
| 155 | 154 |
| 156 if (needed_space < 0) { | 155 if (needed_space < 0) { |
| 157 callback.Run(base::FilePath()); | 156 callback.Run(base::FilePath()); |
| 158 return; | 157 return; |
| 159 } | 158 } |
| 160 | 159 |
| 161 // Free up to the required size. | 160 // Free up to the required size. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 if (result != base::File::FILE_OK) { | 202 if (result != base::File::FILE_OK) { |
| 204 callback.Run(base::FilePath()); | 203 callback.Run(base::FilePath()); |
| 205 return; | 204 return; |
| 206 } | 205 } |
| 207 | 206 |
| 208 file_refs_.push_back(FileReferenceWithSizeInfo(file_ref, file_info.size)); | 207 file_refs_.push_back(FileReferenceWithSizeInfo(file_ref, file_info.size)); |
| 209 callback.Run(platform_path); | 208 callback.Run(platform_path); |
| 210 } | 209 } |
| 211 | 210 |
| 212 } // namespace file_manager | 211 } // namespace file_manager |
| OLD | NEW |