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

Side by Side Diff: webkit/fileapi/file_system_usage_cache.cc

Issue 10824031: Fix two unchecked return values (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: return false Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 "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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 uint32 dirty = 0; 79 uint32 dirty = 0;
80 int64 fs_usage; 80 int64 fs_usage;
81 fs_usage = Read(usage_file_path, &is_valid, &dirty); 81 fs_usage = Read(usage_file_path, &is_valid, &dirty);
82 82
83 return fs_usage >= 0 && Write(usage_file_path, false, dirty, fs_usage); 83 return fs_usage >= 0 && Write(usage_file_path, false, dirty, fs_usage);
84 } 84 }
85 85
86 bool FileSystemUsageCache::IsValid(const FilePath& usage_file_path) { 86 bool FileSystemUsageCache::IsValid(const FilePath& usage_file_path) {
87 bool is_valid = true; 87 bool is_valid = true;
88 uint32 dirty = 0; 88 uint32 dirty = 0;
89 Read(usage_file_path, &is_valid, &dirty); 89 int64 result = Read(usage_file_path, &is_valid, &dirty);
90 if (result < 0)
91 return false;
92
90 return is_valid; 93 return is_valid;
91 } 94 }
92 95
93 // static 96 // static
94 int FileSystemUsageCache::AtomicUpdateUsageByDelta( 97 int FileSystemUsageCache::AtomicUpdateUsageByDelta(
95 const FilePath& usage_file_path, int64 delta) { 98 const FilePath& usage_file_path, int64 delta) {
96 bool is_valid = true; 99 bool is_valid = true;
97 uint32 dirty = 0; 100 uint32 dirty = 0;
98 int64 fs_usage; 101 int64 fs_usage;
99 // TODO(dmikurube): Make sure that usage_file_path is available. 102 // TODO(dmikurube): Make sure that usage_file_path is available.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 uint32 dirty, 159 uint32 dirty,
157 int64 fs_usage) { 160 int64 fs_usage) {
158 Pickle write_pickle; 161 Pickle write_pickle;
159 write_pickle.WriteBytes(kUsageFileHeader, kUsageFileHeaderSize); 162 write_pickle.WriteBytes(kUsageFileHeader, kUsageFileHeaderSize);
160 write_pickle.WriteBool(is_valid); 163 write_pickle.WriteBool(is_valid);
161 write_pickle.WriteUInt32(dirty); 164 write_pickle.WriteUInt32(dirty);
162 write_pickle.WriteInt64(fs_usage); 165 write_pickle.WriteInt64(fs_usage);
163 166
164 DCHECK(!usage_file_path.empty()); 167 DCHECK(!usage_file_path.empty());
165 FilePath temporary_usage_file_path; 168 FilePath temporary_usage_file_path;
166 file_util::CreateTemporaryFileInDir(usage_file_path.DirName(), 169 if (!file_util::CreateTemporaryFileInDir(usage_file_path.DirName(),
167 &temporary_usage_file_path); 170 &temporary_usage_file_path)) {
171 return -1;
172 }
173
168 int bytes_written = file_util::WriteFile(temporary_usage_file_path, 174 int bytes_written = file_util::WriteFile(temporary_usage_file_path,
169 (const char *)write_pickle.data(), 175 (const char *)write_pickle.data(),
170 write_pickle.size()); 176 write_pickle.size());
171 if (bytes_written != kUsageFileSize) 177 if (bytes_written != kUsageFileSize)
172 return -1; 178 return -1;
173 179
174 if (file_util::ReplaceFile(temporary_usage_file_path, usage_file_path)) 180 if (file_util::ReplaceFile(temporary_usage_file_path, usage_file_path))
175 return bytes_written; 181 return bytes_written;
176 else 182 else
177 return -1; 183 return -1;
178 } 184 }
179 185
180 } // namespace fileapi 186 } // namespace fileapi
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698