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

Side by Side Diff: content/browser/streams/stream.h

Issue 22908008: Limit the total memory usage for Stream instances (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #ifndef CONTENT_BROWSER_STREAMS_STREAM_H_ 5 #ifndef CONTENT_BROWSER_STREAMS_STREAM_H_
6 #define CONTENT_BROWSER_STREAMS_STREAM_H_ 6 #define CONTENT_BROWSER_STREAMS_STREAM_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 scoped_ptr<StreamHandle> CreateHandle(const GURL& original_url, 75 scoped_ptr<StreamHandle> CreateHandle(const GURL& original_url,
76 const std::string& mime_type); 76 const std::string& mime_type);
77 void CloseHandle(); 77 void CloseHandle();
78 78
79 // Indicates whether there is space in the buffer to add more data. 79 // Indicates whether there is space in the buffer to add more data.
80 bool can_add_data() const { return can_add_data_; } 80 bool can_add_data() const { return can_add_data_; }
81 81
82 const GURL& url() const { return url_; } 82 const GURL& url() const { return url_; }
83 83
84 // For StreamRegistry to remember the last memory usage reported to it.
85 size_t last_total_buffered_bytes() const {
86 return last_total_buffered_bytes_;
87 }
88
84 private: 89 private:
85 friend class base::RefCountedThreadSafe<Stream>; 90 friend class base::RefCountedThreadSafe<Stream>;
86 91
87 virtual ~Stream(); 92 virtual ~Stream();
88 93
89 void OnSpaceAvailable(); 94 void OnSpaceAvailable();
90 void OnDataAvailable(); 95 void OnDataAvailable();
91 96
92 size_t data_bytes_read_; 97 size_t data_bytes_read_;
93 bool can_add_data_; 98 bool can_add_data_;
94 99
95 GURL url_; 100 GURL url_;
96 101
97 scoped_refptr<net::IOBuffer> data_; 102 scoped_refptr<net::IOBuffer> data_;
98 size_t data_length_; 103 size_t data_length_;
99 104
105 // Last value returned by writer_->TotalBufferedBytes() in AddData(). Stored
106 // in order to check memory usage.
107 size_t last_total_buffered_bytes_;
108
100 scoped_ptr<ByteStreamWriter> writer_; 109 scoped_ptr<ByteStreamWriter> writer_;
101 scoped_ptr<ByteStreamReader> reader_; 110 scoped_ptr<ByteStreamReader> reader_;
102 111
103 StreamRegistry* registry_; 112 StreamRegistry* registry_;
104 StreamReadObserver* read_observer_; 113 StreamReadObserver* read_observer_;
105 StreamWriteObserver* write_observer_; 114 StreamWriteObserver* write_observer_;
106 115
107 StreamHandleImpl* stream_handle_; 116 StreamHandleImpl* stream_handle_;
108 117
109 base::WeakPtrFactory<Stream> weak_ptr_factory_; 118 base::WeakPtrFactory<Stream> weak_ptr_factory_;
110 DISALLOW_COPY_AND_ASSIGN(Stream); 119 DISALLOW_COPY_AND_ASSIGN(Stream);
111 }; 120 };
112 121
113 } // namespace content 122 } // namespace content
114 123
115 #endif // CONTENT_BROWSER_STREAMS_STREAM_H_ 124 #endif // CONTENT_BROWSER_STREAMS_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698