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_THREADEDDATAPROVIDER_IMPL_H_
6 #define CONTENT_CHILD_THREADEDDATAPROVIDER_IMPL_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 ResourceDispatcher
;
31 class ThreadedDataProvider
{
35 blink::WebThreadedDataReceiver
* threaded_data_receiver
,
36 linked_ptr
<base::SharedMemory
> shm_buffer
,
38 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner_
);
40 // Any destruction of this class has to bounce via the background thread to
41 // ensure all data is flushed; call Stop() to start this process.
43 void OnReceivedDataOnBackgroundThread(int data_offset
,
45 int encoded_data_length
);
47 void OnReceivedDataOnForegroundThread(const char* data
,
49 int encoded_data_length
);
51 void OnResourceMessageFilterAddedMainThread();
52 void OnRequestCompleteForegroundThread(
53 base::WeakPtr
<ResourceDispatcher
> resource_dispatcher
,
54 const ResourceMsg_RequestCompleteData
& request_complete_data
,
55 const base::TimeTicks
& renderer_completion_time
);
58 ~ThreadedDataProvider();
59 void DestructOnMainThread();
61 void StopOnBackgroundThread();
62 void OnResourceMessageFilterAddedBackgroundThread();
63 void OnRequestCompleteBackgroundThread(
64 base::WeakPtr
<ResourceDispatcher
> resource_dispatcher
,
65 const ResourceMsg_RequestCompleteData
& request_complete_data
,
66 const base::TimeTicks
& renderer_completion_time
);
67 void ForwardAndACKData(const char* data
,
69 int encoded_data_length
);
70 void DataNotifyForegroundThread(
71 scoped_ptr
<std::vector
<char> > data_copy
,
73 int encoded_data_length
);
75 scoped_refptr
<IPC::MessageFilter
> filter_
;
77 linked_ptr
<base::SharedMemory
> shm_buffer_
;
79 scoped_ptr
<base::WeakPtrFactory
<ThreadedDataProvider
> >
80 background_thread_weak_factory_
;
81 WebThreadImpl
& background_thread_
;
82 IPC::SyncChannel
* ipc_channel_
;
83 blink::WebThreadedDataReceiver
* threaded_data_receiver_
;
84 bool resource_filter_active_
;
85 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner_
;
87 struct QueuedSharedMemoryData
{
92 std::vector
<QueuedSharedMemoryData
> queued_data_
;
94 base::WeakPtrFactory
<ThreadedDataProvider
>
95 main_thread_weak_factory_
;
97 DISALLOW_COPY_AND_ASSIGN(ThreadedDataProvider
);
100 } // namespace content
102 #endif // CONTENT_CHILD_THREADEDDATAPROVIDER_IMPL_H_