| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "net/disk_cache/simple/simple_synchronous_entry.h" | 5 #include "net/disk_cache/simple/simple_synchronous_entry.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 using simple_util::GetFilenameFromKeyAndIndex; | 43 using simple_util::GetFilenameFromKeyAndIndex; |
| 44 using simple_util::GetDataSizeFromKeyAndFileSize; | 44 using simple_util::GetDataSizeFromKeyAndFileSize; |
| 45 using simple_util::GetFileSizeFromKeyAndDataSize; | 45 using simple_util::GetFileSizeFromKeyAndDataSize; |
| 46 using simple_util::GetFileOffsetFromKeyAndDataOffset; | 46 using simple_util::GetFileOffsetFromKeyAndDataOffset; |
| 47 | 47 |
| 48 // static | 48 // static |
| 49 void SimpleSynchronousEntry::OpenEntry( | 49 void SimpleSynchronousEntry::OpenEntry( |
| 50 const FilePath& path, | 50 const FilePath& path, |
| 51 const std::string& key, | 51 const std::string& key, |
| 52 const scoped_refptr<TaskRunner>& callback_runner, | 52 TaskRunner* callback_runner, |
| 53 const SynchronousCreationCallback& callback) { | 53 const SynchronousCreationCallback& callback) { |
| 54 SimpleSynchronousEntry* sync_entry = | 54 SimpleSynchronousEntry* sync_entry = |
| 55 new SimpleSynchronousEntry(callback_runner, path, key); | 55 new SimpleSynchronousEntry(callback_runner, path, key); |
| 56 int rv = sync_entry->InitializeForOpen(); | 56 int rv = sync_entry->InitializeForOpen(); |
| 57 if (rv != net::OK) { | 57 if (rv != net::OK) { |
| 58 sync_entry->Doom(); | 58 sync_entry->Doom(); |
| 59 delete sync_entry; | 59 delete sync_entry; |
| 60 sync_entry = NULL; | 60 sync_entry = NULL; |
| 61 } | 61 } |
| 62 callback_runner->PostTask(FROM_HERE, base::Bind(callback, sync_entry)); | 62 callback_runner->PostTask(FROM_HERE, base::Bind(callback, sync_entry)); |
| 63 } | 63 } |
| 64 | 64 |
| 65 // static | 65 // static |
| 66 void SimpleSynchronousEntry::CreateEntry( | 66 void SimpleSynchronousEntry::CreateEntry( |
| 67 const FilePath& path, | 67 const FilePath& path, |
| 68 const std::string& key, | 68 const std::string& key, |
| 69 const scoped_refptr<TaskRunner>& callback_runner, | 69 TaskRunner* callback_runner, |
| 70 const SynchronousCreationCallback& callback) { | 70 const SynchronousCreationCallback& callback) { |
| 71 SimpleSynchronousEntry* sync_entry = | 71 SimpleSynchronousEntry* sync_entry = |
| 72 new SimpleSynchronousEntry(callback_runner, path, key); | 72 new SimpleSynchronousEntry(callback_runner, path, key); |
| 73 int rv = sync_entry->InitializeForCreate(); | 73 int rv = sync_entry->InitializeForCreate(); |
| 74 if (rv != net::OK) { | 74 if (rv != net::OK) { |
| 75 if (rv != net::ERR_FILE_EXISTS) { | 75 if (rv != net::ERR_FILE_EXISTS) { |
| 76 sync_entry->Doom(); | 76 sync_entry->Doom(); |
| 77 } | 77 } |
| 78 delete sync_entry; | 78 delete sync_entry; |
| 79 sync_entry = NULL; | 79 sync_entry = NULL; |
| 80 } | 80 } |
| 81 callback_runner->PostTask(FROM_HERE, base::Bind(callback, sync_entry)); | 81 callback_runner->PostTask(FROM_HERE, base::Bind(callback, sync_entry)); |
| 82 } | 82 } |
| 83 | 83 |
| 84 // static | 84 // static |
| 85 void SimpleSynchronousEntry::DoomEntry( | 85 void SimpleSynchronousEntry::DoomEntry( |
| 86 const FilePath& path, | 86 const FilePath& path, |
| 87 const std::string& key, | 87 const std::string& key, |
| 88 const scoped_refptr<TaskRunner>& callback_runner, | 88 TaskRunner* callback_runner, |
| 89 const net::CompletionCallback& callback) { | 89 const net::CompletionCallback& callback) { |
| 90 for (int i = 0; i < kSimpleEntryFileCount; ++i) { | 90 for (int i = 0; i < kSimpleEntryFileCount; ++i) { |
| 91 FilePath to_delete = path.AppendASCII(GetFilenameFromKeyAndIndex(key, i)); | 91 FilePath to_delete = path.AppendASCII(GetFilenameFromKeyAndIndex(key, i)); |
| 92 bool ALLOW_UNUSED result = file_util::Delete(to_delete, false); | 92 bool ALLOW_UNUSED result = file_util::Delete(to_delete, false); |
| 93 DLOG_IF(ERROR, !result) << "Could not delete " << to_delete.MaybeAsASCII(); | 93 DLOG_IF(ERROR, !result) << "Could not delete " << to_delete.MaybeAsASCII(); |
| 94 } | 94 } |
| 95 if (!callback.is_null()) | 95 if (!callback.is_null()) |
| 96 callback_runner->PostTask(FROM_HERE, base::Bind(callback, net::OK)); | 96 callback_runner->PostTask(FROM_HERE, base::Bind(callback, net::OK)); |
| 97 } | 97 } |
| 98 | 98 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 callback_runner_->PostTask(FROM_HERE, | 150 callback_runner_->PostTask(FROM_HERE, |
| 151 base::Bind(callback, net::ERR_FAILED)); | 151 base::Bind(callback, net::ERR_FAILED)); |
| 152 return; | 152 return; |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 last_modified_ = Time::Now(); | 155 last_modified_ = Time::Now(); |
| 156 callback_runner_->PostTask(FROM_HERE, base::Bind(callback, buf_len)); | 156 callback_runner_->PostTask(FROM_HERE, base::Bind(callback, buf_len)); |
| 157 } | 157 } |
| 158 | 158 |
| 159 SimpleSynchronousEntry::SimpleSynchronousEntry( | 159 SimpleSynchronousEntry::SimpleSynchronousEntry( |
| 160 const scoped_refptr<TaskRunner>& callback_runner, | 160 TaskRunner* callback_runner, |
| 161 const FilePath& path, | 161 const FilePath& path, |
| 162 const std::string& key) | 162 const std::string& key) |
| 163 : callback_runner_(callback_runner), | 163 : callback_runner_(callback_runner), |
| 164 path_(path), | 164 path_(path), |
| 165 key_(key), | 165 key_(key), |
| 166 initialized_(false) { | 166 initialized_(false) { |
| 167 } | 167 } |
| 168 | 168 |
| 169 SimpleSynchronousEntry::~SimpleSynchronousEntry() { | 169 SimpleSynchronousEntry::~SimpleSynchronousEntry() { |
| 170 } | 170 } |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 return net::OK; | 299 return net::OK; |
| 300 } | 300 } |
| 301 | 301 |
| 302 void SimpleSynchronousEntry::Doom() { | 302 void SimpleSynchronousEntry::Doom() { |
| 303 // TODO(gavinp): Consider if we should guard against redundant Doom() calls. | 303 // TODO(gavinp): Consider if we should guard against redundant Doom() calls. |
| 304 DoomEntry(path_, key_, | 304 DoomEntry(path_, key_, |
| 305 scoped_refptr<base::TaskRunner>(), net::CompletionCallback()); | 305 scoped_refptr<base::TaskRunner>(), net::CompletionCallback()); |
| 306 } | 306 } |
| 307 | 307 |
| 308 } // namespace disk_cache | 308 } // namespace disk_cache |
| OLD | NEW |