OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_cache.h" | 5 #include "components/drive/file_cache.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
12 #include "base/files/file_enumerator.h" | 12 #include "base/files/file_enumerator.h" |
13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "base/sys_info.h" | 19 #include "base/sys_info.h" |
20 #include "chrome/browser/chromeos/drive/file_system_core_util.h" | |
21 #include "chrome/browser/chromeos/drive/resource_metadata_storage.h" | |
22 #include "chromeos/chromeos_constants.h" | |
23 #include "components/drive/drive.pb.h" | 20 #include "components/drive/drive.pb.h" |
24 #include "components/drive/drive_api_util.h" | 21 #include "components/drive/drive_api_util.h" |
| 22 #include "components/drive/file_system_core_util.h" |
| 23 #include "components/drive/resource_metadata_storage.h" |
25 #include "google_apis/drive/task_util.h" | 24 #include "google_apis/drive/task_util.h" |
26 #include "net/base/filename_util.h" | 25 #include "net/base/filename_util.h" |
27 #include "net/base/mime_sniffer.h" | 26 #include "net/base/mime_sniffer.h" |
28 #include "net/base/mime_util.h" | 27 #include "net/base/mime_util.h" |
| 28 #if defined(OS_CHROMEOS) |
29 #include "third_party/cros_system_api/constants/cryptohome.h" | 29 #include "third_party/cros_system_api/constants/cryptohome.h" |
| 30 #endif |
30 | 31 |
31 namespace drive { | 32 namespace drive { |
32 namespace internal { | 33 namespace internal { |
33 namespace { | 34 namespace { |
34 | 35 |
35 // Returns ID extracted from the path. | 36 // Returns ID extracted from the path. |
36 std::string GetIdFromPath(const base::FilePath& path) { | 37 std::string GetIdFromPath(const base::FilePath& path) { |
37 return util::UnescapeCacheFileName(path.BaseName().AsUTF8Unsafe()); | 38 return util::UnescapeCacheFileName(path.BaseName().AsUTF8Unsafe()); |
38 } | 39 } |
39 | 40 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 ResourceEntry entry; | 237 ResourceEntry entry; |
237 FileError error = storage_->GetEntry(id, &entry); | 238 FileError error = storage_->GetEntry(id, &entry); |
238 if (error != FILE_ERROR_OK) | 239 if (error != FILE_ERROR_OK) |
239 return error; | 240 return error; |
240 if (!entry.file_specific_info().cache_state().is_present()) | 241 if (!entry.file_specific_info().cache_state().is_present()) |
241 return FILE_ERROR_NOT_FOUND; | 242 return FILE_ERROR_NOT_FOUND; |
242 | 243 |
243 if (mounted_files_.count(id)) | 244 if (mounted_files_.count(id)) |
244 return FILE_ERROR_INVALID_OPERATION; | 245 return FILE_ERROR_INVALID_OPERATION; |
245 | 246 |
| 247 base::FilePath path = GetCacheFilePath(id); |
| 248 |
| 249 #if defined(OS_CHROMEOS) |
246 // Ensure the file is readable to cros_disks. See crbug.com/236994. | 250 // Ensure the file is readable to cros_disks. See crbug.com/236994. |
247 base::FilePath path = GetCacheFilePath(id); | |
248 if (!base::SetPosixFilePermissions( | 251 if (!base::SetPosixFilePermissions( |
249 path, | 252 path, |
250 base::FILE_PERMISSION_READ_BY_USER | | 253 base::FILE_PERMISSION_READ_BY_USER | |
251 base::FILE_PERMISSION_WRITE_BY_USER | | 254 base::FILE_PERMISSION_WRITE_BY_USER | |
252 base::FILE_PERMISSION_READ_BY_GROUP | | 255 base::FILE_PERMISSION_READ_BY_GROUP | |
253 base::FILE_PERMISSION_READ_BY_OTHERS)) | 256 base::FILE_PERMISSION_READ_BY_OTHERS)) |
254 return FILE_ERROR_FAILED; | 257 return FILE_ERROR_FAILED; |
| 258 #endif |
255 | 259 |
256 mounted_files_.insert(id); | 260 mounted_files_.insert(id); |
257 | 261 |
258 *cache_file_path = path; | 262 *cache_file_path = path; |
259 return FILE_ERROR_OK; | 263 return FILE_ERROR_OK; |
260 } | 264 } |
261 | 265 |
262 FileError FileCache::OpenForWrite( | 266 FileError FileCache::OpenForWrite( |
263 const std::string& id, | 267 const std::string& id, |
264 scoped_ptr<base::ScopedClosureRunner>* file_closer) { | 268 scoped_ptr<base::ScopedClosureRunner>* file_closer) { |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 | 556 |
553 bool FileCache::HasEnoughSpaceFor(int64 num_bytes, | 557 bool FileCache::HasEnoughSpaceFor(int64 num_bytes, |
554 const base::FilePath& path) { | 558 const base::FilePath& path) { |
555 int64 free_space = 0; | 559 int64 free_space = 0; |
556 if (free_disk_space_getter_) | 560 if (free_disk_space_getter_) |
557 free_space = free_disk_space_getter_->AmountOfFreeDiskSpace(); | 561 free_space = free_disk_space_getter_->AmountOfFreeDiskSpace(); |
558 else | 562 else |
559 free_space = base::SysInfo::AmountOfFreeDiskSpace(path); | 563 free_space = base::SysInfo::AmountOfFreeDiskSpace(path); |
560 | 564 |
561 // Subtract this as if this portion does not exist. | 565 // Subtract this as if this portion does not exist. |
562 free_space -= cryptohome::kMinFreeSpaceInBytes; | 566 #if defined(OS_CHROMEOS) |
| 567 const int64 kMinFreeBytes = cryptohome::kMinFreeSpaceInBytes; |
| 568 #else |
| 569 const int64 kMinFreeBytes = 512ull * 1024ull * 1024ull; // 512MB |
| 570 #endif |
| 571 free_space -= kMinFreeBytes; |
563 return (free_space >= num_bytes); | 572 return (free_space >= num_bytes); |
564 } | 573 } |
565 | 574 |
566 bool FileCache::RenameCacheFilesToNewFormat() { | 575 bool FileCache::RenameCacheFilesToNewFormat() { |
567 base::FileEnumerator enumerator(cache_file_directory_, | 576 base::FileEnumerator enumerator(cache_file_directory_, |
568 false, // not recursive | 577 false, // not recursive |
569 base::FileEnumerator::FILES); | 578 base::FileEnumerator::FILES); |
570 for (base::FilePath current = enumerator.Next(); !current.empty(); | 579 for (base::FilePath current = enumerator.Next(); !current.empty(); |
571 current = enumerator.Next()) { | 580 current = enumerator.Next()) { |
572 base::FilePath new_path = current.RemoveExtension(); | 581 base::FilePath new_path = current.RemoveExtension(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 base::Time::Now().ToInternalValue()); | 617 base::Time::Now().ToInternalValue()); |
609 error = storage_->PutEntry(entry); | 618 error = storage_->PutEntry(entry); |
610 if (error != FILE_ERROR_OK) { | 619 if (error != FILE_ERROR_OK) { |
611 LOG(ERROR) << "Failed to put entry: " << id << ", " | 620 LOG(ERROR) << "Failed to put entry: " << id << ", " |
612 << FileErrorToString(error); | 621 << FileErrorToString(error); |
613 } | 622 } |
614 } | 623 } |
615 | 624 |
616 } // namespace internal | 625 } // namespace internal |
617 } // namespace drive | 626 } // namespace drive |
OLD | NEW |