Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / child / threaded_data_provider.h
blob9ac2ac21037debcb3612bd5053b6c564ca64f134
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;
19 namespace blink {
20 class WebThreadedDataReceiver;
23 namespace IPC {
24 class SyncChannel;
27 namespace content {
28 class ResourceDispatcher;
29 class WebThreadImpl;
31 class ThreadedDataProvider {
32 public:
33 ThreadedDataProvider(
34 int request_id,
35 blink::WebThreadedDataReceiver* threaded_data_receiver,
36 linked_ptr<base::SharedMemory> shm_buffer,
37 int shm_size,
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.
42 void Stop();
43 void OnReceivedDataOnBackgroundThread(int data_offset,
44 int data_length,
45 int encoded_data_length);
47 void OnReceivedDataOnForegroundThread(const char* data,
48 int data_length,
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);
57 private:
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,
68 int data_length,
69 int encoded_data_length);
70 void DataNotifyForegroundThread(
71 scoped_ptr<std::vector<char> > data_copy,
72 int data_length,
73 int encoded_data_length);
75 scoped_refptr<IPC::MessageFilter> filter_;
76 int request_id_;
77 linked_ptr<base::SharedMemory> shm_buffer_;
78 int shm_size_;
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 {
88 const char* data;
89 int length;
90 int encoded_length;
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_THREADED_DATA_PROVIDER_H_