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

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: 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/compiler_specific.h"
7 #include "base/file_path.h" 8 #include "base/file_path.h"
8 #include "base/file_util.h" 9 #include "base/file_util.h"
9 #include "base/pickle.h" 10 #include "base/pickle.h"
10 11
11 namespace fileapi { 12 namespace fileapi {
12 13
13 const FilePath::CharType FileSystemUsageCache::kUsageFileName[] = 14 const FilePath::CharType FileSystemUsageCache::kUsageFileName[] =
14 FILE_PATH_LITERAL(".usage"); 15 FILE_PATH_LITERAL(".usage");
15 const char FileSystemUsageCache::kUsageFileHeader[] = "FSU4"; 16 const char FileSystemUsageCache::kUsageFileHeader[] = "FSU4";
16 const int FileSystemUsageCache::kUsageFileHeaderSize = 4; 17 const int FileSystemUsageCache::kUsageFileHeaderSize = 4;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 uint32 dirty = 0; 80 uint32 dirty = 0;
80 int64 fs_usage; 81 int64 fs_usage;
81 fs_usage = Read(usage_file_path, &is_valid, &dirty); 82 fs_usage = Read(usage_file_path, &is_valid, &dirty);
82 83
83 return fs_usage >= 0 && Write(usage_file_path, false, dirty, fs_usage); 84 return fs_usage >= 0 && Write(usage_file_path, false, dirty, fs_usage);
84 } 85 }
85 86
86 bool FileSystemUsageCache::IsValid(const FilePath& usage_file_path) { 87 bool FileSystemUsageCache::IsValid(const FilePath& usage_file_path) {
87 bool is_valid = true; 88 bool is_valid = true;
88 uint32 dirty = 0; 89 uint32 dirty = 0;
89 Read(usage_file_path, &is_valid, &dirty); 90 int64 result = Read(usage_file_path, &is_valid, &dirty);
91 if (result < 0)
92 return true;
brettw 2012/07/26 17:38:04 I'm not 100% sure if this is correct. Let's ask Er
ericu 2012/07/26 17:58:52 I think we want to return false there, but Kinuko
kinuko 2012/07/26 18:45:31 Looks like this should return false. dmikurube@ c
Tyler Breisacher (Chromium) 2012/07/26 18:47:07 If I'm not mistaken it's currently returning true,
Dai Mikurube (NOT FULLTIME) 2012/07/27 03:53:43 I think false is fine here.
93
90 return is_valid; 94 return is_valid;
91 } 95 }
92 96
93 // static 97 // static
94 int FileSystemUsageCache::AtomicUpdateUsageByDelta( 98 int FileSystemUsageCache::AtomicUpdateUsageByDelta(
95 const FilePath& usage_file_path, int64 delta) { 99 const FilePath& usage_file_path, int64 delta) {
96 bool is_valid = true; 100 bool is_valid = true;
97 uint32 dirty = 0; 101 uint32 dirty = 0;
98 int64 fs_usage; 102 int64 fs_usage;
99 // TODO(dmikurube): Make sure that usage_file_path is available. 103 // 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, 160 uint32 dirty,
157 int64 fs_usage) { 161 int64 fs_usage) {
158 Pickle write_pickle; 162 Pickle write_pickle;
159 write_pickle.WriteBytes(kUsageFileHeader, kUsageFileHeaderSize); 163 write_pickle.WriteBytes(kUsageFileHeader, kUsageFileHeaderSize);
160 write_pickle.WriteBool(is_valid); 164 write_pickle.WriteBool(is_valid);
161 write_pickle.WriteUInt32(dirty); 165 write_pickle.WriteUInt32(dirty);
162 write_pickle.WriteInt64(fs_usage); 166 write_pickle.WriteInt64(fs_usage);
163 167
164 DCHECK(!usage_file_path.empty()); 168 DCHECK(!usage_file_path.empty());
165 FilePath temporary_usage_file_path; 169 FilePath temporary_usage_file_path;
166 file_util::CreateTemporaryFileInDir(usage_file_path.DirName(), 170 if (!file_util::CreateTemporaryFileInDir(usage_file_path.DirName(),
167 &temporary_usage_file_path); 171 &temporary_usage_file_path))
172 return -1;
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