Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / content / child / threaded_data_provider.h
blob5cd7433021adb3aedb8dffa6adaa6d926a089f9d
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 scheduler {
28 class WebThreadImplForWorkerScheduler;
31 namespace content {
32 class ResourceDispatcher;
34 class ThreadedDataProvider {
35 public:
36 ThreadedDataProvider(
37 int request_id,
38 blink::WebThreadedDataReceiver* threaded_data_receiver,
39 linked_ptr<base::SharedMemory> shm_buffer,
40 int shm_size,
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.
45 void Stop();
46 void OnReceivedDataOnBackgroundThread(int data_offset,
47 int data_length,
48 int encoded_data_length);
50 void OnReceivedDataOnForegroundThread(const char* data,
51 int data_length,
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);
60 private:
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,
71 int data_length,
72 int encoded_data_length);
73 void DataNotifyForegroundThread(
74 scoped_ptr<std::vector<char> > data_copy,
75 int data_length,
76 int encoded_data_length);
78 scoped_refptr<IPC::MessageFilter> filter_;
79 int request_id_;
80 linked_ptr<base::SharedMemory> shm_buffer_;
81 int shm_size_;
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 {
91 const char* data;
92 int length;
93 int encoded_length;
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_