Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: storage/browser/fileapi/file_system_usage_cache.cc

Issue 1154283003: Change most uses of Pickle to base::Pickle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « skia/ext/skia_utils_base.cc ('k') | storage/browser/fileapi/sandbox_directory_database.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "storage/browser/fileapi/file_system_usage_cache.h" 5 #include "storage/browser/fileapi/file_system_usage_cache.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 20 matching lines...) Expand all
31 CloseCacheFiles(); 31 CloseCacheFiles();
32 } 32 }
33 33
34 const base::FilePath::CharType FileSystemUsageCache::kUsageFileName[] = 34 const base::FilePath::CharType FileSystemUsageCache::kUsageFileName[] =
35 FILE_PATH_LITERAL(".usage"); 35 FILE_PATH_LITERAL(".usage");
36 const char FileSystemUsageCache::kUsageFileHeader[] = "FSU5"; 36 const char FileSystemUsageCache::kUsageFileHeader[] = "FSU5";
37 const int FileSystemUsageCache::kUsageFileHeaderSize = 4; 37 const int FileSystemUsageCache::kUsageFileHeaderSize = 4;
38 38
39 // Pickle::{Read,Write}Bool treat bool as int 39 // Pickle::{Read,Write}Bool treat bool as int
40 const int FileSystemUsageCache::kUsageFileSize = 40 const int FileSystemUsageCache::kUsageFileSize =
41 sizeof(Pickle::Header) + 41 sizeof(base::Pickle::Header) + FileSystemUsageCache::kUsageFileHeaderSize +
42 FileSystemUsageCache::kUsageFileHeaderSize +
43 sizeof(int) + sizeof(int32) + sizeof(int64); // NOLINT 42 sizeof(int) + sizeof(int32) + sizeof(int64); // NOLINT
44 43
45 bool FileSystemUsageCache::GetUsage(const base::FilePath& usage_file_path, 44 bool FileSystemUsageCache::GetUsage(const base::FilePath& usage_file_path,
46 int64* usage_out) { 45 int64* usage_out) {
47 TRACE_EVENT0("FileSystem", "UsageCache::GetUsage"); 46 TRACE_EVENT0("FileSystem", "UsageCache::GetUsage");
48 DCHECK(CalledOnValidThread()); 47 DCHECK(CalledOnValidThread());
49 DCHECK(usage_out); 48 DCHECK(usage_out);
50 bool is_valid = true; 49 bool is_valid = true;
51 uint32 dirty = 0; 50 uint32 dirty = 0;
52 int64 usage = 0; 51 int64 usage = 0;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 TRACE_EVENT0("FileSystem", "UsageCache::Read"); 168 TRACE_EVENT0("FileSystem", "UsageCache::Read");
170 DCHECK(CalledOnValidThread()); 169 DCHECK(CalledOnValidThread());
171 DCHECK(is_valid); 170 DCHECK(is_valid);
172 DCHECK(dirty_out); 171 DCHECK(dirty_out);
173 DCHECK(usage_out); 172 DCHECK(usage_out);
174 char buffer[kUsageFileSize]; 173 char buffer[kUsageFileSize];
175 const char *header; 174 const char *header;
176 if (usage_file_path.empty() || 175 if (usage_file_path.empty() ||
177 !ReadBytes(usage_file_path, buffer, kUsageFileSize)) 176 !ReadBytes(usage_file_path, buffer, kUsageFileSize))
178 return false; 177 return false;
179 Pickle read_pickle(buffer, kUsageFileSize); 178 base::Pickle read_pickle(buffer, kUsageFileSize);
180 PickleIterator iter(read_pickle); 179 base::PickleIterator iter(read_pickle);
181 uint32 dirty = 0; 180 uint32 dirty = 0;
182 int64 usage = 0; 181 int64 usage = 0;
183 182
184 if (!iter.ReadBytes(&header, kUsageFileHeaderSize) || 183 if (!iter.ReadBytes(&header, kUsageFileHeaderSize) ||
185 !iter.ReadBool(is_valid) || 184 !iter.ReadBool(is_valid) ||
186 !iter.ReadUInt32(&dirty) || 185 !iter.ReadUInt32(&dirty) ||
187 !iter.ReadInt64(&usage)) 186 !iter.ReadInt64(&usage))
188 return false; 187 return false;
189 188
190 if (header[0] != kUsageFileHeader[0] || 189 if (header[0] != kUsageFileHeader[0] ||
191 header[1] != kUsageFileHeader[1] || 190 header[1] != kUsageFileHeader[1] ||
192 header[2] != kUsageFileHeader[2] || 191 header[2] != kUsageFileHeader[2] ||
193 header[3] != kUsageFileHeader[3]) 192 header[3] != kUsageFileHeader[3])
194 return false; 193 return false;
195 194
196 *dirty_out = dirty; 195 *dirty_out = dirty;
197 *usage_out = usage; 196 *usage_out = usage;
198 return true; 197 return true;
199 } 198 }
200 199
201 bool FileSystemUsageCache::Write(const base::FilePath& usage_file_path, 200 bool FileSystemUsageCache::Write(const base::FilePath& usage_file_path,
202 bool is_valid, 201 bool is_valid,
203 int32 dirty, 202 int32 dirty,
204 int64 usage) { 203 int64 usage) {
205 TRACE_EVENT0("FileSystem", "UsageCache::Write"); 204 TRACE_EVENT0("FileSystem", "UsageCache::Write");
206 DCHECK(CalledOnValidThread()); 205 DCHECK(CalledOnValidThread());
207 Pickle write_pickle; 206 base::Pickle write_pickle;
208 write_pickle.WriteBytes(kUsageFileHeader, kUsageFileHeaderSize); 207 write_pickle.WriteBytes(kUsageFileHeader, kUsageFileHeaderSize);
209 write_pickle.WriteBool(is_valid); 208 write_pickle.WriteBool(is_valid);
210 write_pickle.WriteUInt32(dirty); 209 write_pickle.WriteUInt32(dirty);
211 write_pickle.WriteInt64(usage); 210 write_pickle.WriteInt64(usage);
212 211
213 if (!WriteBytes(usage_file_path, 212 if (!WriteBytes(usage_file_path,
214 static_cast<const char*>(write_pickle.data()), 213 static_cast<const char*>(write_pickle.data()),
215 write_pickle.size())) { 214 write_pickle.size())) {
216 Delete(usage_file_path); 215 Delete(usage_file_path);
217 return false; 216 return false;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 return !task_runner_.get() || task_runner_->RunsTasksOnCurrentThread(); 293 return !task_runner_.get() || task_runner_->RunsTasksOnCurrentThread();
295 } 294 }
296 295
297 bool FileSystemUsageCache::HasCacheFileHandle(const base::FilePath& file_path) { 296 bool FileSystemUsageCache::HasCacheFileHandle(const base::FilePath& file_path) {
298 DCHECK(CalledOnValidThread()); 297 DCHECK(CalledOnValidThread());
299 DCHECK_LE(cache_files_.size(), kMaxHandleCacheSize); 298 DCHECK_LE(cache_files_.size(), kMaxHandleCacheSize);
300 return ContainsKey(cache_files_, file_path); 299 return ContainsKey(cache_files_, file_path);
301 } 300 }
302 301
303 } // namespace storage 302 } // namespace storage
OLDNEW
« no previous file with comments | « skia/ext/skia_utils_base.cc ('k') | storage/browser/fileapi/sandbox_directory_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698