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

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

Issue 13813015: Separate Simple Backend creation from initialization. (Closed) Base URL: http://git.chromium.org/chromium/src.git@trace-2
Patch Set: 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
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"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 VLOG(1) << "Using the Simple Cache Backend.";
gavinp 2013/04/09 16:03:49 Maybe lose this VLOG?
pasko-google - do not use 2013/04/09 16:20:48 Done.
90 use_simple_cache_backend_ = true; 88 disk_cache::SimpleBackendImpl* simple_cache =
91 return disk_cache::SimpleBackendImpl::CreateBackend( 89 new disk_cache::SimpleBackendImpl(path_, max_bytes_, type_, thread_,
92 path_, max_bytes_, type_, disk_cache::kNone, thread_, net_log_, 90 net_log_);
93 backend_, base::Bind(&CacheCreator::OnIOComplete, 91 created_cache_ = simple_cache;
94 base::Unretained(this))); 92 return simple_cache->Init(
93 base::Bind(&CacheCreator::OnIOComplete, base::Unretained(this)));
95 } 94 }
96 } 95 }
97 disk_cache::BackendImpl* new_cache = 96 disk_cache::BackendImpl* new_cache =
98 new disk_cache::BackendImpl(path_, thread_, net_log_); 97 new disk_cache::BackendImpl(path_, thread_, net_log_);
99 created_cache_ = new_cache; 98 created_cache_ = new_cache;
100 new_cache->SetMaxSize(max_bytes_); 99 new_cache->SetMaxSize(max_bytes_);
101 new_cache->SetType(type_); 100 new_cache->SetType(type_);
102 new_cache->SetFlags(flags_); 101 new_cache->SetFlags(flags_);
103 int rv = new_cache->Init( 102 int rv = new_cache->Init(
104 base::Bind(&CacheCreator::OnIOComplete, base::Unretained(this))); 103 base::Bind(&CacheCreator::OnIOComplete, base::Unretained(this)));
105 DCHECK_EQ(net::ERR_IO_PENDING, rv); 104 DCHECK_EQ(net::ERR_IO_PENDING, rv);
106 return rv; 105 return rv;
107 } 106 }
108 107
109 void CacheCreator::DoCallback(int result) { 108 void CacheCreator::DoCallback(int result) {
110 DCHECK_NE(net::ERR_IO_PENDING, result); 109 DCHECK_NE(net::ERR_IO_PENDING, result);
111 if (result == net::OK) { 110 if (result == net::OK) {
112 // TODO(pasko): Separate creation of the Simple Backend from its 111 *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 112 #ifdef USE_TRACING_CACHE_BACKEND
119 *backend_ = new disk_cache::TracingCacheBackend(*backend_); 113 *backend_ = new disk_cache::TracingCacheBackend(created_cache_);
gavinp 2013/04/09 16:03:49 This change looks like a NOP. Is it a NOP?
pasko-google - do not use 2013/04/09 16:20:48 It is based on another change (https://codereview.
120 #endif 114 #endif
121 } else { 115 } else {
122 LOG(ERROR) << "Unable to create cache"; 116 LOG(ERROR) << "Unable to create cache";
123 *backend_ = NULL; 117 *backend_ = NULL;
124 delete created_cache_; 118 delete created_cache_;
125 } 119 }
126 callback_.Run(result); 120 callback_.Run(result);
127 delete this; 121 delete this;
128 } 122 }
129 123
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 *backend = disk_cache::MemBackendImpl::CreateBackend(max_bytes, net_log); 155 *backend = disk_cache::MemBackendImpl::CreateBackend(max_bytes, net_log);
162 return *backend ? net::OK : net::ERR_FAILED; 156 return *backend ? net::OK : net::ERR_FAILED;
163 } 157 }
164 DCHECK(thread); 158 DCHECK(thread);
165 CacheCreator* creator = new CacheCreator(path, force, max_bytes, type, kNone, 159 CacheCreator* creator = new CacheCreator(path, force, max_bytes, type, kNone,
166 thread, net_log, backend, callback); 160 thread, net_log, backend, callback);
167 return creator->Run(); 161 return creator->Run();
168 } 162 }
169 163
170 } // namespace disk_cache 164 } // namespace disk_cache
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/simple/simple_backend_impl.h » ('j') | net/disk_cache/simple/simple_backend_impl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698