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 "components/drive/resource_metadata.h" | 5 #include "components/drive/resource_metadata.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
9 #include "base/guid.h" | 11 #include "base/guid.h" |
10 #include "base/location.h" | 12 #include "base/location.h" |
11 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
12 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
14 #include "base/sys_info.h" | 16 #include "base/sys_info.h" |
15 #include "components/drive/drive.pb.h" | 17 #include "components/drive/drive.pb.h" |
16 #include "components/drive/file_cache.h" | 18 #include "components/drive/file_cache.h" |
17 #include "components/drive/file_system_core_util.h" | 19 #include "components/drive/file_system_core_util.h" |
18 #include "components/drive/resource_metadata_storage.h" | 20 #include "components/drive/resource_metadata_storage.h" |
19 | 21 |
20 namespace drive { | 22 namespace drive { |
21 namespace internal { | 23 namespace internal { |
22 namespace { | 24 namespace { |
23 | 25 |
24 // Returns true if enough disk space is available for DB operation. | 26 // Returns true if enough disk space is available for DB operation. |
25 // TODO(hashimoto): Merge this with FileCache's FreeDiskSpaceGetterInterface. | 27 // TODO(hashimoto): Merge this with FileCache's FreeDiskSpaceGetterInterface. |
26 bool EnoughDiskSpaceIsAvailableForDBOperation(const base::FilePath& path) { | 28 bool EnoughDiskSpaceIsAvailableForDBOperation(const base::FilePath& path) { |
27 const int64 kRequiredDiskSpaceInMB = 128; // 128 MB seems to be large enough. | 29 const int64_t kRequiredDiskSpaceInMB = |
| 30 128; // 128 MB seems to be large enough. |
28 return base::SysInfo::AmountOfFreeDiskSpace(path) >= | 31 return base::SysInfo::AmountOfFreeDiskSpace(path) >= |
29 kRequiredDiskSpaceInMB * (1 << 20); | 32 kRequiredDiskSpaceInMB * (1 << 20); |
30 } | 33 } |
31 | 34 |
32 // Returns a file name with a uniquifier appended. (e.g. "File (1).txt") | 35 // Returns a file name with a uniquifier appended. (e.g. "File (1).txt") |
33 std::string GetUniquifiedName(const std::string& name, int uniquifier) { | 36 std::string GetUniquifiedName(const std::string& name, int uniquifier) { |
34 base::FilePath name_path = base::FilePath::FromUTF8Unsafe(name); | 37 base::FilePath name_path = base::FilePath::FromUTF8Unsafe(name); |
35 name_path = name_path.InsertBeforeExtensionASCII( | 38 name_path = name_path.InsertBeforeExtensionASCII( |
36 base::StringPrintf(" (%d)", uniquifier)); | 39 base::StringPrintf(" (%d)", uniquifier)); |
37 return name_path.AsUTF8Unsafe(); | 40 return name_path.AsUTF8Unsafe(); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 return error; | 203 return error; |
201 } | 204 } |
202 return FILE_ERROR_OK; | 205 return FILE_ERROR_OK; |
203 } | 206 } |
204 | 207 |
205 void ResourceMetadata::DestroyOnBlockingPool() { | 208 void ResourceMetadata::DestroyOnBlockingPool() { |
206 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 209 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
207 delete this; | 210 delete this; |
208 } | 211 } |
209 | 212 |
210 FileError ResourceMetadata::GetLargestChangestamp(int64* out_value) { | 213 FileError ResourceMetadata::GetLargestChangestamp(int64_t* out_value) { |
211 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 214 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
212 return storage_->GetLargestChangestamp(out_value); | 215 return storage_->GetLargestChangestamp(out_value); |
213 } | 216 } |
214 | 217 |
215 FileError ResourceMetadata::SetLargestChangestamp(int64 value) { | 218 FileError ResourceMetadata::SetLargestChangestamp(int64_t value) { |
216 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 219 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
217 | 220 |
218 if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path())) | 221 if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path())) |
219 return FILE_ERROR_NO_LOCAL_SPACE; | 222 return FILE_ERROR_NO_LOCAL_SPACE; |
220 | 223 |
221 return storage_->SetLargestChangestamp(value); | 224 return storage_->SetLargestChangestamp(value); |
222 } | 225 } |
223 | 226 |
224 FileError ResourceMetadata::AddEntry(const ResourceEntry& entry, | 227 FileError ResourceMetadata::AddEntry(const ResourceEntry& entry, |
225 std::string* out_id) { | 228 std::string* out_id) { |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 | 601 |
599 error = cache_->Remove(id); | 602 error = cache_->Remove(id); |
600 if (error != FILE_ERROR_OK) | 603 if (error != FILE_ERROR_OK) |
601 return error; | 604 return error; |
602 | 605 |
603 return storage_->RemoveEntry(id); | 606 return storage_->RemoveEntry(id); |
604 } | 607 } |
605 | 608 |
606 } // namespace internal | 609 } // namespace internal |
607 } // namespace drive | 610 } // namespace drive |
OLD | NEW |