OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/fileapi/file_system_usage_cache.h" | 5 #include "webkit/fileapi/file_system_usage_cache.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
10 | 10 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 } | 67 } |
68 | 68 |
69 // static | 69 // static |
70 int FileSystemUsageCache::AtomicUpdateUsageByDelta( | 70 int FileSystemUsageCache::AtomicUpdateUsageByDelta( |
71 const FilePath& usage_file_path, int64 delta) { | 71 const FilePath& usage_file_path, int64 delta) { |
72 uint32 dirty = 0; | 72 uint32 dirty = 0; |
73 int64 fs_usage; | 73 int64 fs_usage; |
74 // TODO(dmikurube): Make sure that usage_file_path is available. | 74 // TODO(dmikurube): Make sure that usage_file_path is available. |
75 fs_usage = Read(usage_file_path, &dirty); | 75 fs_usage = Read(usage_file_path, &dirty); |
76 | 76 |
| 77 if (fs_usage < 0) |
| 78 return -1; |
| 79 |
77 return Write(usage_file_path, dirty, fs_usage + delta); | 80 return Write(usage_file_path, dirty, fs_usage + delta); |
78 } | 81 } |
79 | 82 |
80 // static | 83 // static |
81 int FileSystemUsageCache::UpdateUsage(const FilePath& usage_file_path, | 84 int FileSystemUsageCache::UpdateUsage(const FilePath& usage_file_path, |
82 int64 fs_usage) { | 85 int64 fs_usage) { |
83 return Write(usage_file_path, 0, fs_usage); | 86 return Write(usage_file_path, 0, fs_usage); |
84 } | 87 } |
85 | 88 |
86 // static | 89 // static |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 write_pickle.size()); | 140 write_pickle.size()); |
138 if (bytes_written != kUsageFileSize) | 141 if (bytes_written != kUsageFileSize) |
139 return -1; | 142 return -1; |
140 | 143 |
141 if (file_util::ReplaceFile(temporary_usage_file_path, usage_file_path)) | 144 if (file_util::ReplaceFile(temporary_usage_file_path, usage_file_path)) |
142 return bytes_written; | 145 return bytes_written; |
143 else | 146 else |
144 return -1; | 147 return -1; |
145 } | 148 } |
146 | 149 |
147 } | 150 } // namespace fileapi |
OLD | NEW |