OLD | NEW |
1 // Copyright (c) 2011 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 "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 |
11 namespace fileapi { | 11 namespace fileapi { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 int64 FileSystemUsageCache::Read(const FilePath& usage_file_path, | 124 int64 FileSystemUsageCache::Read(const FilePath& usage_file_path, |
125 bool* is_valid, | 125 bool* is_valid, |
126 uint32* dirty) { | 126 uint32* dirty) { |
127 char buffer[kUsageFileSize]; | 127 char buffer[kUsageFileSize]; |
128 const char *header; | 128 const char *header; |
129 DCHECK(!usage_file_path.empty()); | 129 DCHECK(!usage_file_path.empty()); |
130 if (kUsageFileSize != | 130 if (kUsageFileSize != |
131 file_util::ReadFile(usage_file_path, buffer, kUsageFileSize)) | 131 file_util::ReadFile(usage_file_path, buffer, kUsageFileSize)) |
132 return -1; | 132 return -1; |
133 Pickle read_pickle(buffer, kUsageFileSize); | 133 Pickle read_pickle(buffer, kUsageFileSize); |
134 void* iter = NULL; | 134 PickleIterator iter(read_pickle); |
135 int64 fs_usage; | 135 int64 fs_usage; |
136 | 136 |
137 if (!read_pickle.ReadBytes(&iter, &header, kUsageFileHeaderSize) || | 137 if (!read_pickle.ReadBytes(&iter, &header, kUsageFileHeaderSize) || |
138 !read_pickle.ReadBool(&iter, is_valid) || | 138 !read_pickle.ReadBool(&iter, is_valid) || |
139 !read_pickle.ReadUInt32(&iter, dirty) || | 139 !read_pickle.ReadUInt32(&iter, dirty) || |
140 !read_pickle.ReadInt64(&iter, &fs_usage)) | 140 !read_pickle.ReadInt64(&iter, &fs_usage)) |
141 return -1; | 141 return -1; |
142 | 142 |
143 if (header[0] != kUsageFileHeader[0] || | 143 if (header[0] != kUsageFileHeader[0] || |
144 header[1] != kUsageFileHeader[1] || | 144 header[1] != kUsageFileHeader[1] || |
(...skipping 25 matching lines...) Expand all Loading... |
170 if (bytes_written != kUsageFileSize) | 170 if (bytes_written != kUsageFileSize) |
171 return -1; | 171 return -1; |
172 | 172 |
173 if (file_util::ReplaceFile(temporary_usage_file_path, usage_file_path)) | 173 if (file_util::ReplaceFile(temporary_usage_file_path, usage_file_path)) |
174 return bytes_written; | 174 return bytes_written; |
175 else | 175 else |
176 return -1; | 176 return -1; |
177 } | 177 } |
178 | 178 |
179 } // namespace fileapi | 179 } // namespace fileapi |
OLD | NEW |