OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 class ResourceError; | 47 class ResourceError; |
48 class ResourceRequest; | 48 class ResourceRequest; |
49 class WorkerGlobalScope; | 49 class WorkerGlobalScope; |
50 class WorkerLoaderProxy; | 50 class WorkerLoaderProxy; |
51 struct CrossThreadResourceRequestData; | 51 struct CrossThreadResourceRequestData; |
52 | 52 |
53 class WorkerThreadableLoader final : public ThreadableLoader, private Threadable LoaderClientWrapper::ResourceTimingClient { | 53 class WorkerThreadableLoader final : public ThreadableLoader, private Threadable LoaderClientWrapper::ResourceTimingClient { |
54 USING_FAST_MALLOC(WorkerThreadableLoader); | 54 USING_FAST_MALLOC(WorkerThreadableLoader); |
55 public: | 55 public: |
56 static void loadResourceSynchronously(WorkerGlobalScope&, const ResourceRequ est&, ThreadableLoaderClient&, const ThreadableLoaderOptions&, const ResourceLoa derOptions&); | 56 static void loadResourceSynchronously(WorkerGlobalScope&, const ResourceRequ est&, ThreadableLoaderClient&, const ThreadableLoaderOptions&, const ResourceLoa derOptions&); |
57 static PassRefPtr<WorkerThreadableLoader> create(WorkerGlobalScope& workerGl obalScope, PassRefPtr<ThreadableLoaderClientWrapper> clientWrapper, PassOwnPtr<T hreadableLoaderClient> clientBridge, const ResourceRequest& request, const Threa dableLoaderOptions& options, const ResourceLoaderOptions& resourceLoaderOptions) | 57 static PassRefPtr<WorkerThreadableLoader> create(WorkerGlobalScope& workerGl obalScope, PassRefPtr<ThreadableLoaderClientWrapper> clientWrapper, PassOwnPtr<T hreadableLoaderClient> clientBridge, const ThreadableLoaderOptions& options, con st ResourceLoaderOptions& resourceLoaderOptions) |
58 { | 58 { |
59 return adoptRef(new WorkerThreadableLoader(workerGlobalScope, clientWrap per, clientBridge, request, options, resourceLoaderOptions)); | 59 return adoptRef(new WorkerThreadableLoader(workerGlobalScope, clientWrap per, clientBridge, options, resourceLoaderOptions)); |
60 } | 60 } |
61 | 61 |
62 ~WorkerThreadableLoader() override; | 62 ~WorkerThreadableLoader() override; |
63 | 63 |
64 void start(const ResourceRequest&) override; | |
65 | |
64 void overrideTimeout(unsigned long timeout) override; | 66 void overrideTimeout(unsigned long timeout) override; |
65 | 67 |
66 void cancel() override; | 68 void cancel() override; |
67 | 69 |
68 private: | 70 private: |
69 // Creates a loader on the main thread and bridges communication between | 71 // Creates a loader on the main thread and bridges communication between |
70 // the main thread and the worker context's thread where WorkerThreadableLoa der runs. | 72 // the main thread and the worker context's thread where WorkerThreadableLoa der runs. |
71 // | 73 // |
72 // Regarding the bridge and lifetimes of items used in callbacks, there are a few cases: | 74 // Regarding the bridge and lifetimes of items used in callbacks, there are a few cases: |
73 // | 75 // |
74 // all cases. All tasks posted from the worker context's thread are ok becau se | 76 // all cases. All tasks posted from the worker context's thread are ok becau se |
75 // the last task posted always is "mainThreadDestroy", so MainThreadBridg e is | 77 // the last task posted always is "mainThreadDestroy", so MainThreadBridg e is |
76 // around for all tasks that use it on the main thread. | 78 // around for all tasks that use it on the main thread. |
77 // | 79 // |
78 // case 1. worker.terminate is called. | 80 // case 1. worker.terminate is called. |
79 // In this case, no more tasks are posted from the worker object's thread to the worker | 81 // In this case, no more tasks are posted from the worker object's thread to the worker |
80 // context's thread -- WorkerGlobalScopeProxy implementation enforces thi s. | 82 // context's thread -- WorkerGlobalScopeProxy implementation enforces thi s. |
81 // | 83 // |
82 // case 2. xhr gets aborted and the worker context continues running. | 84 // case 2. xhr gets aborted and the worker context continues running. |
83 // The ThreadableLoaderClientWrapper has the underlying client cleared, s o no more calls | 85 // The ThreadableLoaderClientWrapper has the underlying client cleared, s o no more calls |
84 // go through it. All tasks posted from the worker object's thread to th e worker context's | 86 // go through it. All tasks posted from the worker object's thread to th e worker context's |
85 // thread do "ThreadableLoaderClientWrapper::ref" (automatically inside o f the cross thread copy | 87 // thread do "ThreadableLoaderClientWrapper::ref" (automatically inside o f the cross thread copy |
86 // done in createCrossThreadTask), so the ThreadableLoaderClientWrapper i nstance is there until all | 88 // done in createCrossThreadTask), so the ThreadableLoaderClientWrapper i nstance is there until all |
87 // tasks are executed. | 89 // tasks are executed. |
88 class MainThreadBridge final : public ThreadableLoaderClient { | 90 class MainThreadBridge final : public ThreadableLoaderClient { |
89 public: | 91 public: |
90 // All executed on the worker context's thread. | 92 // All executed on the worker context's thread. |
91 MainThreadBridge(PassRefPtr<ThreadableLoaderClientWrapper>, PassOwnPtr<T hreadableLoaderClient>, PassRefPtr<WorkerLoaderProxy>, const ResourceRequest&, c onst ThreadableLoaderOptions&, const ResourceLoaderOptions&, const ReferrerPolic y, const String& outgoingReferrer); | 93 MainThreadBridge(PassRefPtr<ThreadableLoaderClientWrapper>, PassOwnPtr<T hreadableLoaderClient>, PassRefPtr<WorkerLoaderProxy>, const ThreadableLoaderOpt ions&, const ResourceLoaderOptions&); |
94 void start(const ResourceRequest&, const ReferrerPolicy, const String&); | |
hiroshige
2016/01/26 08:44:50
nit: The third argument is |outgoingReferrer| and
tyoshino (SeeGerritForStatus)
2016/01/29 12:36:52
Done.
| |
92 void overrideTimeout(unsigned long timeoutMilliseconds); | 95 void overrideTimeout(unsigned long timeoutMilliseconds); |
93 void cancel(); | 96 void cancel(); |
94 void destroy(); | 97 void destroy(); |
95 | 98 |
96 private: | 99 private: |
97 // Executed on the worker context's thread. | 100 // Executed on the worker context's thread. |
98 void clearClientWrapper(); | 101 void clearClientWrapper(); |
99 | 102 |
100 // All executed on the main thread. | 103 // All executed on the main thread. |
101 void mainThreadDestroy(ExecutionContext*); | 104 void mainThreadDestroy(ExecutionContext*); |
102 ~MainThreadBridge() override; | 105 ~MainThreadBridge() override; |
103 | 106 |
104 void mainThreadCreateLoader(PassOwnPtr<CrossThreadResourceRequestData>, ThreadableLoaderOptions, ResourceLoaderOptions, const ReferrerPolicy, const Stri ng& outgoingReferrer, ExecutionContext*); | 107 void mainThreadCreateLoader(ThreadableLoaderOptions, ResourceLoaderOptio ns, ExecutionContext*); |
108 void mainThreadStart(PassOwnPtr<CrossThreadResourceRequestData>, const R eferrerPolicy, const String&); | |
hiroshige
2016/01/26 08:44:50
nit: ditto.
tyoshino (SeeGerritForStatus)
2016/01/29 12:36:52
Done.
| |
105 void mainThreadOverrideTimeout(unsigned long timeoutMilliseconds, Execut ionContext*); | 109 void mainThreadOverrideTimeout(unsigned long timeoutMilliseconds, Execut ionContext*); |
106 void mainThreadCancel(ExecutionContext*); | 110 void mainThreadCancel(ExecutionContext*); |
107 void didSendData(unsigned long long bytesSent, unsigned long long totalB ytesToBeSent) override; | 111 void didSendData(unsigned long long bytesSent, unsigned long long totalB ytesToBeSent) override; |
108 void didReceiveResponse(unsigned long identifier, const ResourceResponse &, PassOwnPtr<WebDataConsumerHandle>) override; | 112 void didReceiveResponse(unsigned long identifier, const ResourceResponse &, PassOwnPtr<WebDataConsumerHandle>) override; |
109 void didReceiveData(const char*, unsigned dataLength) override; | 113 void didReceiveData(const char*, unsigned dataLength) override; |
110 void didDownloadData(int dataLength) override; | 114 void didDownloadData(int dataLength) override; |
111 void didReceiveCachedMetadata(const char*, int dataLength) override; | 115 void didReceiveCachedMetadata(const char*, int dataLength) override; |
112 void didFinishLoading(unsigned long identifier, double finishTime) overr ide; | 116 void didFinishLoading(unsigned long identifier, double finishTime) overr ide; |
113 void didFail(const ResourceError&) override; | 117 void didFail(const ResourceError&) override; |
114 void didFailAccessControlCheck(const ResourceError&) override; | 118 void didFailAccessControlCheck(const ResourceError&) override; |
115 void didFailRedirectCheck() override; | 119 void didFailRedirectCheck() override; |
116 void didReceiveResourceTiming(const ResourceTimingInfo&) override; | 120 void didReceiveResourceTiming(const ResourceTimingInfo&) override; |
117 | 121 |
118 // Only to be used on the main thread. | 122 // Only to be used on the main thread. |
119 RefPtr<ThreadableLoader> m_mainThreadLoader; | 123 RefPtr<ThreadableLoader> m_mainThreadLoader; |
120 OwnPtr<ThreadableLoaderClient> m_clientBridge; | 124 OwnPtr<ThreadableLoaderClient> m_clientBridge; |
121 | 125 |
122 // ThreadableLoaderClientWrapper is to be used on the worker context thr ead. | 126 // ThreadableLoaderClientWrapper is to be used on the worker context thr ead. |
123 // The ref counting is done on either thread. | 127 // The ref counting is done on either thread. |
124 RefPtr<ThreadableLoaderClientWrapper> m_workerClientWrapper; | 128 RefPtr<ThreadableLoaderClientWrapper> m_workerClientWrapper; |
125 | 129 |
126 // Used on the worker context thread. | 130 // Used on the worker context thread. |
127 RefPtr<WorkerLoaderProxy> m_loaderProxy; | 131 RefPtr<WorkerLoaderProxy> m_loaderProxy; |
128 }; | 132 }; |
129 | 133 |
130 WorkerThreadableLoader(WorkerGlobalScope&, PassRefPtr<ThreadableLoaderClient Wrapper>, PassOwnPtr<ThreadableLoaderClient>, const ResourceRequest&, const Thre adableLoaderOptions&, const ResourceLoaderOptions&); | 134 WorkerThreadableLoader(WorkerGlobalScope&, PassRefPtr<ThreadableLoaderClient Wrapper>, PassOwnPtr<ThreadableLoaderClient>, const ThreadableLoaderOptions&, co nst ResourceLoaderOptions&); |
131 | 135 |
132 void didReceiveResourceTiming(const ResourceTimingInfo&) override; | 136 void didReceiveResourceTiming(const ResourceTimingInfo&) override; |
133 | 137 |
134 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; | 138 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; |
135 RefPtr<ThreadableLoaderClientWrapper> m_workerClientWrapper; | 139 RefPtr<ThreadableLoaderClientWrapper> m_workerClientWrapper; |
136 MainThreadBridge& m_bridge; | 140 MainThreadBridge& m_bridge; |
137 }; | 141 }; |
138 | 142 |
139 } // namespace blink | 143 } // namespace blink |
140 | 144 |
141 #endif // WorkerThreadableLoader_h | 145 #endif // WorkerThreadableLoader_h |
OLD | NEW |