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

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

Issue 13517004: Test cache creation retry via public interface only. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: check cache integrity after destroying the backend 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
« no previous file with comments | « net/disk_cache/backend_unittest.cc ('k') | net/disk_cache/cache_util.h » ('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) 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 bool use_simple_cache_backend_;
49
50 DISALLOW_COPY_AND_ASSIGN(CacheCreator);
51 };
15 52
16 CacheCreator::CacheCreator( 53 CacheCreator::CacheCreator(
17 const base::FilePath& path, bool force, int max_bytes, 54 const base::FilePath& path, bool force, int max_bytes,
18 net::CacheType type, uint32 flags, 55 net::CacheType type, uint32 flags,
19 base::MessageLoopProxy* thread, net::NetLog* net_log, 56 base::MessageLoopProxy* thread, net::NetLog* net_log,
20 disk_cache::Backend** backend, 57 disk_cache::Backend** backend,
21 const net::CompletionCallback& callback) 58 const net::CompletionCallback& callback)
22 : path_(path), 59 : path_(path),
23 force_(force), 60 force_(force),
24 retry_(false), 61 retry_(false),
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 created_cache_ = NULL; 133 created_cache_ = NULL;
97 if (!disk_cache::DelayedCacheCleanup(path_)) 134 if (!disk_cache::DelayedCacheCleanup(path_))
98 return DoCallback(result); 135 return DoCallback(result);
99 136
100 // The worker thread will start deleting files soon, but the original folder 137 // The worker thread will start deleting files soon, but the original folder
101 // is not there anymore... let's create a new set of files. 138 // is not there anymore... let's create a new set of files.
102 int rv = Run(); 139 int rv = Run();
103 DCHECK_EQ(net::ERR_IO_PENDING, rv); 140 DCHECK_EQ(net::ERR_IO_PENDING, rv);
104 } 141 }
105 142
143 } // namespace
144
145 namespace disk_cache {
146
106 int CreateCacheBackend(net::CacheType type, const base::FilePath& path, 147 int CreateCacheBackend(net::CacheType type, const base::FilePath& path,
107 int max_bytes, 148 int max_bytes,
108 bool force, base::MessageLoopProxy* thread, 149 bool force, base::MessageLoopProxy* thread,
109 net::NetLog* net_log, Backend** backend, 150 net::NetLog* net_log, Backend** backend,
110 const net::CompletionCallback& callback) { 151 const net::CompletionCallback& callback) {
111 DCHECK(!callback.is_null()); 152 DCHECK(!callback.is_null());
112 if (type == net::MEMORY_CACHE) { 153 if (type == net::MEMORY_CACHE) {
113 *backend = disk_cache::MemBackendImpl::CreateBackend(max_bytes, net_log); 154 *backend = disk_cache::MemBackendImpl::CreateBackend(max_bytes, net_log);
114 return *backend ? net::OK : net::ERR_FAILED; 155 return *backend ? net::OK : net::ERR_FAILED;
115 } 156 }
116 DCHECK(thread); 157 DCHECK(thread);
117 CacheCreator* creator = new CacheCreator(path, force, max_bytes, type, kNone, 158 CacheCreator* creator = new CacheCreator(path, force, max_bytes, type, kNone,
118 thread, net_log, backend, callback); 159 thread, net_log, backend, callback);
119 return creator->Run(); 160 return creator->Run();
120 } 161 }
121 162
122 163
123 } // namespace disk_cache 164 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/backend_unittest.cc ('k') | net/disk_cache/cache_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698