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

Side by Side Diff: net/disk_cache/simple/simple_synchronous_entry.cc

Issue 14022012: Code quality and standards in SimpleBackend. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remediate Created 7 years, 8 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
OLDNEW
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 15 matching lines...) Expand all
26 using base::FilePath; 26 using base::FilePath;
27 using base::GetPlatformFileInfo; 27 using base::GetPlatformFileInfo;
28 using base::PlatformFileError; 28 using base::PlatformFileError;
29 using base::PlatformFileInfo; 29 using base::PlatformFileInfo;
30 using base::PLATFORM_FILE_CREATE; 30 using base::PLATFORM_FILE_CREATE;
31 using base::PLATFORM_FILE_OK; 31 using base::PLATFORM_FILE_OK;
32 using base::PLATFORM_FILE_OPEN; 32 using base::PLATFORM_FILE_OPEN;
33 using base::PLATFORM_FILE_READ; 33 using base::PLATFORM_FILE_READ;
34 using base::PLATFORM_FILE_WRITE; 34 using base::PLATFORM_FILE_WRITE;
35 using base::ReadPlatformFile; 35 using base::ReadPlatformFile;
36 using base::TaskRunner; 36 using base::SingleThreadTaskRunner;
37 using base::Time; 37 using base::Time;
38 using base::TruncatePlatformFile; 38 using base::TruncatePlatformFile;
39 using base::WritePlatformFile; 39 using base::WritePlatformFile;
40 40
41 namespace disk_cache { 41 namespace disk_cache {
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 SingleThreadTaskRunner* 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 SingleThreadTaskRunner* 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 SingleThreadTaskRunner* 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
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 SingleThreadTaskRunner* 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 return net::ERR_FAILED; 295 return net::ERR_FAILED;
296 } 296 }
297 } 297 }
298 initialized_ = true; 298 initialized_ = true;
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<SingleThreadTaskRunner>(), net::CompletionCallback());
306 } 306 }
307 307
308 } // namespace disk_cache 308 } // namespace disk_cache
OLDNEW
« net/disk_cache/simple/simple_index.cc ('K') | « net/disk_cache/simple/simple_synchronous_entry.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698