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 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 | 553 |
553 bool FileCache::HasEnoughSpaceFor(int64 num_bytes, | 554 bool FileCache::HasEnoughSpaceFor(int64 num_bytes, |
554 const base::FilePath& path) { | 555 const base::FilePath& path) { |
555 int64 free_space = 0; | 556 int64 free_space = 0; |
556 if (free_disk_space_getter_) | 557 if (free_disk_space_getter_) |
557 free_space = free_disk_space_getter_->AmountOfFreeDiskSpace(); | 558 free_space = free_disk_space_getter_->AmountOfFreeDiskSpace(); |
558 else | 559 else |
559 free_space = base::SysInfo::AmountOfFreeDiskSpace(path); | 560 free_space = base::SysInfo::AmountOfFreeDiskSpace(path); |
560 | 561 |
561 // Subtract this as if this portion does not exist. | 562 // Subtract this as if this portion does not exist. |
562 free_space -= cryptohome::kMinFreeSpaceInBytes; | 563 #if defined(OS_CHROMEOS) |
| 564 const int64 kMinFreeBytes = cryptohome::kMinFreeSpaceInBytes; |
| 565 #else |
| 566 const int64 kMinFreeBytes = 512ull * 1024ull * 1024ull; // 512MB |
| 567 #endif |
| 568 free_space -= kMinFreeBytes; |
563 return (free_space >= num_bytes); | 569 return (free_space >= num_bytes); |
564 } | 570 } |
565 | 571 |
566 bool FileCache::RenameCacheFilesToNewFormat() { | 572 bool FileCache::RenameCacheFilesToNewFormat() { |
567 base::FileEnumerator enumerator(cache_file_directory_, | 573 base::FileEnumerator enumerator(cache_file_directory_, |
568 false, // not recursive | 574 false, // not recursive |
569 base::FileEnumerator::FILES); | 575 base::FileEnumerator::FILES); |
570 for (base::FilePath current = enumerator.Next(); !current.empty(); | 576 for (base::FilePath current = enumerator.Next(); !current.empty(); |
571 current = enumerator.Next()) { | 577 current = enumerator.Next()) { |
572 base::FilePath new_path = current.RemoveExtension(); | 578 base::FilePath new_path = current.RemoveExtension(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 base::Time::Now().ToInternalValue()); | 614 base::Time::Now().ToInternalValue()); |
609 error = storage_->PutEntry(entry); | 615 error = storage_->PutEntry(entry); |
610 if (error != FILE_ERROR_OK) { | 616 if (error != FILE_ERROR_OK) { |
611 LOG(ERROR) << "Failed to put entry: " << id << ", " | 617 LOG(ERROR) << "Failed to put entry: " << id << ", " |
612 << FileErrorToString(error); | 618 << FileErrorToString(error); |
613 } | 619 } |
614 } | 620 } |
615 | 621 |
616 } // namespace internal | 622 } // namespace internal |
617 } // namespace drive | 623 } // namespace drive |
OLD | NEW |