| 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 "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/metrics/field_trial.h" | 6 #include "base/metrics/field_trial.h" |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
| 9 #include "net/disk_cache/backend_impl.h" | 9 #include "net/disk_cache/backend_impl.h" |
| 10 #include "net/disk_cache/cache_util.h" | 10 #include "net/disk_cache/cache_util.h" |
| 11 #include "net/disk_cache/mem_backend_impl.h" | 11 #include "net/disk_cache/mem_backend_impl.h" |
| 12 #include "net/disk_cache/simple/simple_backend_impl.h" | 12 #include "net/disk_cache/simple/simple_backend_impl.h" |
| 13 | 13 |
| 14 namespace disk_cache { | 14 namespace { |
| 15 |
| 16 // Builds an instance of the backend depending on platform, type, experiments |
| 17 // etc. Takes care of the retry state. This object will self-destroy when |
| 18 // finished. |
| 19 class CacheCreator { |
| 20 public: |
| 21 CacheCreator(const base::FilePath& path, bool force, int max_bytes, |
| 22 net::CacheType type, uint32 flags, |
| 23 base::MessageLoopProxy* thread, net::NetLog* net_log, |
| 24 disk_cache::Backend** backend, |
| 25 const net::CompletionCallback& callback); |
| 26 |
| 27 // Creates the backend. |
| 28 int Run(); |
| 29 |
| 30 private: |
| 31 ~CacheCreator(); |
| 32 |
| 33 void DoCallback(int result); |
| 34 |
| 35 void OnIOComplete(int result); |
| 36 |
| 37 const base::FilePath& path_; |
| 38 bool force_; |
| 39 bool retry_; |
| 40 int max_bytes_; |
| 41 net::CacheType type_; |
| 42 uint32 flags_; |
| 43 scoped_refptr<base::MessageLoopProxy> thread_; |
| 44 disk_cache::Backend** backend_; |
| 45 net::CompletionCallback callback_; |
| 46 disk_cache::Backend* created_cache_; |
| 47 net::NetLog* net_log_; |
| 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(CacheCreator); |
| 50 }; |
| 15 | 51 |
| 16 CacheCreator::CacheCreator( | 52 CacheCreator::CacheCreator( |
| 17 const base::FilePath& path, bool force, int max_bytes, | 53 const base::FilePath& path, bool force, int max_bytes, |
| 18 net::CacheType type, uint32 flags, | 54 net::CacheType type, uint32 flags, |
| 19 base::MessageLoopProxy* thread, net::NetLog* net_log, | 55 base::MessageLoopProxy* thread, net::NetLog* net_log, |
| 20 disk_cache::Backend** backend, | 56 disk_cache::Backend** backend, |
| 21 const net::CompletionCallback& callback) | 57 const net::CompletionCallback& callback) |
| 22 : path_(path), | 58 : path_(path), |
| 23 force_(force), | 59 force_(force), |
| 24 retry_(false), | 60 retry_(false), |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 created_cache_ = NULL; | 125 created_cache_ = NULL; |
| 90 if (!disk_cache::DelayedCacheCleanup(path_)) | 126 if (!disk_cache::DelayedCacheCleanup(path_)) |
| 91 return DoCallback(result); | 127 return DoCallback(result); |
| 92 | 128 |
| 93 // The worker thread will start deleting files soon, but the original folder | 129 // The worker thread will start deleting files soon, but the original folder |
| 94 // is not there anymore... let's create a new set of files. | 130 // is not there anymore... let's create a new set of files. |
| 95 int rv = Run(); | 131 int rv = Run(); |
| 96 DCHECK_EQ(net::ERR_IO_PENDING, rv); | 132 DCHECK_EQ(net::ERR_IO_PENDING, rv); |
| 97 } | 133 } |
| 98 | 134 |
| 135 } // namespace |
| 136 |
| 137 namespace disk_cache { |
| 138 |
| 99 int CreateCacheBackend(net::CacheType type, const base::FilePath& path, | 139 int CreateCacheBackend(net::CacheType type, const base::FilePath& path, |
| 100 int max_bytes, | 140 int max_bytes, |
| 101 bool force, base::MessageLoopProxy* thread, | 141 bool force, base::MessageLoopProxy* thread, |
| 102 net::NetLog* net_log, Backend** backend, | 142 net::NetLog* net_log, Backend** backend, |
| 103 const net::CompletionCallback& callback) { | 143 const net::CompletionCallback& callback) { |
| 104 DCHECK(!callback.is_null()); | 144 DCHECK(!callback.is_null()); |
| 105 if (type == net::MEMORY_CACHE) { | 145 if (type == net::MEMORY_CACHE) { |
| 106 *backend = disk_cache::MemBackendImpl::CreateBackend(max_bytes, net_log); | 146 *backend = disk_cache::MemBackendImpl::CreateBackend(max_bytes, net_log); |
| 107 return *backend ? net::OK : net::ERR_FAILED; | 147 return *backend ? net::OK : net::ERR_FAILED; |
| 108 } | 148 } |
| 109 DCHECK(thread); | 149 DCHECK(thread); |
| 110 CacheCreator* creator = new CacheCreator(path, force, max_bytes, type, kNone, | 150 CacheCreator* creator = new CacheCreator(path, force, max_bytes, type, kNone, |
| 111 thread, net_log, backend, callback); | 151 thread, net_log, backend, callback); |
| 112 return creator->Run(); | 152 return creator->Run(); |
| 113 } | 153 } |
| 114 | 154 |
| 115 | 155 |
| 116 } // namespace disk_cache | 156 } // namespace disk_cache |
| OLD | NEW |