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 "storage/browser/blob/blob_reader.h" | 5 #include "storage/browser/blob/blob_reader.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <limits> | 11 #include <limits> |
12 #include <memory> | 12 #include <memory> |
13 #include <utility> | 13 #include <utility> |
14 | 14 |
15 #include "base/bind.h" | 15 #include "base/bind.h" |
16 #include "base/callback_helpers.h" | 16 #include "base/callback_helpers.h" |
17 #include "base/debug/stack_trace.h" | 17 #include "base/debug/stack_trace.h" |
18 #include "base/sequenced_task_runner.h" | 18 #include "base/sequenced_task_runner.h" |
19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
20 #include "base/trace_event/trace_event.h" | 20 #include "base/trace_event/trace_event.h" |
21 #include "net/base/io_buffer.h" | 21 #include "net/base/io_buffer.h" |
22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
23 #include "net/disk_cache/disk_cache.h" | 23 #include "net/disk_cache/disk_cache.h" |
24 #include "storage/browser/blob/blob_data_handle.h" | 24 #include "storage/browser/blob/blob_data_handle.h" |
25 #include "storage/browser/blob/blob_data_snapshot.h" | 25 #include "storage/browser/blob/blob_data_snapshot.h" |
26 #include "storage/browser/fileapi/file_stream_reader.h" | 26 #include "storage/browser/fileapi/file_stream_reader.h" |
27 #include "storage/browser/fileapi/file_system_context.h" | 27 #include "storage/browser/fileapi/file_system_context.h" |
28 #include "storage/browser/fileapi/file_system_url.h" | 28 #include "storage/browser/fileapi/file_system_url.h" |
29 #include "storage/common/data_element.h" | 29 #include "storage/common/data_element.h" |
| 30 #include "storage/common/storage_histograms.h" |
30 | 31 |
31 namespace storage { | 32 namespace storage { |
32 namespace { | 33 namespace { |
| 34 const char kCacheStorageRecordBytesLabel[] = "DiskCache.CacheStorage"; |
| 35 |
33 bool IsFileType(DataElement::Type type) { | 36 bool IsFileType(DataElement::Type type) { |
34 switch (type) { | 37 switch (type) { |
35 case DataElement::TYPE_FILE: | 38 case DataElement::TYPE_FILE: |
36 case DataElement::TYPE_FILE_FILESYSTEM: | 39 case DataElement::TYPE_FILE_FILESYSTEM: |
37 return true; | 40 return true; |
38 default: | 41 default: |
39 return false; | 42 return false; |
40 } | 43 } |
41 } | 44 } |
42 | 45 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 if (result == net::ERR_IO_PENDING) | 141 if (result == net::ERR_IO_PENDING) |
139 return Status::IO_PENDING; | 142 return Status::IO_PENDING; |
140 return ReportError(result); | 143 return ReportError(result); |
141 } | 144 } |
142 | 145 |
143 void BlobReader::DidReadDiskCacheEntrySideData(const StatusCallback& done, | 146 void BlobReader::DidReadDiskCacheEntrySideData(const StatusCallback& done, |
144 int expected_size, | 147 int expected_size, |
145 int result) { | 148 int result) { |
146 if (result >= 0) { | 149 if (result >= 0) { |
147 DCHECK_EQ(expected_size, result); | 150 DCHECK_EQ(expected_size, result); |
| 151 if (result > 0) |
| 152 storage::RecordBytesRead(kCacheStorageRecordBytesLabel, result); |
148 done.Run(Status::DONE); | 153 done.Run(Status::DONE); |
149 return; | 154 return; |
150 } | 155 } |
151 side_data_ = nullptr; | 156 side_data_ = nullptr; |
152 done.Run(ReportError(result)); | 157 done.Run(ReportError(result)); |
153 } | 158 } |
154 | 159 |
155 BlobReader::Status BlobReader::SetReadRange(uint64_t offset, uint64_t length) { | 160 BlobReader::Status BlobReader::SetReadRange(uint64_t offset, uint64_t length) { |
156 if (!blob_handle_.get() || blob_handle_->IsBroken()) { | 161 if (!blob_handle_.get() || blob_handle_->IsBroken()) { |
157 return ReportError(net::ERR_FILE_NOT_FOUND); | 162 return ReportError(net::ERR_FILE_NOT_FOUND); |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 if (result == net::ERR_IO_PENDING) { | 582 if (result == net::ERR_IO_PENDING) { |
578 io_pending_ = true; | 583 io_pending_ = true; |
579 return Status::IO_PENDING; | 584 return Status::IO_PENDING; |
580 } | 585 } |
581 return ReportError(result); | 586 return ReportError(result); |
582 } | 587 } |
583 | 588 |
584 void BlobReader::DidReadDiskCacheEntry(int result) { | 589 void BlobReader::DidReadDiskCacheEntry(int result) { |
585 TRACE_EVENT_ASYNC_END1("Blob", "BlobRequest::ReadDiskCacheItem", this, "uuid", | 590 TRACE_EVENT_ASYNC_END1("Blob", "BlobRequest::ReadDiskCacheItem", this, "uuid", |
586 blob_data_->uuid()); | 591 blob_data_->uuid()); |
| 592 if (result > 0) |
| 593 storage::RecordBytesRead(kCacheStorageRecordBytesLabel, result); |
587 DidReadItem(result); | 594 DidReadItem(result); |
588 } | 595 } |
589 | 596 |
590 void BlobReader::DidReadItem(int result) { | 597 void BlobReader::DidReadItem(int result) { |
591 DCHECK(io_pending_) << "Asynchronous IO completed while IO wasn't pending?"; | 598 DCHECK(io_pending_) << "Asynchronous IO completed while IO wasn't pending?"; |
592 io_pending_ = false; | 599 io_pending_ = false; |
593 if (result <= 0) { | 600 if (result <= 0) { |
594 InvalidateCallbacksAndDone(result, read_callback_); | 601 InvalidateCallbacksAndDone(result, read_callback_); |
595 return; | 602 return; |
596 } | 603 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 void BlobReader::SetFileReaderAtIndex( | 676 void BlobReader::SetFileReaderAtIndex( |
670 size_t index, | 677 size_t index, |
671 std::unique_ptr<FileStreamReader> reader) { | 678 std::unique_ptr<FileStreamReader> reader) { |
672 if (reader) | 679 if (reader) |
673 index_to_reader_[index] = std::move(reader); | 680 index_to_reader_[index] = std::move(reader); |
674 else | 681 else |
675 index_to_reader_.erase(index); | 682 index_to_reader_.erase(index); |
676 } | 683 } |
677 | 684 |
678 } // namespace storage | 685 } // namespace storage |
OLD | NEW |