| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_BUFFER_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_BUFFER_H_ |
| 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_BUFFER_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_BUFFER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 typedef std::pair<scoped_refptr<net::IOBuffer>, size_t> ContentElement; | 22 typedef std::pair<scoped_refptr<net::IOBuffer>, size_t> ContentElement; |
| 23 typedef std::vector<ContentElement> ContentVector; | 23 typedef std::vector<ContentElement> ContentVector; |
| 24 | 24 |
| 25 // Helper function for ContentVector. | 25 // Helper function for ContentVector. |
| 26 // Assembles the data from |contents| and returns it in an |IOBuffer|. | 26 // Assembles the data from |contents| and returns it in an |IOBuffer|. |
| 27 // The number of bytes in the |IOBuffer| is returned in |*num_bytes| | 27 // The number of bytes in the |IOBuffer| is returned in |*num_bytes| |
| 28 // (if |num_bytes| is not NULL). | 28 // (if |num_bytes| is not NULL). |
| 29 // If |contents| is empty, returns NULL as an |IOBuffer| is not allowed | 29 // If |contents| is empty, returns NULL as an |IOBuffer| is not allowed |
| 30 // to have 0 bytes. | 30 // to have 0 bytes. |
| 31 net::IOBuffer* AssembleData(const ContentVector& contents, size_t* num_bytes); | 31 CONTENT_EXPORT net::IOBuffer* AssembleData(const ContentVector& contents, |
| 32 size_t* num_bytes); |
| 32 | 33 |
| 33 // |DownloadBuffer| is a thread-safe wrapper around |ContentVector|. | 34 // |DownloadBuffer| is a thread-safe wrapper around |ContentVector|. |
| 34 // | 35 // |
| 35 // It is created and populated on the IO thread, and passed to the | 36 // It is created and populated on the IO thread, and passed to the |
| 36 // FILE thread for writing. In order to avoid flooding the FILE thread with | 37 // FILE thread for writing. In order to avoid flooding the FILE thread with |
| 37 // too many small write messages, each write is appended to the | 38 // too many small write messages, each write is appended to the |
| 38 // |DownloadBuffer| while waiting for the task to run on the FILE | 39 // |DownloadBuffer| while waiting for the task to run on the FILE |
| 39 // thread. Access to the write buffers is synchronized via the lock. | 40 // thread. Access to the write buffers is synchronized via the lock. |
| 40 class CONTENT_EXPORT DownloadBuffer : | 41 class CONTENT_EXPORT DownloadBuffer : |
| 41 public base::RefCountedThreadSafe<DownloadBuffer> { | 42 public base::RefCountedThreadSafe<DownloadBuffer> { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 61 | 62 |
| 62 mutable base::Lock lock_; | 63 mutable base::Lock lock_; |
| 63 ContentVector contents_; | 64 ContentVector contents_; |
| 64 | 65 |
| 65 DISALLOW_COPY_AND_ASSIGN(DownloadBuffer); | 66 DISALLOW_COPY_AND_ASSIGN(DownloadBuffer); |
| 66 }; | 67 }; |
| 67 | 68 |
| 68 } // namespace content | 69 } // namespace content |
| 69 | 70 |
| 70 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_BUFFER_H_ | 71 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_BUFFER_H_ |
| OLD | NEW |