Skip to content

Commit 0281335

Browse files
- Add MayBlock() method to stream classes which is used as a hint when determining the thread to access the stream from (issue #1187).
- In cases where MayBlock() returns true have CefStreamResourceReader perform the reads on the FILE thread (issue #1187). git-svn-id: http://chromiumembedded.googlecode.com/svn/trunk/cef3@1582 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
1 parent 4d22faf commit 0281335

23 files changed

+541
-18
lines changed

cef.gyp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@
399399
'tests/cefclient/client_app.h',
400400
'tests/cefclient/client_switches.cpp',
401401
'tests/cefclient/client_switches.h',
402+
'tests/cefclient/resource_util.h',
402403
'tests/cefclient/res/osr_test.html',
403404
'tests/unittests/browser_info_map_unittest.cc',
404405
'tests/unittests/command_line_unittest.cc',
@@ -417,12 +418,12 @@
417418
'tests/unittests/request_context_unittest.cc',
418419
'tests/unittests/request_handler_unittest.cc',
419420
'tests/unittests/request_unittest.cc',
420-
'tests/cefclient/resource_util.h',
421421
'tests/unittests/routing_test_handler.cc',
422422
'tests/unittests/routing_test_handler.h',
423423
'tests/unittests/run_all_unittests.cc',
424424
'tests/unittests/scheme_handler_unittest.cc',
425425
'tests/unittests/stream_unittest.cc',
426+
'tests/unittests/stream_resource_handler_unittest.cc',
426427
'tests/unittests/string_unittest.cc',
427428
'tests/unittests/client_app_delegates.cc',
428429
'tests/unittests/task_unittest.cc',
@@ -920,6 +921,7 @@
920921
'libcef/browser/download_item_impl.h',
921922
'libcef/browser/download_manager_delegate.cc',
922923
'libcef/browser/download_manager_delegate.h',
924+
'libcef/browser/file_impl.cc',
923925
'libcef/browser/frame_host_impl.cc',
924926
'libcef/browser/frame_host_impl.h',
925927
'libcef/browser/geolocation_impl.cc',

cef_paths.gypi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
'include/cef_download_item.h',
2929
'include/cef_drag_data.h',
3030
'include/cef_drag_handler.h',
31+
'include/cef_file.h',
3132
'include/cef_focus_handler.h',
3233
'include/cef_frame.h',
3334
'include/cef_geolocation.h',
@@ -80,6 +81,7 @@
8081
'include/capi/cef_download_item_capi.h',
8182
'include/capi/cef_drag_data_capi.h',
8283
'include/capi/cef_drag_handler_capi.h',
84+
'include/capi/cef_file_capi.h',
8385
'include/capi/cef_focus_handler_capi.h',
8486
'include/capi/cef_frame_capi.h',
8587
'include/capi/cef_geolocation_capi.h',

include/capi/cef_stream_capi.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ typedef struct _cef_read_handler_t {
7777
// Return non-zero if at end of file.
7878
///
7979
int (CEF_CALLBACK *eof)(struct _cef_read_handler_t* self);
80+
81+
///
82+
// Return true (1) if this handler performs work like accessing the file
83+
// system which may block. Used as a hint for determining the thread to access
84+
// the handler from.
85+
///
86+
int (CEF_CALLBACK *may_block)(struct _cef_read_handler_t* self);
8087
} cef_read_handler_t;
8188

8289

@@ -112,6 +119,13 @@ typedef struct _cef_stream_reader_t {
112119
// Return non-zero if at end of file.
113120
///
114121
int (CEF_CALLBACK *eof)(struct _cef_stream_reader_t* self);
122+
123+
///
124+
// Returns true (1) if this reader performs work like accessing the file
125+
// system which may block. Used as a hint for determining the thread to access
126+
// the reader from.
127+
///
128+
int (CEF_CALLBACK *may_block)(struct _cef_stream_reader_t* self);
115129
} cef_stream_reader_t;
116130

117131

@@ -166,6 +180,13 @@ typedef struct _cef_write_handler_t {
166180
// Flush the stream.
167181
///
168182
int (CEF_CALLBACK *flush)(struct _cef_write_handler_t* self);
183+
184+
///
185+
// Return true (1) if this handler performs work like accessing the file
186+
// system which may block. Used as a hint for determining the thread to access
187+
// the handler from.
188+
///
189+
int (CEF_CALLBACK *may_block)(struct _cef_write_handler_t* self);
169190
} cef_write_handler_t;
170191

171192

@@ -201,6 +222,13 @@ typedef struct _cef_stream_writer_t {
201222
// Flush the stream.
202223
///
203224
int (CEF_CALLBACK *flush)(struct _cef_stream_writer_t* self);
225+
226+
///
227+
// Returns true (1) if this writer performs work like accessing the file
228+
// system which may block. Used as a hint for determining the thread to access
229+
// the writer from.
230+
///
231+
int (CEF_CALLBACK *may_block)(struct _cef_stream_writer_t* self);
204232
} cef_stream_writer_t;
205233

206234

include/cef_stream.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ class CefReadHandler : public virtual CefBase {
7171
///
7272
/*--cef()--*/
7373
virtual int Eof() =0;
74+
75+
///
76+
// Return true if this handler performs work like accessing the file system
77+
// which may block. Used as a hint for determining the thread to access the
78+
// handler from.
79+
///
80+
/*--cef()--*/
81+
virtual bool MayBlock() =0;
7482
};
7583

7684

@@ -123,6 +131,14 @@ class CefStreamReader : public virtual CefBase {
123131
///
124132
/*--cef()--*/
125133
virtual int Eof() =0;
134+
135+
///
136+
// Returns true if this reader performs work like accessing the file system
137+
// which may block. Used as a hint for determining the thread to access the
138+
// reader from.
139+
///
140+
/*--cef()--*/
141+
virtual bool MayBlock() =0;
126142
};
127143

128144

@@ -158,6 +174,14 @@ class CefWriteHandler : public virtual CefBase {
158174
///
159175
/*--cef()--*/
160176
virtual int Flush() =0;
177+
178+
///
179+
// Return true if this handler performs work like accessing the file system
180+
// which may block. Used as a hint for determining the thread to access the
181+
// handler from.
182+
///
183+
/*--cef()--*/
184+
virtual bool MayBlock() =0;
161185
};
162186

163187

@@ -205,6 +229,14 @@ class CefStreamWriter : public virtual CefBase {
205229
///
206230
/*--cef()--*/
207231
virtual int Flush() =0;
232+
233+
///
234+
// Returns true if this writer performs work like accessing the file system
235+
// which may block. Used as a hint for determining the thread to access the
236+
// writer from.
237+
///
238+
/*--cef()--*/
239+
virtual bool MayBlock() =0;
208240
};
209241

210242
#endif // CEF_INCLUDE_CEF_STREAM_H_

include/wrapper/cef_byte_read_handler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class CefByteReadHandler : public CefReadHandler {
6060
virtual int Seek(int64 offset, int whence) OVERRIDE;
6161
virtual int64 Tell() OVERRIDE;
6262
virtual int Eof() OVERRIDE;
63+
virtual bool MayBlock() OVERRIDE { return false; }
6364

6465
private:
6566
const unsigned char* bytes_;

include/wrapper/cef_stream_resource_handler.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,14 @@ class CefStreamResourceHandler : public CefResourceHandler {
5757
// Create a new object with explicit response values.
5858
///
5959
CefStreamResourceHandler(int status_code,
60+
const CefString& status_text,
6061
const CefString& mime_type,
6162
CefResponse::HeaderMap header_map,
6263
CefRefPtr<CefStreamReader> stream);
6364

64-
// CefStreamResourceHandler methods.
65+
virtual ~CefStreamResourceHandler();
66+
67+
// CefResourceHandler methods.
6568
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
6669
CefRefPtr<CefCallback> callback) OVERRIDE;
6770
virtual void GetResponseHeaders(CefRefPtr<CefResponse> response,
@@ -74,10 +77,23 @@ class CefStreamResourceHandler : public CefResourceHandler {
7477
virtual void Cancel() OVERRIDE;
7578

7679
private:
77-
int status_code_;
78-
CefString mime_type_;
79-
CefResponse::HeaderMap header_map_;
80-
CefRefPtr<CefStreamReader> stream_;
80+
void ReadOnFileThread(int bytes_to_read,
81+
CefRefPtr<CefCallback> callback);
82+
83+
const int status_code_;
84+
const CefString status_text_;
85+
const CefString mime_type_;
86+
const CefResponse::HeaderMap header_map_;
87+
const CefRefPtr<CefStreamReader> stream_;
88+
bool read_on_file_thread_;
89+
90+
class Buffer;
91+
Buffer* buffer_;
92+
#ifndef NDEBUG
93+
// Used in debug builds to verify that |buffer_| isn't being accessed on
94+
// multiple threads at the same time.
95+
bool buffer_owned_by_file_thread_;
96+
#endif
8197

8298
IMPLEMENT_REFCOUNTING(CefStreamResourceHandler);
8399
};

libcef/browser/stream_impl.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class CefFileReader : public CefStreamReader {
2020
virtual int Seek(int64 offset, int whence) OVERRIDE;
2121
virtual int64 Tell() OVERRIDE;
2222
virtual int Eof() OVERRIDE;
23+
virtual bool MayBlock() OVERRIDE { return true; }
2324

2425
protected:
2526
bool close_;
@@ -39,6 +40,7 @@ class CefFileWriter : public CefStreamWriter {
3940
virtual int Seek(int64 offset, int whence) OVERRIDE;
4041
virtual int64 Tell() OVERRIDE;
4142
virtual int Flush() OVERRIDE;
43+
virtual bool MayBlock() OVERRIDE { return true; }
4244

4345
protected:
4446
FILE* file_;
@@ -58,6 +60,7 @@ class CefBytesReader : public CefStreamReader {
5860
virtual int Seek(int64 offset, int whence) OVERRIDE;
5961
virtual int64 Tell() OVERRIDE;
6062
virtual int Eof() OVERRIDE;
63+
virtual bool MayBlock() OVERRIDE { return false; }
6164

6265
void SetData(void* data, int64 datasize, bool copy);
6366

@@ -84,6 +87,7 @@ class CefBytesWriter : public CefStreamWriter {
8487
virtual int Seek(int64 offset, int whence) OVERRIDE;
8588
virtual int64 Tell() OVERRIDE;
8689
virtual int Flush() OVERRIDE;
90+
virtual bool MayBlock() OVERRIDE { return false; }
8791

8892
void* GetData() { return data_; }
8993
int64 GetDataSize() { return offset_; }
@@ -119,6 +123,9 @@ class CefHandlerReader : public CefStreamReader {
119123
virtual int Eof() OVERRIDE {
120124
return handler_->Eof();
121125
}
126+
virtual bool MayBlock() OVERRIDE {
127+
return handler_->MayBlock();
128+
}
122129

123130
protected:
124131
CefRefPtr<CefReadHandler> handler_;
@@ -144,6 +151,9 @@ class CefHandlerWriter : public CefStreamWriter {
144151
virtual int Flush() OVERRIDE {
145152
return handler_->Flush();
146153
}
154+
virtual bool MayBlock() OVERRIDE {
155+
return handler_->MayBlock();
156+
}
147157

148158
protected:
149159
CefRefPtr<CefWriteHandler> handler_;

libcef_dll/cef_logging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#endif // !BUILDING_CEF_SHARED
2929

3030
#define CEF_REQUIRE_UI_THREAD() DCHECK(CefCurrentlyOn(TID_UI));
31+
#define CEF_REQUIRE_IO_THREAD() DCHECK(CefCurrentlyOn(TID_IO));
32+
#define CEF_REQUIRE_FILE_THREAD() DCHECK(CefCurrentlyOn(TID_FILE));
3133
#define CEF_REQUIRE_RENDERER_THREAD() DCHECK(CefCurrentlyOn(TID_RENDERER));
3234

3335
#endif // CEF_LIBCEF_DLL_CEF_LOGGING_H_

libcef_dll/cpptoc/read_handler_cpptoc.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ int CEF_CALLBACK read_handler_eof(struct _cef_read_handler_t* self) {
8282
return _retval;
8383
}
8484

85+
int CEF_CALLBACK read_handler_may_block(struct _cef_read_handler_t* self) {
86+
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
87+
88+
DCHECK(self);
89+
if (!self)
90+
return 0;
91+
92+
// Execute
93+
bool _retval = CefReadHandlerCppToC::Get(self)->MayBlock();
94+
95+
// Return type: bool
96+
return _retval;
97+
}
98+
8599

86100
// CONSTRUCTOR - Do not edit by hand.
87101

@@ -91,6 +105,7 @@ CefReadHandlerCppToC::CefReadHandlerCppToC(CefReadHandler* cls)
91105
struct_.struct_.seek = read_handler_seek;
92106
struct_.struct_.tell = read_handler_tell;
93107
struct_.struct_.eof = read_handler_eof;
108+
struct_.struct_.may_block = read_handler_may_block;
94109
}
95110

96111
#ifndef NDEBUG

libcef_dll/cpptoc/stream_reader_cpptoc.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,20 @@ int CEF_CALLBACK stream_reader_eof(struct _cef_stream_reader_t* self) {
138138
return _retval;
139139
}
140140

141+
int CEF_CALLBACK stream_reader_may_block(struct _cef_stream_reader_t* self) {
142+
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
143+
144+
DCHECK(self);
145+
if (!self)
146+
return 0;
147+
148+
// Execute
149+
bool _retval = CefStreamReaderCppToC::Get(self)->MayBlock();
150+
151+
// Return type: bool
152+
return _retval;
153+
}
154+
141155

142156
// CONSTRUCTOR - Do not edit by hand.
143157

@@ -148,6 +162,7 @@ CefStreamReaderCppToC::CefStreamReaderCppToC(CefStreamReader* cls)
148162
struct_.struct_.seek = stream_reader_seek;
149163
struct_.struct_.tell = stream_reader_tell;
150164
struct_.struct_.eof = stream_reader_eof;
165+
struct_.struct_.may_block = stream_reader_may_block;
151166
}
152167

153168
#ifndef NDEBUG

0 commit comments

Comments
 (0)