| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/nacl_host/pnacl_translation_cache.h" | 5 #include "chrome/browser/nacl_host/pnacl_translation_cache.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 if (rv != net::ERR_IO_PENDING) | 156 if (rv != net::ERR_IO_PENDING) |
| 157 DispatchNext(rv); | 157 DispatchNext(rv); |
| 158 } | 158 } |
| 159 | 159 |
| 160 void PNaClTranslationCacheEntry::WriteEntry(int offset, int len) { | 160 void PNaClTranslationCacheEntry::WriteEntry(int offset, int len) { |
| 161 scoped_refptr<net::StringIOBuffer> io_buf = | 161 scoped_refptr<net::StringIOBuffer> io_buf = |
| 162 new net::StringIOBuffer(write_nexe_.substr(offset, len)); | 162 new net::StringIOBuffer(write_nexe_.substr(offset, len)); |
| 163 int rv = entry_->WriteData( | 163 int rv = entry_->WriteData( |
| 164 1, | 164 1, |
| 165 offset, | 165 offset, |
| 166 io_buf, | 166 io_buf.get(), |
| 167 len, | 167 len, |
| 168 base::Bind(&PNaClTranslationCacheEntry::DispatchNext, this), | 168 base::Bind(&PNaClTranslationCacheEntry::DispatchNext, this), |
| 169 false); | 169 false); |
| 170 if (rv != net::ERR_IO_PENDING) | 170 if (rv != net::ERR_IO_PENDING) |
| 171 DispatchNext(rv); | 171 DispatchNext(rv); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void PNaClTranslationCacheEntry::ReadEntry(int offset, int len) { | 174 void PNaClTranslationCacheEntry::ReadEntry(int offset, int len) { |
| 175 read_buf_ = new net::IOBufferWithSize(len); | 175 read_buf_ = new net::IOBufferWithSize(len); |
| 176 int rv = entry_->ReadData( | 176 int rv = entry_->ReadData( |
| 177 1, | 177 1, |
| 178 offset, | 178 offset, |
| 179 read_buf_, | 179 read_buf_.get(), |
| 180 len, | 180 len, |
| 181 base::Bind(&PNaClTranslationCacheEntry::DispatchNext, this)); | 181 base::Bind(&PNaClTranslationCacheEntry::DispatchNext, this)); |
| 182 if (rv != net::ERR_IO_PENDING) | 182 if (rv != net::ERR_IO_PENDING) |
| 183 DispatchNext(rv); | 183 DispatchNext(rv); |
| 184 } | 184 } |
| 185 | 185 |
| 186 int PNaClTranslationCacheEntry::GetTransferSize() { | 186 int PNaClTranslationCacheEntry::GetTransferSize() { |
| 187 if (is_read_) { | 187 if (is_read_) { |
| 188 DCHECK(entry_); | 188 DCHECK(entry_); |
| 189 return entry_->GetDataSize(1); | 189 return entry_->GetDataSize(1); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 int PNaClTranslationCache::Init(net::CacheType cache_type, | 308 int PNaClTranslationCache::Init(net::CacheType cache_type, |
| 309 const base::FilePath& cache_dir, | 309 const base::FilePath& cache_dir, |
| 310 int cache_size, | 310 int cache_size, |
| 311 const CompletionCallback& callback) { | 311 const CompletionCallback& callback) { |
| 312 int rv = disk_cache::CreateCacheBackend( | 312 int rv = disk_cache::CreateCacheBackend( |
| 313 cache_type, | 313 cache_type, |
| 314 net::CACHE_BACKEND_DEFAULT, | 314 net::CACHE_BACKEND_DEFAULT, |
| 315 cache_dir, | 315 cache_dir, |
| 316 cache_size, | 316 cache_size, |
| 317 true /* force_initialize */, | 317 true /* force_initialize */, |
| 318 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE), | 318 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE).get(), |
| 319 NULL, /* dummy net log */ | 319 NULL, /* dummy net log */ |
| 320 &disk_cache_, | 320 &disk_cache_, |
| 321 base::Bind(&PNaClTranslationCache::OnCreateBackendComplete, AsWeakPtr())); | 321 base::Bind(&PNaClTranslationCache::OnCreateBackendComplete, AsWeakPtr())); |
| 322 init_callback_ = callback; | 322 init_callback_ = callback; |
| 323 if (rv != net::ERR_IO_PENDING) { | 323 if (rv != net::ERR_IO_PENDING) { |
| 324 OnCreateBackendComplete(rv); | 324 OnCreateBackendComplete(rv); |
| 325 } | 325 } |
| 326 return rv; | 326 return rv; |
| 327 } | 327 } |
| 328 | 328 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 return rv; | 376 return rv; |
| 377 } | 377 } |
| 378 | 378 |
| 379 int PNaClTranslationCache::Size() { | 379 int PNaClTranslationCache::Size() { |
| 380 if (!disk_cache_) | 380 if (!disk_cache_) |
| 381 return -1; | 381 return -1; |
| 382 return disk_cache_->GetEntryCount(); | 382 return disk_cache_->GetEntryCount(); |
| 383 } | 383 } |
| 384 | 384 |
| 385 } // namespace pnacl_cache | 385 } // namespace pnacl_cache |
| OLD | NEW |