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

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

Issue 15817013: Add Stream support to WebBlobRegistry and FileAPIMessageFilter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Redesign 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 20 matching lines...) Expand all
31 // reader to consume part of the stream, then pass it along to another client 31 // reader to consume part of the stream, then pass it along to another client
32 // to continue processing the stream. 32 // to continue processing the stream.
33 class CONTENT_EXPORT Stream : public base::RefCountedThreadSafe<Stream> { 33 class CONTENT_EXPORT Stream : public base::RefCountedThreadSafe<Stream> {
34 public: 34 public:
35 enum StreamState { 35 enum StreamState {
36 STREAM_HAS_DATA, 36 STREAM_HAS_DATA,
37 STREAM_COMPLETE, 37 STREAM_COMPLETE,
38 STREAM_EMPTY, 38 STREAM_EMPTY,
39 }; 39 };
40 40
41 // Creates a stream useable from the |security_origin|. 41 // Creates a stream.
42 //
43 // TODO(tyoshino): Add |security_origin| parameter back to prevent cross
44 // origin access to streams inside Chromium (Blink has its own origin checking
45 // mechanism).
kinuko 2013/07/24 13:11:05 nit: this comment should be added in/after https:/
tyoshino (SeeGerritForStatus) 2013/07/24 13:56:22 ditto. already removed
42 Stream(StreamRegistry* registry, 46 Stream(StreamRegistry* registry,
43 StreamWriteObserver* write_observer, 47 StreamWriteObserver* write_observer,
44 const GURL& security_origin, 48 const GURL& security_origin,
45 const GURL& url); 49 const GURL& url);
46 50
47 // Sets the reader of this stream. Returns true on success, or false if there 51 // Sets the reader of this stream. Returns true on success, or false if there
48 // is already a reader. 52 // is already a reader.
49 bool SetReadObserver(StreamReadObserver* observer); 53 bool SetReadObserver(StreamReadObserver* observer);
50 54
51 // Removes the read observer. |observer| must be the current observer. 55 // Removes the read observer. |observer| must be the current observer.
52 void RemoveReadObserver(StreamReadObserver* observer); 56 void RemoveReadObserver(StreamReadObserver* observer);
53 57
54 // Removes the write observer. |observer| must be the current observer. 58 // Removes the write observer. |observer| must be the current observer.
55 void RemoveWriteObserver(StreamWriteObserver* observer); 59 void RemoveWriteObserver(StreamWriteObserver* observer);
56 60
57 // Adds the data in |buffer| to the stream. Takes ownership of |buffer|. 61 // Adds the data in |buffer| to the stream. Takes ownership of |buffer|.
58 void AddData(scoped_refptr<net::IOBuffer> buffer, size_t size); 62 void AddData(scoped_refptr<net::IOBuffer> buffer, size_t size);
63 // Adds data of |size| at |data| to the stream. This method creates a copy
64 // of the data, and then passes it to |writer_|.
65 void AddData(const char* data, size_t size);
59 66
60 // Notifies this stream that it will not be receiving any more data. 67 // Notifies this stream that it will not be receiving any more data.
61 void Finalize(); 68 void Finalize();
62 69
63 // Reads a maximum of |buf_size| from the stream into |buf|. Sets 70 // Reads a maximum of |buf_size| from the stream into |buf|. Sets
64 // |*bytes_read| to the number of bytes actually read. 71 // |*bytes_read| to the number of bytes actually read.
65 // Returns STREAM_HAS_DATA if data was read, STREAM_EMPTY if no data was read, 72 // Returns STREAM_HAS_DATA if data was read, STREAM_EMPTY if no data was read,
66 // and STREAM_COMPLETE if the stream is finalized and all data has been read. 73 // and STREAM_COMPLETE if the stream is finalized and all data has been read.
67 StreamState ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read); 74 StreamState ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read);
68 75
69 scoped_ptr<StreamHandle> CreateHandle(const GURL& original_url, 76 scoped_ptr<StreamHandle> CreateHandle(const GURL& original_url,
70 const std::string& mime_type); 77 const std::string& mime_type);
71 void CloseHandle(); 78 void CloseHandle();
72 79
73 // Indicates whether there is space in the buffer to add more data. 80 // Indicates whether there is space in the buffer to add more data.
74 bool can_add_data() const { return can_add_data_; } 81 bool can_add_data() const { return can_add_data_; }
75 82
76 const GURL& url() const { return url_; } 83 const GURL& url() const { return url_; }
77 84
85 // TODO(tyoshino): Once security origin handling inside Chromium is fixed,
86 // revisit callers of the Stream constructor and fix them if necessary to
87 // pass right data (e.g. FileAPIMessageFilter). (crbug.com/263342)
78 const GURL& security_origin() const { return security_origin_; } 88 const GURL& security_origin() const { return security_origin_; }
79 89
80 private: 90 private:
81 friend class base::RefCountedThreadSafe<Stream>; 91 friend class base::RefCountedThreadSafe<Stream>;
82 92
83 virtual ~Stream(); 93 virtual ~Stream();
84 94
85 void OnSpaceAvailable(); 95 void OnSpaceAvailable();
86 void OnDataAvailable(); 96 void OnDataAvailable();
87 97
(...skipping 15 matching lines...) Expand all
103 113
104 StreamHandleImpl* stream_handle_; 114 StreamHandleImpl* stream_handle_;
105 115
106 base::WeakPtrFactory<Stream> weak_ptr_factory_; 116 base::WeakPtrFactory<Stream> weak_ptr_factory_;
107 DISALLOW_COPY_AND_ASSIGN(Stream); 117 DISALLOW_COPY_AND_ASSIGN(Stream);
108 }; 118 };
109 119
110 } // namespace content 120 } // namespace content
111 121
112 #endif // CONTENT_BROWSER_STREAMS_STREAM_H_ 122 #endif // CONTENT_BROWSER_STREAMS_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698