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

Side by Side Diff: net/disk_cache/backend_impl.cc

Issue 6339012: More net/ method ordering. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More done while waiting for previous patch to clear Created 9 years, 10 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 | « net/base/x509_certificate.cc ('k') | net/disk_cache/file_posix.cc » ('j') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/backend_impl.h" 5 #include "net/disk_cache/backend_impl.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 337
338 // Return 1% of the available space if it does not exceed kint32max. 338 // Return 1% of the available space if it does not exceed kint32max.
339 if (available < static_cast<int64>(kint32max) * 100) 339 if (available < static_cast<int64>(kint32max) * 100)
340 return static_cast<int32>(available / 100); 340 return static_cast<int32>(available / 100);
341 341
342 return kint32max; 342 return kint32max;
343 } 343 }
344 344
345 // ------------------------------------------------------------------------ 345 // ------------------------------------------------------------------------
346 346
347 // If the initialization of the cache fails, and force is true, we will discard
348 // the whole cache and create a new one. In order to process a potentially large
349 // number of files, we'll rename the cache folder to old_ + original_name +
350 // number, (located on the same parent folder), and spawn a worker thread to
351 // delete all the files on all the stale cache folders. The whole process can
352 // still fail if we are not able to rename the cache folder (for instance due to
353 // a sharing violation), and in that case a cache for this profile (on the
354 // desired path) cannot be created.
355 //
356 // Static.
357 int BackendImpl::CreateBackend(const FilePath& full_path, bool force,
358 int max_bytes, net::CacheType type,
359 uint32 flags, base::MessageLoopProxy* thread,
360 net::NetLog* net_log, Backend** backend,
361 CompletionCallback* callback) {
362 DCHECK(callback);
363 CacheCreator* creator = new CacheCreator(full_path, force, max_bytes, type,
364 flags, thread, net_log, backend,
365 callback);
366 // This object will self-destroy when finished.
367 return creator->Run();
368 }
369
370 int BackendImpl::Init(CompletionCallback* callback) {
371 background_queue_.Init(callback);
372 return net::ERR_IO_PENDING;
373 }
374
375 BackendImpl::BackendImpl(const FilePath& path, 347 BackendImpl::BackendImpl(const FilePath& path,
376 base::MessageLoopProxy* cache_thread, 348 base::MessageLoopProxy* cache_thread,
377 net::NetLog* net_log) 349 net::NetLog* net_log)
378 : ALLOW_THIS_IN_INITIALIZER_LIST(background_queue_(this, cache_thread)), 350 : ALLOW_THIS_IN_INITIALIZER_LIST(background_queue_(this, cache_thread)),
379 path_(path), 351 path_(path),
380 block_files_(path), 352 block_files_(path),
381 mask_(0), 353 mask_(0),
382 max_size_(0), 354 max_size_(0),
383 io_delay_(0), 355 io_delay_(0),
384 cache_type_(net::DISK_CACHE), 356 cache_type_(net::DISK_CACHE),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 if (background_queue_.BackgroundIsCurrentThread()) { 401 if (background_queue_.BackgroundIsCurrentThread()) {
430 // Unit tests may use the same thread for everything. 402 // Unit tests may use the same thread for everything.
431 CleanupCache(); 403 CleanupCache();
432 } else { 404 } else {
433 background_queue_.background_thread()->PostTask(FROM_HERE, 405 background_queue_.background_thread()->PostTask(FROM_HERE,
434 new FinalCleanup(this)); 406 new FinalCleanup(this));
435 done_.Wait(); 407 done_.Wait();
436 } 408 }
437 } 409 }
438 410
439 // ------------------------------------------------------------------------ 411 // If the initialization of the cache fails, and force is true, we will discard
412 // the whole cache and create a new one. In order to process a potentially large
413 // number of files, we'll rename the cache folder to old_ + original_name +
414 // number, (located on the same parent folder), and spawn a worker thread to
415 // delete all the files on all the stale cache folders. The whole process can
416 // still fail if we are not able to rename the cache folder (for instance due to
417 // a sharing violation), and in that case a cache for this profile (on the
418 // desired path) cannot be created.
419 //
420 // Static.
421 int BackendImpl::CreateBackend(const FilePath& full_path, bool force,
422 int max_bytes, net::CacheType type,
423 uint32 flags, base::MessageLoopProxy* thread,
424 net::NetLog* net_log, Backend** backend,
425 CompletionCallback* callback) {
426 DCHECK(callback);
427 CacheCreator* creator = new CacheCreator(full_path, force, max_bytes, type,
428 flags, thread, net_log, backend,
429 callback);
430 // This object will self-destroy when finished.
431 return creator->Run();
432 }
433
434 int BackendImpl::Init(CompletionCallback* callback) {
435 background_queue_.Init(callback);
436 return net::ERR_IO_PENDING;
437 }
440 438
441 int BackendImpl::SyncInit() { 439 int BackendImpl::SyncInit() {
442 DCHECK(!init_); 440 DCHECK(!init_);
443 if (init_) 441 if (init_)
444 return net::ERR_FAILED; 442 return net::ERR_FAILED;
445 443
446 bool create_files = false; 444 bool create_files = false;
447 if (!InitBackingStore(&create_files)) { 445 if (!InitBackingStore(&create_files)) {
448 ReportError(ERR_STORAGE_ERROR); 446 ReportError(ERR_STORAGE_ERROR);
449 return net::ERR_FAILED; 447 return net::ERR_FAILED;
(...skipping 1687 matching lines...) Expand 10 before | Expand all | Expand 10 after
2137 if (total_memory > kMaxBuffersSize || total_memory <= 0) 2135 if (total_memory > kMaxBuffersSize || total_memory <= 0)
2138 total_memory = kMaxBuffersSize; 2136 total_memory = kMaxBuffersSize;
2139 2137
2140 done = true; 2138 done = true;
2141 } 2139 }
2142 2140
2143 return static_cast<int>(total_memory); 2141 return static_cast<int>(total_memory);
2144 } 2142 }
2145 2143
2146 } // namespace disk_cache 2144 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/base/x509_certificate.cc ('k') | net/disk_cache/file_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698