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

Side by Side Diff: content/browser/cache_storage/cache_storage_cache.cc

Issue 2858133002: Add uma stats to help evaluate the impact of changes to the quota allocation logic. (Closed)
Patch Set: macros Created 3 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_cache.h" 5 #include "content/browser/cache_storage/cache_storage_cache.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <limits> 9 #include <limits>
10 #include <memory> 10 #include <memory>
(...skipping 20 matching lines...) Expand all
31 #include "net/base/completion_callback.h" 31 #include "net/base/completion_callback.h"
32 #include "net/base/io_buffer.h" 32 #include "net/base/io_buffer.h"
33 #include "net/base/net_errors.h" 33 #include "net/base/net_errors.h"
34 #include "net/disk_cache/disk_cache.h" 34 #include "net/disk_cache/disk_cache.h"
35 #include "net/url_request/url_request_context_getter.h" 35 #include "net/url_request/url_request_context_getter.h"
36 #include "storage/browser/blob/blob_data_builder.h" 36 #include "storage/browser/blob/blob_data_builder.h"
37 #include "storage/browser/blob/blob_data_handle.h" 37 #include "storage/browser/blob/blob_data_handle.h"
38 #include "storage/browser/blob/blob_storage_context.h" 38 #include "storage/browser/blob/blob_storage_context.h"
39 #include "storage/browser/blob/blob_url_request_job_factory.h" 39 #include "storage/browser/blob/blob_url_request_job_factory.h"
40 #include "storage/browser/quota/quota_manager_proxy.h" 40 #include "storage/browser/quota/quota_manager_proxy.h"
41 #include "storage/common/storage_histograms.h"
41 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerResponseType.h" 42 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerResponseType.h"
42 43
43 namespace content { 44 namespace content {
44 45
45 namespace { 46 namespace {
46 47
47 const size_t kMaxQueryCacheResultBytes = 48 const size_t kMaxQueryCacheResultBytes =
48 1024 * 1024 * 10; // 10MB query cache limit 49 1024 * 1024 * 10; // 10MB query cache limit
49 50
51 const char kRecordBytesLabel[] = "DiskCache.CacheStorage";
52
50 // This class ensures that the cache and the entry have a lifetime as long as 53 // This class ensures that the cache and the entry have a lifetime as long as
51 // the blob that is created to contain them. 54 // the blob that is created to contain them.
52 class CacheStorageCacheDataHandle 55 class CacheStorageCacheDataHandle
53 : public storage::BlobDataBuilder::DataHandle { 56 : public storage::BlobDataBuilder::DataHandle {
54 public: 57 public:
55 CacheStorageCacheDataHandle( 58 CacheStorageCacheDataHandle(
56 std::unique_ptr<CacheStorageCacheHandle> cache_handle, 59 std::unique_ptr<CacheStorageCacheHandle> cache_handle,
57 disk_cache::ScopedEntryPtr entry) 60 disk_cache::ScopedEntryPtr entry)
58 : cache_handle_(std::move(cache_handle)), entry_(std::move(entry)) {} 61 : cache_handle_(std::move(cache_handle)), entry_(std::move(entry)) {}
59 62
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 181
179 void ReadMetadataDidReadMetadata(disk_cache::Entry* entry, 182 void ReadMetadataDidReadMetadata(disk_cache::Entry* entry,
180 const MetadataCallback& callback, 183 const MetadataCallback& callback,
181 scoped_refptr<net::IOBufferWithSize> buffer, 184 scoped_refptr<net::IOBufferWithSize> buffer,
182 int rv) { 185 int rv) {
183 if (rv != buffer->size()) { 186 if (rv != buffer->size()) {
184 callback.Run(std::unique_ptr<proto::CacheMetadata>()); 187 callback.Run(std::unique_ptr<proto::CacheMetadata>());
185 return; 188 return;
186 } 189 }
187 190
191 if (rv > 0)
192 storage::RecordBytesRead(kRecordBytesLabel, rv);
193
188 std::unique_ptr<proto::CacheMetadata> metadata(new proto::CacheMetadata()); 194 std::unique_ptr<proto::CacheMetadata> metadata(new proto::CacheMetadata());
189 195
190 if (!metadata->ParseFromArray(buffer->data(), buffer->size())) { 196 if (!metadata->ParseFromArray(buffer->data(), buffer->size())) {
191 callback.Run(std::unique_ptr<proto::CacheMetadata>()); 197 callback.Run(std::unique_ptr<proto::CacheMetadata>());
192 return; 198 return;
193 } 199 }
194 200
195 callback.Run(std::move(metadata)); 201 callback.Run(std::move(metadata));
196 } 202 }
197 203
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 void CacheStorageCache::WriteSideDataDidWrite(const ErrorCallback& callback, 1001 void CacheStorageCache::WriteSideDataDidWrite(const ErrorCallback& callback,
996 disk_cache::ScopedEntryPtr entry, 1002 disk_cache::ScopedEntryPtr entry,
997 int expected_bytes, 1003 int expected_bytes,
998 int rv) { 1004 int rv) {
999 if (rv != expected_bytes) { 1005 if (rv != expected_bytes) {
1000 entry->Doom(); 1006 entry->Doom();
1001 UpdateCacheSize(base::Bind(callback, CACHE_STORAGE_ERROR_NOT_FOUND)); 1007 UpdateCacheSize(base::Bind(callback, CACHE_STORAGE_ERROR_NOT_FOUND));
1002 return; 1008 return;
1003 } 1009 }
1004 1010
1011 if (rv > 0)
1012 storage::RecordBytesWritten(kRecordBytesLabel, rv);
1013
1005 UpdateCacheSize(base::Bind(callback, CACHE_STORAGE_OK)); 1014 UpdateCacheSize(base::Bind(callback, CACHE_STORAGE_OK));
1006 } 1015 }
1007 1016
1008 void CacheStorageCache::Put(const CacheStorageBatchOperation& operation, 1017 void CacheStorageCache::Put(const CacheStorageBatchOperation& operation,
1009 const ErrorCallback& callback) { 1018 const ErrorCallback& callback) {
1010 DCHECK(BACKEND_OPEN == backend_state_ || initializing_); 1019 DCHECK(BACKEND_OPEN == backend_state_ || initializing_);
1011 DCHECK_EQ(CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT, operation.operation_type); 1020 DCHECK_EQ(CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT, operation.operation_type);
1012 1021
1013 std::unique_ptr<ServiceWorkerFetchRequest> request( 1022 std::unique_ptr<ServiceWorkerFetchRequest> request(
1014 new ServiceWorkerFetchRequest( 1023 new ServiceWorkerFetchRequest(
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 void CacheStorageCache::PutDidWriteHeaders( 1175 void CacheStorageCache::PutDidWriteHeaders(
1167 std::unique_ptr<PutContext> put_context, 1176 std::unique_ptr<PutContext> put_context,
1168 int expected_bytes, 1177 int expected_bytes,
1169 int rv) { 1178 int rv) {
1170 if (rv != expected_bytes) { 1179 if (rv != expected_bytes) {
1171 put_context->cache_entry->Doom(); 1180 put_context->cache_entry->Doom();
1172 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); 1181 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE);
1173 return; 1182 return;
1174 } 1183 }
1175 1184
1185 if (rv > 0)
1186 storage::RecordBytesWritten(kRecordBytesLabel, rv);
1187
1176 // The metadata is written, now for the response content. The data is streamed 1188 // The metadata is written, now for the response content. The data is streamed
1177 // from the blob into the cache entry. 1189 // from the blob into the cache entry.
1178 1190
1179 if (put_context->response->blob_uuid.empty()) { 1191 if (put_context->response->blob_uuid.empty()) {
1180 UpdateCacheSize(base::Bind(put_context->callback, CACHE_STORAGE_OK)); 1192 UpdateCacheSize(base::Bind(put_context->callback, CACHE_STORAGE_OK));
1181 return; 1193 return;
1182 } 1194 }
1183 1195
1184 DCHECK(put_context->blob_data_handle); 1196 DCHECK(put_context->blob_data_handle);
1185 1197
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 temp_entry, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA); 1495 temp_entry, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA);
1484 return blob_storage_context_->AddFinishedBlob(&blob_data); 1496 return blob_storage_context_->AddFinishedBlob(&blob_data);
1485 } 1497 }
1486 1498
1487 std::unique_ptr<CacheStorageCacheHandle> 1499 std::unique_ptr<CacheStorageCacheHandle>
1488 CacheStorageCache::CreateCacheHandle() { 1500 CacheStorageCache::CreateCacheHandle() {
1489 return cache_storage_->CreateCacheHandle(this); 1501 return cache_storage_->CreateCacheHandle(this);
1490 } 1502 }
1491 1503
1492 } // namespace content 1504 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698