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

Side by Side Diff: content/browser/appcache/appcache_disk_cache.cc

Issue 1499423004: Remove kint32max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kint9
Patch Set: rebase Created 5 years 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) 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 "content/browser/appcache/appcache_disk_cache.h" 5 #include "content/browser/appcache/appcache_disk_cache.h"
6 6
7 #include <limits>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
9 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
10 #include "base/logging.h" 12 #include "base/logging.h"
11 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
12 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
13 #include "base/stl_util.h" 15 #include "base/stl_util.h"
14 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
15 #include "net/base/cache_type.h" 17 #include "net/base/cache_type.h"
16 #include "net/base/net_errors.h" 18 #include "net/base/net_errors.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 EntryImpl(disk_cache::Entry* disk_cache_entry, 56 EntryImpl(disk_cache::Entry* disk_cache_entry,
55 AppCacheDiskCache* owner) 57 AppCacheDiskCache* owner)
56 : disk_cache_entry_(disk_cache_entry), owner_(owner) { 58 : disk_cache_entry_(disk_cache_entry), owner_(owner) {
57 DCHECK(disk_cache_entry); 59 DCHECK(disk_cache_entry);
58 DCHECK(owner); 60 DCHECK(owner);
59 owner_->AddOpenEntry(this); 61 owner_->AddOpenEntry(this);
60 } 62 }
61 63
62 // Entry implementation. 64 // Entry implementation.
63 int Read(int index, 65 int Read(int index,
64 int64 offset, 66 int64_t offset,
65 net::IOBuffer* buf, 67 net::IOBuffer* buf,
66 int buf_len, 68 int buf_len,
67 const net::CompletionCallback& callback) override { 69 const net::CompletionCallback& callback) override {
68 if (offset < 0 || offset > kint32max) 70 if (offset < 0 || offset > std::numeric_limits<int32_t>::max())
69 return net::ERR_INVALID_ARGUMENT; 71 return net::ERR_INVALID_ARGUMENT;
70 if (!disk_cache_entry_) 72 if (!disk_cache_entry_)
71 return net::ERR_ABORTED; 73 return net::ERR_ABORTED;
72 return disk_cache_entry_->ReadData( 74 return disk_cache_entry_->ReadData(
73 index, static_cast<int>(offset), buf, buf_len, callback); 75 index, static_cast<int>(offset), buf, buf_len, callback);
74 } 76 }
75 77
76 int Write(int index, 78 int Write(int index,
77 int64 offset, 79 int64_t offset,
78 net::IOBuffer* buf, 80 net::IOBuffer* buf,
79 int buf_len, 81 int buf_len,
80 const net::CompletionCallback& callback) override { 82 const net::CompletionCallback& callback) override {
81 if (offset < 0 || offset > kint32max) 83 if (offset < 0 || offset > std::numeric_limits<int32_t>::max())
82 return net::ERR_INVALID_ARGUMENT; 84 return net::ERR_INVALID_ARGUMENT;
83 if (!disk_cache_entry_) 85 if (!disk_cache_entry_)
84 return net::ERR_ABORTED; 86 return net::ERR_ABORTED;
85 const bool kTruncate = true; 87 const bool kTruncate = true;
86 return disk_cache_entry_->WriteData( 88 return disk_cache_entry_->WriteData(
87 index, static_cast<int>(offset), buf, buf_len, callback, kTruncate); 89 index, static_cast<int>(offset), buf, buf_len, callback, kTruncate);
88 } 90 }
89 91
90 int64 GetSize(int index) override { 92 int64_t GetSize(int index) override {
91 return disk_cache_entry_ ? disk_cache_entry_->GetDataSize(index) : 0L; 93 return disk_cache_entry_ ? disk_cache_entry_->GetDataSize(index) : 0L;
92 } 94 }
93 95
94 void Close() override { 96 void Close() override {
95 if (disk_cache_entry_) 97 if (disk_cache_entry_)
96 disk_cache_entry_->Close(); 98 disk_cache_entry_->Close();
97 delete this; 99 delete this;
98 } 100 }
99 101
100 void Abandon() { 102 void Abandon() {
(...skipping 11 matching lines...) Expand all
112 disk_cache::Entry* disk_cache_entry_; 114 disk_cache::Entry* disk_cache_entry_;
113 AppCacheDiskCache* owner_; 115 AppCacheDiskCache* owner_;
114 }; 116 };
115 117
116 // Separate object to hold state for each Create, Delete, or Doom call 118 // Separate object to hold state for each Create, Delete, or Doom call
117 // while the call is in-flight and to produce an EntryImpl upon completion. 119 // while the call is in-flight and to produce an EntryImpl upon completion.
118 class AppCacheDiskCache::ActiveCall 120 class AppCacheDiskCache::ActiveCall
119 : public base::RefCounted<AppCacheDiskCache::ActiveCall> { 121 : public base::RefCounted<AppCacheDiskCache::ActiveCall> {
120 public: 122 public:
121 static int CreateEntry(const base::WeakPtr<AppCacheDiskCache>& owner, 123 static int CreateEntry(const base::WeakPtr<AppCacheDiskCache>& owner,
122 int64 key, Entry** entry, 124 int64_t key,
125 Entry** entry,
123 const net::CompletionCallback& callback) { 126 const net::CompletionCallback& callback) {
124 scoped_refptr<ActiveCall> active_call( 127 scoped_refptr<ActiveCall> active_call(
125 new ActiveCall(owner, entry, callback)); 128 new ActiveCall(owner, entry, callback));
126 int rv = owner->disk_cache()->CreateEntry( 129 int rv = owner->disk_cache()->CreateEntry(
127 base::Int64ToString(key), &active_call->entry_ptr_, 130 base::Int64ToString(key), &active_call->entry_ptr_,
128 base::Bind(&ActiveCall::OnAsyncCompletion, active_call)); 131 base::Bind(&ActiveCall::OnAsyncCompletion, active_call));
129 return active_call->HandleImmediateReturnValue(rv); 132 return active_call->HandleImmediateReturnValue(rv);
130 } 133 }
131 134
132 static int OpenEntry(const base::WeakPtr<AppCacheDiskCache>& owner, 135 static int OpenEntry(const base::WeakPtr<AppCacheDiskCache>& owner,
133 int64 key, Entry** entry, 136 int64_t key,
137 Entry** entry,
134 const net::CompletionCallback& callback) { 138 const net::CompletionCallback& callback) {
135 scoped_refptr<ActiveCall> active_call( 139 scoped_refptr<ActiveCall> active_call(
136 new ActiveCall(owner, entry, callback)); 140 new ActiveCall(owner, entry, callback));
137 int rv = owner->disk_cache()->OpenEntry( 141 int rv = owner->disk_cache()->OpenEntry(
138 base::Int64ToString(key), &active_call->entry_ptr_, 142 base::Int64ToString(key), &active_call->entry_ptr_,
139 base::Bind(&ActiveCall::OnAsyncCompletion, active_call)); 143 base::Bind(&ActiveCall::OnAsyncCompletion, active_call));
140 return active_call->HandleImmediateReturnValue(rv); 144 return active_call->HandleImmediateReturnValue(rv);
141 } 145 }
142 146
143 static int DoomEntry(const base::WeakPtr<AppCacheDiskCache>& owner, 147 static int DoomEntry(const base::WeakPtr<AppCacheDiskCache>& owner,
144 int64 key, const net::CompletionCallback& callback) { 148 int64_t key,
149 const net::CompletionCallback& callback) {
145 scoped_refptr<ActiveCall> active_call( 150 scoped_refptr<ActiveCall> active_call(
146 new ActiveCall(owner, nullptr, callback)); 151 new ActiveCall(owner, nullptr, callback));
147 int rv = owner->disk_cache()->DoomEntry( 152 int rv = owner->disk_cache()->DoomEntry(
148 base::Int64ToString(key), 153 base::Int64ToString(key),
149 base::Bind(&ActiveCall::OnAsyncCompletion, active_call)); 154 base::Bind(&ActiveCall::OnAsyncCompletion, active_call));
150 return active_call->HandleImmediateReturnValue(rv); 155 return active_call->HandleImmediateReturnValue(rv);
151 } 156 }
152 157
153 private: 158 private:
154 friend class base::RefCounted<AppCacheDiskCache::ActiveCall>; 159 friend class base::RefCounted<AppCacheDiskCache::ActiveCall>;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // appcache system on the fly. File handles held in both entries and in 251 // appcache system on the fly. File handles held in both entries and in
247 // the main disk_cache::Backend class need to be released. 252 // the main disk_cache::Backend class need to be released.
248 for (OpenEntries::const_iterator iter = open_entries_.begin(); 253 for (OpenEntries::const_iterator iter = open_entries_.begin();
249 iter != open_entries_.end(); ++iter) { 254 iter != open_entries_.end(); ++iter) {
250 (*iter)->Abandon(); 255 (*iter)->Abandon();
251 } 256 }
252 open_entries_.clear(); 257 open_entries_.clear();
253 disk_cache_.reset(); 258 disk_cache_.reset();
254 } 259 }
255 260
256 int AppCacheDiskCache::CreateEntry(int64 key, Entry** entry, 261 int AppCacheDiskCache::CreateEntry(int64_t key,
262 Entry** entry,
257 const net::CompletionCallback& callback) { 263 const net::CompletionCallback& callback) {
258 DCHECK(entry); 264 DCHECK(entry);
259 DCHECK(!callback.is_null()); 265 DCHECK(!callback.is_null());
260 if (is_disabled_) 266 if (is_disabled_)
261 return net::ERR_ABORTED; 267 return net::ERR_ABORTED;
262 268
263 if (is_initializing_or_waiting_to_initialize()) { 269 if (is_initializing_or_waiting_to_initialize()) {
264 pending_calls_.push_back(PendingCall(CREATE, key, entry, callback)); 270 pending_calls_.push_back(PendingCall(CREATE, key, entry, callback));
265 return net::ERR_IO_PENDING; 271 return net::ERR_IO_PENDING;
266 } 272 }
267 273
268 if (!disk_cache_) 274 if (!disk_cache_)
269 return net::ERR_FAILED; 275 return net::ERR_FAILED;
270 276
271 return ActiveCall::CreateEntry( 277 return ActiveCall::CreateEntry(
272 weak_factory_.GetWeakPtr(), key, entry, callback); 278 weak_factory_.GetWeakPtr(), key, entry, callback);
273 } 279 }
274 280
275 int AppCacheDiskCache::OpenEntry(int64 key, Entry** entry, 281 int AppCacheDiskCache::OpenEntry(int64_t key,
282 Entry** entry,
276 const net::CompletionCallback& callback) { 283 const net::CompletionCallback& callback) {
277 DCHECK(entry); 284 DCHECK(entry);
278 DCHECK(!callback.is_null()); 285 DCHECK(!callback.is_null());
279 if (is_disabled_) 286 if (is_disabled_)
280 return net::ERR_ABORTED; 287 return net::ERR_ABORTED;
281 288
282 if (is_initializing_or_waiting_to_initialize()) { 289 if (is_initializing_or_waiting_to_initialize()) {
283 pending_calls_.push_back(PendingCall(OPEN, key, entry, callback)); 290 pending_calls_.push_back(PendingCall(OPEN, key, entry, callback));
284 return net::ERR_IO_PENDING; 291 return net::ERR_IO_PENDING;
285 } 292 }
286 293
287 if (!disk_cache_) 294 if (!disk_cache_)
288 return net::ERR_FAILED; 295 return net::ERR_FAILED;
289 296
290 return ActiveCall::OpenEntry( 297 return ActiveCall::OpenEntry(
291 weak_factory_.GetWeakPtr(), key, entry, callback); 298 weak_factory_.GetWeakPtr(), key, entry, callback);
292 } 299 }
293 300
294 int AppCacheDiskCache::DoomEntry(int64 key, 301 int AppCacheDiskCache::DoomEntry(int64_t key,
295 const net::CompletionCallback& callback) { 302 const net::CompletionCallback& callback) {
296 DCHECK(!callback.is_null()); 303 DCHECK(!callback.is_null());
297 if (is_disabled_) 304 if (is_disabled_)
298 return net::ERR_ABORTED; 305 return net::ERR_ABORTED;
299 306
300 if (is_initializing_or_waiting_to_initialize()) { 307 if (is_initializing_or_waiting_to_initialize()) {
301 pending_calls_.push_back(PendingCall(DOOM, key, NULL, callback)); 308 pending_calls_.push_back(PendingCall(DOOM, key, NULL, callback));
302 return net::ERR_IO_PENDING; 309 return net::ERR_IO_PENDING;
303 } 310 }
304 311
305 if (!disk_cache_) 312 if (!disk_cache_)
306 return net::ERR_FAILED; 313 return net::ERR_FAILED;
307 314
308 return ActiveCall::DoomEntry(weak_factory_.GetWeakPtr(), key, callback); 315 return ActiveCall::DoomEntry(weak_factory_.GetWeakPtr(), key, callback);
309 } 316 }
310 317
311 AppCacheDiskCache::AppCacheDiskCache(bool use_simple_cache) 318 AppCacheDiskCache::AppCacheDiskCache(bool use_simple_cache)
312 : use_simple_cache_(use_simple_cache), 319 : use_simple_cache_(use_simple_cache),
313 is_disabled_(false), 320 is_disabled_(false),
314 is_waiting_to_initialize_(false), 321 is_waiting_to_initialize_(false),
315 weak_factory_(this) { 322 weak_factory_(this) {
316 } 323 }
317 324
318 AppCacheDiskCache::PendingCall::PendingCall() 325 AppCacheDiskCache::PendingCall::PendingCall()
319 : call_type(CREATE), 326 : call_type(CREATE),
320 key(0), 327 key(0),
321 entry(NULL) { 328 entry(NULL) {
322 } 329 }
323 330
324 AppCacheDiskCache::PendingCall::PendingCall(PendingCallType call_type, 331 AppCacheDiskCache::PendingCall::PendingCall(
325 int64 key, 332 PendingCallType call_type,
333 int64_t key,
326 Entry** entry, 334 Entry** entry,
327 const net::CompletionCallback& callback) 335 const net::CompletionCallback& callback)
328 : call_type(call_type), 336 : call_type(call_type), key(key), entry(entry), callback(callback) {}
329 key(key),
330 entry(entry),
331 callback(callback) {
332 }
333 337
334 AppCacheDiskCache::PendingCall::~PendingCall() {} 338 AppCacheDiskCache::PendingCall::~PendingCall() {}
335 339
336 int AppCacheDiskCache::Init( 340 int AppCacheDiskCache::Init(
337 net::CacheType cache_type, 341 net::CacheType cache_type,
338 const base::FilePath& cache_directory, 342 const base::FilePath& cache_directory,
339 int cache_size, 343 int cache_size,
340 bool force, 344 bool force,
341 const scoped_refptr<base::SingleThreadTaskRunner>& cache_thread, 345 const scoped_refptr<base::SingleThreadTaskRunner>& cache_thread,
342 const net::CompletionCallback& callback) { 346 const net::CompletionCallback& callback) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 NOTREACHED(); 397 NOTREACHED();
394 break; 398 break;
395 } 399 }
396 if (rv != net::ERR_IO_PENDING) 400 if (rv != net::ERR_IO_PENDING)
397 iter->callback.Run(rv); 401 iter->callback.Run(rv);
398 } 402 }
399 pending_calls_.clear(); 403 pending_calls_.clear();
400 } 404 }
401 405
402 } // namespace content 406 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/appcache/appcache_disk_cache.h ('k') | content/browser/appcache/appcache_response.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698