1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_CHILD_THREADED_DATA_PROVIDER_H_
6 #define CONTENT_CHILD_THREADED_DATA_PROVIDER_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/linked_ptr.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/shared_memory.h"
13 #include "base/memory/weak_ptr.h"
14 #include "ipc/ipc_channel.h"
15 #include "ipc/message_filter.h"
17 struct ResourceMsg_RequestCompleteData
;
20 class WebThreadedDataReceiver
;
28 class WebThreadImplForWorkerScheduler
;
32 class ResourceDispatcher
;
34 class ThreadedDataProvider
{
38 blink::WebThreadedDataReceiver
* threaded_data_receiver
,
39 linked_ptr
<base::SharedMemory
> shm_buffer
,
41 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner_
);
43 // Any destruction of this class has to bounce via the background thread to
44 // ensure all data is flushed; call Stop() to start this process.
46 void OnReceivedDataOnBackgroundThread(int data_offset
,
48 int encoded_data_length
);
50 void OnReceivedDataOnForegroundThread(const char* data
,
52 int encoded_data_length
);
54 void OnResourceMessageFilterAddedMainThread();
55 void OnRequestCompleteForegroundThread(
56 base::WeakPtr
<ResourceDispatcher
> resource_dispatcher
,
57 const ResourceMsg_RequestCompleteData
& request_complete_data
,
58 const base::TimeTicks
& renderer_completion_time
);
61 ~ThreadedDataProvider();
62 void DestructOnMainThread();
64 void StopOnBackgroundThread();
65 void OnResourceMessageFilterAddedBackgroundThread();
66 void OnRequestCompleteBackgroundThread(
67 base::WeakPtr
<ResourceDispatcher
> resource_dispatcher
,
68 const ResourceMsg_RequestCompleteData
& request_complete_data
,
69 const base::TimeTicks
& renderer_completion_time
);
70 void ForwardAndACKData(const char* data
,
72 int encoded_data_length
);
73 void DataNotifyForegroundThread(
74 scoped_ptr
<std::vector
<char> > data_copy
,
76 int encoded_data_length
);
78 scoped_refptr
<IPC::MessageFilter
> filter_
;
80 linked_ptr
<base::SharedMemory
> shm_buffer_
;
82 scoped_ptr
<base::WeakPtrFactory
<ThreadedDataProvider
> >
83 background_thread_weak_factory_
;
84 scheduler::WebThreadImplForWorkerScheduler
& background_thread_
;
85 IPC::SyncChannel
* ipc_channel_
;
86 blink::WebThreadedDataReceiver
* threaded_data_receiver_
;
87 bool resource_filter_active_
;
88 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner_
;
90 struct QueuedSharedMemoryData
{
95 std::vector
<QueuedSharedMemoryData
> queued_data_
;
97 base::WeakPtrFactory
<ThreadedDataProvider
>
98 main_thread_weak_factory_
;
100 DISALLOW_COPY_AND_ASSIGN(ThreadedDataProvider
);
103 } // namespace content
105 #endif // CONTENT_CHILD_THREADED_DATA_PROVIDER_H_