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

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

Issue 13731002: Cache Backend Proxy to intercept all cache events from the IO thread. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: trivial net.gyp merge 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/disk_cache_test_base.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) 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 #ifdef USE_TRACING_CACHE_BACKEND
15 #include "net/disk_cache/tracing_cache_backend.h"
16 #endif
17
14 namespace { 18 namespace {
15 19
16 // Builds an instance of the backend depending on platform, type, experiments 20 // 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 21 // etc. Takes care of the retry state. This object will self-destroy when
18 // finished. 22 // finished.
19 class CacheCreator { 23 class CacheCreator {
20 public: 24 public:
21 CacheCreator(const base::FilePath& path, bool force, int max_bytes, 25 CacheCreator(const base::FilePath& path, bool force, int max_bytes,
22 net::CacheType type, uint32 flags, 26 net::CacheType type, uint32 flags,
23 base::MessageLoopProxy* thread, net::NetLog* net_log, 27 base::MessageLoopProxy* thread, net::NetLog* net_log,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 new_cache->SetType(type_); 99 new_cache->SetType(type_);
96 new_cache->SetFlags(flags_); 100 new_cache->SetFlags(flags_);
97 int rv = new_cache->Init( 101 int rv = new_cache->Init(
98 base::Bind(&CacheCreator::OnIOComplete, base::Unretained(this))); 102 base::Bind(&CacheCreator::OnIOComplete, base::Unretained(this)));
99 DCHECK_EQ(net::ERR_IO_PENDING, rv); 103 DCHECK_EQ(net::ERR_IO_PENDING, rv);
100 return rv; 104 return rv;
101 } 105 }
102 106
103 void CacheCreator::DoCallback(int result) { 107 void CacheCreator::DoCallback(int result) {
104 DCHECK_NE(net::ERR_IO_PENDING, result); 108 DCHECK_NE(net::ERR_IO_PENDING, result);
105 if (result == net::OK) 109 if (result == net::OK) {
110 #ifndef USE_TRACING_CACHE_BACKEND
106 *backend_ = created_cache_; 111 *backend_ = created_cache_;
107 else { 112 #else
113 *backend_ = new disk_cache::TracingCacheBackend(created_cache_);
114 #endif
115 } else {
108 LOG(ERROR) << "Unable to create cache"; 116 LOG(ERROR) << "Unable to create cache";
109 *backend_ = NULL; 117 *backend_ = NULL;
110 delete created_cache_; 118 delete created_cache_;
111 } 119 }
112 callback_.Run(result); 120 callback_.Run(result);
113 delete this; 121 delete this;
114 } 122 }
115 123
116 // If the initialization of the cache fails, and |force| is true, we will 124 // If the initialization of the cache fails, and |force| is true, we will
117 // discard the whole cache and create a new one. 125 // discard the whole cache and create a new one.
(...skipping 29 matching lines...) Expand all
147 *backend = disk_cache::MemBackendImpl::CreateBackend(max_bytes, net_log); 155 *backend = disk_cache::MemBackendImpl::CreateBackend(max_bytes, net_log);
148 return *backend ? net::OK : net::ERR_FAILED; 156 return *backend ? net::OK : net::ERR_FAILED;
149 } 157 }
150 DCHECK(thread); 158 DCHECK(thread);
151 CacheCreator* creator = new CacheCreator(path, force, max_bytes, type, kNone, 159 CacheCreator* creator = new CacheCreator(path, force, max_bytes, type, kNone,
152 thread, net_log, backend, callback); 160 thread, net_log, backend, callback);
153 return creator->Run(); 161 return creator->Run();
154 } 162 }
155 163
156 } // namespace disk_cache 164 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/backend_unittest.cc ('k') | net/disk_cache/disk_cache_test_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698