OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/browser/cache_storage/cache_storage_blob_to_disk_cache.h" | 5 #include "content/browser/cache_storage/cache_storage_blob_to_disk_cache.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
11 #include "net/url_request/url_request_context.h" | 11 #include "net/url_request/url_request_context.h" |
12 #include "net/url_request/url_request_context_getter.h" | 12 #include "net/url_request/url_request_context_getter.h" |
13 #include "storage/browser/blob/blob_data_handle.h" | 13 #include "storage/browser/blob/blob_data_handle.h" |
14 #include "storage/browser/blob/blob_url_request_job_factory.h" | 14 #include "storage/browser/blob/blob_url_request_job_factory.h" |
| 15 #include "storage/common/storage_histograms.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
18 const int CacheStorageBlobToDiskCache::kBufferSize = 1024 * 512; | 19 const int CacheStorageBlobToDiskCache::kBufferSize = 1024 * 512; |
19 | 20 |
20 CacheStorageBlobToDiskCache::CacheStorageBlobToDiskCache() | 21 CacheStorageBlobToDiskCache::CacheStorageBlobToDiskCache() |
21 : cache_entry_offset_(0), | 22 : cache_entry_offset_(0), |
22 disk_cache_body_index_(0), | 23 disk_cache_body_index_(0), |
23 buffer_(new net::IOBufferWithSize(kBufferSize)), | 24 buffer_(new net::IOBufferWithSize(kBufferSize)), |
24 weak_ptr_factory_(this) { | 25 weak_ptr_factory_(this) { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 if (bytes_read != net::ERR_IO_PENDING) | 131 if (bytes_read != net::ERR_IO_PENDING) |
131 OnReadCompleted(blob_request_.get(), bytes_read); | 132 OnReadCompleted(blob_request_.get(), bytes_read); |
132 } | 133 } |
133 | 134 |
134 void CacheStorageBlobToDiskCache::DidWriteDataToEntry(int expected_bytes, | 135 void CacheStorageBlobToDiskCache::DidWriteDataToEntry(int expected_bytes, |
135 int rv) { | 136 int rv) { |
136 if (rv != expected_bytes) { | 137 if (rv != expected_bytes) { |
137 RunCallbackAndRemoveObserver(false); | 138 RunCallbackAndRemoveObserver(false); |
138 return; | 139 return; |
139 } | 140 } |
140 | 141 if (rv > 0) |
| 142 storage::RecordBytesWritten("DiskCache.CacheStorage", rv); |
141 cache_entry_offset_ += rv; | 143 cache_entry_offset_ += rv; |
142 ReadFromBlob(); | 144 ReadFromBlob(); |
143 } | 145 } |
144 | 146 |
145 void CacheStorageBlobToDiskCache::RunCallbackAndRemoveObserver(bool success) { | 147 void CacheStorageBlobToDiskCache::RunCallbackAndRemoveObserver(bool success) { |
146 DCHECK(request_context_getter_); | 148 DCHECK(request_context_getter_); |
147 | 149 |
148 request_context_getter_->RemoveObserver(this); | 150 request_context_getter_->RemoveObserver(this); |
149 blob_request_.reset(); | 151 blob_request_.reset(); |
150 callback_.Run(std::move(entry_), success); | 152 callback_.Run(std::move(entry_), success); |
151 } | 153 } |
152 | 154 |
153 } // namespace content | 155 } // namespace content |
OLD | NEW |