| OLD | NEW |
| 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 "chrome/browser/safe_browsing/prefix_set.h" | 5 #include "chrome/browser/safe_browsing/prefix_set.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <math.h> | 8 #include <math.h> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 153 |
| 154 // static | 154 // static |
| 155 PrefixSet* PrefixSet::LoadFile(const base::FilePath& filter_name) { | 155 PrefixSet* PrefixSet::LoadFile(const base::FilePath& filter_name) { |
| 156 int64 size_64; | 156 int64 size_64; |
| 157 if (!base::GetFileSize(filter_name, &size_64)) | 157 if (!base::GetFileSize(filter_name, &size_64)) |
| 158 return NULL; | 158 return NULL; |
| 159 using base::MD5Digest; | 159 using base::MD5Digest; |
| 160 if (size_64 < static_cast<int64>(sizeof(FileHeader) + sizeof(MD5Digest))) | 160 if (size_64 < static_cast<int64>(sizeof(FileHeader) + sizeof(MD5Digest))) |
| 161 return NULL; | 161 return NULL; |
| 162 | 162 |
| 163 file_util::ScopedFILE file(file_util::OpenFile(filter_name, "rb")); | 163 file_util::ScopedFILE file(base::OpenFile(filter_name, "rb")); |
| 164 if (!file.get()) | 164 if (!file.get()) |
| 165 return NULL; | 165 return NULL; |
| 166 | 166 |
| 167 FileHeader header; | 167 FileHeader header; |
| 168 size_t read = fread(&header, sizeof(header), 1, file.get()); | 168 size_t read = fread(&header, sizeof(header), 1, file.get()); |
| 169 if (read != 1) | 169 if (read != 1) |
| 170 return NULL; | 170 return NULL; |
| 171 | 171 |
| 172 if (header.magic != kMagic || header.version != kVersion) | 172 if (header.magic != kMagic || header.version != kVersion) |
| 173 return NULL; | 173 return NULL; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 header.index_size = static_cast<uint32>(index_.size()); | 236 header.index_size = static_cast<uint32>(index_.size()); |
| 237 header.deltas_size = static_cast<uint32>(deltas_.size()); | 237 header.deltas_size = static_cast<uint32>(deltas_.size()); |
| 238 | 238 |
| 239 // Sanity check that the 32-bit values never mess things up. | 239 // Sanity check that the 32-bit values never mess things up. |
| 240 if (static_cast<size_t>(header.index_size) != index_.size() || | 240 if (static_cast<size_t>(header.index_size) != index_.size() || |
| 241 static_cast<size_t>(header.deltas_size) != deltas_.size()) { | 241 static_cast<size_t>(header.deltas_size) != deltas_.size()) { |
| 242 NOTREACHED(); | 242 NOTREACHED(); |
| 243 return false; | 243 return false; |
| 244 } | 244 } |
| 245 | 245 |
| 246 file_util::ScopedFILE file(file_util::OpenFile(filter_name, "wb")); | 246 file_util::ScopedFILE file(base::OpenFile(filter_name, "wb")); |
| 247 if (!file.get()) | 247 if (!file.get()) |
| 248 return false; | 248 return false; |
| 249 | 249 |
| 250 base::MD5Context context; | 250 base::MD5Context context; |
| 251 base::MD5Init(&context); | 251 base::MD5Init(&context); |
| 252 | 252 |
| 253 // TODO(shess): The I/O code in safe_browsing_store_file.cc would | 253 // TODO(shess): The I/O code in safe_browsing_store_file.cc would |
| 254 // sure be useful about now. | 254 // sure be useful about now. |
| 255 size_t written = fwrite(&header, sizeof(header), 1, file.get()); | 255 size_t written = fwrite(&header, sizeof(header), 1, file.get()); |
| 256 if (written != 1) | 256 if (written != 1) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 if (written != 1) | 290 if (written != 1) |
| 291 return false; | 291 return false; |
| 292 | 292 |
| 293 // TODO(shess): Can this code check that the close was successful? | 293 // TODO(shess): Can this code check that the close was successful? |
| 294 file.reset(); | 294 file.reset(); |
| 295 | 295 |
| 296 return true; | 296 return true; |
| 297 } | 297 } |
| 298 | 298 |
| 299 } // namespace safe_browsing | 299 } // namespace safe_browsing |
| OLD | NEW |