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" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 bool force_; | 42 bool force_; |
43 bool retry_; | 43 bool retry_; |
44 int max_bytes_; | 44 int max_bytes_; |
45 net::CacheType type_; | 45 net::CacheType type_; |
46 uint32 flags_; | 46 uint32 flags_; |
47 scoped_refptr<base::MessageLoopProxy> thread_; | 47 scoped_refptr<base::MessageLoopProxy> thread_; |
48 disk_cache::Backend** backend_; | 48 disk_cache::Backend** backend_; |
49 net::CompletionCallback callback_; | 49 net::CompletionCallback callback_; |
50 disk_cache::Backend* created_cache_; | 50 disk_cache::Backend* created_cache_; |
51 net::NetLog* net_log_; | 51 net::NetLog* net_log_; |
52 bool use_simple_cache_backend_; | |
53 | 52 |
54 DISALLOW_COPY_AND_ASSIGN(CacheCreator); | 53 DISALLOW_COPY_AND_ASSIGN(CacheCreator); |
55 }; | 54 }; |
56 | 55 |
57 CacheCreator::CacheCreator( | 56 CacheCreator::CacheCreator( |
58 const base::FilePath& path, bool force, int max_bytes, | 57 const base::FilePath& path, bool force, int max_bytes, |
59 net::CacheType type, uint32 flags, | 58 net::CacheType type, uint32 flags, |
60 base::MessageLoopProxy* thread, net::NetLog* net_log, | 59 base::MessageLoopProxy* thread, net::NetLog* net_log, |
61 disk_cache::Backend** backend, | 60 disk_cache::Backend** backend, |
62 const net::CompletionCallback& callback) | 61 const net::CompletionCallback& callback) |
63 : path_(path), | 62 : path_(path), |
64 force_(force), | 63 force_(force), |
65 retry_(false), | 64 retry_(false), |
66 max_bytes_(max_bytes), | 65 max_bytes_(max_bytes), |
67 type_(type), | 66 type_(type), |
68 flags_(flags), | 67 flags_(flags), |
69 thread_(thread), | 68 thread_(thread), |
70 backend_(backend), | 69 backend_(backend), |
71 callback_(callback), | 70 callback_(callback), |
72 created_cache_(NULL), | 71 created_cache_(NULL), |
73 net_log_(net_log), | 72 net_log_(net_log) { |
74 use_simple_cache_backend_(false) { | |
75 } | 73 } |
76 | 74 |
77 CacheCreator::~CacheCreator() { | 75 CacheCreator::~CacheCreator() { |
78 } | 76 } |
79 | 77 |
80 int CacheCreator::Run() { | 78 int CacheCreator::Run() { |
81 // TODO(pasko): The two caches should never coexist on disk. Each individual | 79 // TODO(pasko): The two caches should never coexist on disk. Each individual |
82 // cache backend should fail to initialize if it observes the index that does | 80 // cache backend should fail to initialize if it observes the index that does |
83 // not belong to it. | 81 // not belong to it. |
84 if (base::FieldTrialList::FindFullName("SimpleCacheTrial") == "Yes") { | 82 if (base::FieldTrialList::FindFullName("SimpleCacheTrial") == "Yes") { |
85 // TODO(gavinp,pasko): While simple backend development proceeds, we're only | 83 // TODO(gavinp,pasko): While simple backend development proceeds, we're only |
86 // testing it against net::DISK_CACHE. Turn it on for more cache types as | 84 // testing it against net::DISK_CACHE. Turn it on for more cache types as |
87 // appropriate. | 85 // appropriate. |
88 if (type_ == net::DISK_CACHE) { | 86 if (type_ == net::DISK_CACHE) { |
89 VLOG(1) << "Using the Simple Cache Backend."; | 87 disk_cache::SimpleBackendImpl* simple_cache = |
90 use_simple_cache_backend_ = true; | 88 new disk_cache::SimpleBackendImpl(path_, max_bytes_, type_, thread_, |
91 return disk_cache::SimpleBackendImpl::CreateBackend( | 89 net_log_); |
92 path_, max_bytes_, type_, disk_cache::kNone, thread_, net_log_, | 90 created_cache_ = simple_cache; |
93 backend_, base::Bind(&CacheCreator::OnIOComplete, | 91 return simple_cache->Init( |
94 base::Unretained(this))); | 92 base::Bind(&CacheCreator::OnIOComplete, base::Unretained(this))); |
95 } | 93 } |
96 } | 94 } |
97 disk_cache::BackendImpl* new_cache = | 95 disk_cache::BackendImpl* new_cache = |
98 new disk_cache::BackendImpl(path_, thread_, net_log_); | 96 new disk_cache::BackendImpl(path_, thread_, net_log_); |
99 created_cache_ = new_cache; | 97 created_cache_ = new_cache; |
100 new_cache->SetMaxSize(max_bytes_); | 98 new_cache->SetMaxSize(max_bytes_); |
101 new_cache->SetType(type_); | 99 new_cache->SetType(type_); |
102 new_cache->SetFlags(flags_); | 100 new_cache->SetFlags(flags_); |
103 int rv = new_cache->Init( | 101 int rv = new_cache->Init( |
104 base::Bind(&CacheCreator::OnIOComplete, base::Unretained(this))); | 102 base::Bind(&CacheCreator::OnIOComplete, base::Unretained(this))); |
105 DCHECK_EQ(net::ERR_IO_PENDING, rv); | 103 DCHECK_EQ(net::ERR_IO_PENDING, rv); |
106 return rv; | 104 return rv; |
107 } | 105 } |
108 | 106 |
109 void CacheCreator::DoCallback(int result) { | 107 void CacheCreator::DoCallback(int result) { |
110 DCHECK_NE(net::ERR_IO_PENDING, result); | 108 DCHECK_NE(net::ERR_IO_PENDING, result); |
111 if (result == net::OK) { | 109 if (result == net::OK) { |
112 // TODO(pasko): Separate creation of the Simple Backend from its | 110 *backend_ = created_cache_; |
113 // initialization, eliminate unnecessary use_simple_cache_backend_. | |
114 if (use_simple_cache_backend_) | |
115 created_cache_ = *backend_; | |
116 else | |
117 *backend_ = created_cache_; | |
118 #ifdef USE_TRACING_CACHE_BACKEND | 111 #ifdef USE_TRACING_CACHE_BACKEND |
rvargas (doing something else)
2013/04/09 19:16:07
I should not be seeing this!
gavinp
2013/04/10 10:04:39
I'm confused. Since this CL is downstream from htt
rvargas (doing something else)
2013/04/10 18:50:11
No, I'm not saying that I don't understand what th
| |
119 *backend_ = new disk_cache::TracingCacheBackend(*backend_); | 112 *backend_ = new disk_cache::TracingCacheBackend(created_cache_); |
120 #endif | 113 #endif |
121 } else { | 114 } else { |
122 LOG(ERROR) << "Unable to create cache"; | 115 LOG(ERROR) << "Unable to create cache"; |
123 *backend_ = NULL; | 116 *backend_ = NULL; |
124 delete created_cache_; | 117 delete created_cache_; |
125 } | 118 } |
126 callback_.Run(result); | 119 callback_.Run(result); |
127 delete this; | 120 delete this; |
128 } | 121 } |
129 | 122 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 *backend = disk_cache::MemBackendImpl::CreateBackend(max_bytes, net_log); | 154 *backend = disk_cache::MemBackendImpl::CreateBackend(max_bytes, net_log); |
162 return *backend ? net::OK : net::ERR_FAILED; | 155 return *backend ? net::OK : net::ERR_FAILED; |
163 } | 156 } |
164 DCHECK(thread); | 157 DCHECK(thread); |
165 CacheCreator* creator = new CacheCreator(path, force, max_bytes, type, kNone, | 158 CacheCreator* creator = new CacheCreator(path, force, max_bytes, type, kNone, |
166 thread, net_log, backend, callback); | 159 thread, net_log, backend, callback); |
167 return creator->Run(); | 160 return creator->Run(); |
168 } | 161 } |
169 | 162 |
170 } // namespace disk_cache | 163 } // namespace disk_cache |
OLD | NEW |