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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 WTF_MAKE_FAST_ALLOCATED; | 54 WTF_MAKE_FAST_ALLOCATED; |
55 public: | 55 public: |
56 static void loadResourceSynchronously(WorkerGlobalScope&, const Resource
Request&, ThreadableLoaderClient&, const ThreadableLoaderOptions&, const Resourc
eLoaderOptions&); | 56 static void loadResourceSynchronously(WorkerGlobalScope&, const Resource
Request&, ThreadableLoaderClient&, const ThreadableLoaderOptions&, const Resourc
eLoaderOptions&); |
57 static PassRefPtr<WorkerThreadableLoader> create(WorkerGlobalScope& work
erGlobalScope, PassRefPtr<ThreadableLoaderClientWrapper> clientWrapper, PassOwnP
tr<ThreadableLoaderClient> clientBridge, const ResourceRequest& request, const T
hreadableLoaderOptions& options, const ResourceLoaderOptions& resourceLoaderOpti
ons) | 57 static PassRefPtr<WorkerThreadableLoader> create(WorkerGlobalScope& work
erGlobalScope, PassRefPtr<ThreadableLoaderClientWrapper> clientWrapper, PassOwnP
tr<ThreadableLoaderClient> clientBridge, const ResourceRequest& request, const T
hreadableLoaderOptions& options, const ResourceLoaderOptions& resourceLoaderOpti
ons) |
58 { | 58 { |
59 return adoptRef(new WorkerThreadableLoader(workerGlobalScope, client
Wrapper, clientBridge, request, options, resourceLoaderOptions)); | 59 return adoptRef(new WorkerThreadableLoader(workerGlobalScope, client
Wrapper, clientBridge, request, options, resourceLoaderOptions)); |
60 } | 60 } |
61 | 61 |
62 virtual ~WorkerThreadableLoader(); | 62 virtual ~WorkerThreadableLoader(); |
63 | 63 |
64 virtual void overrideTimeout(unsigned long timeout) OVERRIDE; | |
65 | |
66 virtual void cancel() OVERRIDE; | 64 virtual void cancel() OVERRIDE; |
67 | 65 |
68 bool done() const { return m_workerClientWrapper->done(); } | 66 bool done() const { return m_workerClientWrapper->done(); } |
69 | 67 |
70 private: | 68 private: |
71 // Creates a loader on the main thread and bridges communication between | 69 // Creates a loader on the main thread and bridges communication between |
72 // the main thread and the worker context's thread where WorkerThreadabl
eLoader runs. | 70 // the main thread and the worker context's thread where WorkerThreadabl
eLoader runs. |
73 // | 71 // |
74 // Regarding the bridge and lifetimes of items used in callbacks, there
are a few cases: | 72 // Regarding the bridge and lifetimes of items used in callbacks, there
are a few cases: |
75 // | 73 // |
76 // all cases. All tasks posted from the worker context's thread are ok b
ecause | 74 // all cases. All tasks posted from the worker context's thread are ok b
ecause |
77 // the last task posted always is "mainThreadDestroy", so MainThreadB
ridge is | 75 // the last task posted always is "mainThreadDestroy", so MainThreadB
ridge is |
78 // around for all tasks that use it on the main thread. | 76 // around for all tasks that use it on the main thread. |
79 // | 77 // |
80 // case 1. worker.terminate is called. | 78 // case 1. worker.terminate is called. |
81 // In this case, no more tasks are posted from the worker object's th
read to the worker | 79 // In this case, no more tasks are posted from the worker object's th
read to the worker |
82 // context's thread -- WorkerGlobalScopeProxy implementation enforces
this. | 80 // context's thread -- WorkerGlobalScopeProxy implementation enforces
this. |
83 // | 81 // |
84 // case 2. xhr gets aborted and the worker context continues running. | 82 // case 2. xhr gets aborted and the worker context continues running. |
85 // The ThreadableLoaderClientWrapper has the underlying client cleare
d, so no more calls | 83 // The ThreadableLoaderClientWrapper has the underlying client cleare
d, so no more calls |
86 // go through it. All tasks posted from the worker object's thread t
o the worker context's | 84 // go through it. All tasks posted from the worker object's thread t
o the worker context's |
87 // thread do "ThreadableLoaderClientWrapper::ref" (automatically insi
de of the cross thread copy | 85 // thread do "ThreadableLoaderClientWrapper::ref" (automatically insi
de of the cross thread copy |
88 // done in createCallbackTask), so the ThreadableLoaderClientWrapper
instance is there until all | 86 // done in createCallbackTask), so the ThreadableLoaderClientWrapper
instance is there until all |
89 // tasks are executed. | 87 // tasks are executed. |
90 class MainThreadBridge FINAL : public ThreadableLoaderClient { | 88 class MainThreadBridge FINAL : public ThreadableLoaderClient { |
91 public: | 89 public: |
92 // All executed on the worker context's thread. | 90 // All executed on the worker context's thread. |
93 MainThreadBridge(PassRefPtr<ThreadableLoaderClientWrapper>, PassOwnP
tr<ThreadableLoaderClient>, WorkerLoaderProxy&, const ResourceRequest&, const Th
readableLoaderOptions&, const ResourceLoaderOptions&, const String& outgoingRefe
rrer); | 91 MainThreadBridge(PassRefPtr<ThreadableLoaderClientWrapper>, PassOwnP
tr<ThreadableLoaderClient>, WorkerLoaderProxy&, const ResourceRequest&, const Th
readableLoaderOptions&, const ResourceLoaderOptions&, const String& outgoingRefe
rrer); |
94 void overrideTimeout(unsigned long timeoutMilliseconds); | |
95 void cancel(); | 92 void cancel(); |
96 void destroy(); | 93 void destroy(); |
97 | 94 |
98 private: | 95 private: |
99 // Executed on the worker context's thread. | 96 // Executed on the worker context's thread. |
100 void clearClientWrapper(); | 97 void clearClientWrapper(); |
101 | 98 |
102 // All executed on the main thread. | 99 // All executed on the main thread. |
103 static void mainThreadDestroy(ExecutionContext*, MainThreadBridge*); | 100 static void mainThreadDestroy(ExecutionContext*, MainThreadBridge*); |
104 virtual ~MainThreadBridge(); | 101 virtual ~MainThreadBridge(); |
105 | 102 |
106 static void mainThreadCreateLoader(ExecutionContext*, MainThreadBrid
ge*, PassOwnPtr<CrossThreadResourceRequestData>, ThreadableLoaderOptions, Resour
ceLoaderOptions, const String& outgoingReferrer); | 103 static void mainThreadCreateLoader(ExecutionContext*, MainThreadBrid
ge*, PassOwnPtr<CrossThreadResourceRequestData>, ThreadableLoaderOptions, Resour
ceLoaderOptions, const String& outgoingReferrer); |
107 static void mainThreadOverrideTimeout(ExecutionContext*, MainThreadB
ridge*, unsigned long timeoutMilliseconds); | |
108 static void mainThreadCancel(ExecutionContext*, MainThreadBridge*); | 104 static void mainThreadCancel(ExecutionContext*, MainThreadBridge*); |
109 virtual void didSendData(unsigned long long bytesSent, unsigned long
long totalBytesToBeSent) OVERRIDE; | 105 virtual void didSendData(unsigned long long bytesSent, unsigned long
long totalBytesToBeSent) OVERRIDE; |
110 virtual void didReceiveResponse(unsigned long identifier, const Reso
urceResponse&) OVERRIDE; | 106 virtual void didReceiveResponse(unsigned long identifier, const Reso
urceResponse&) OVERRIDE; |
111 virtual void didReceiveData(const char*, int dataLength) OVERRIDE; | 107 virtual void didReceiveData(const char*, int dataLength) OVERRIDE; |
112 virtual void didDownloadData(int dataLength) OVERRIDE; | 108 virtual void didDownloadData(int dataLength) OVERRIDE; |
113 virtual void didReceiveCachedMetadata(const char*, int dataLength) O
VERRIDE; | 109 virtual void didReceiveCachedMetadata(const char*, int dataLength) O
VERRIDE; |
114 virtual void didFinishLoading(unsigned long identifier, double finis
hTime) OVERRIDE; | 110 virtual void didFinishLoading(unsigned long identifier, double finis
hTime) OVERRIDE; |
115 virtual void didFail(const ResourceError&) OVERRIDE; | 111 virtual void didFail(const ResourceError&) OVERRIDE; |
116 virtual void didFailAccessControlCheck(const ResourceError&) OVERRID
E; | 112 virtual void didFailAccessControlCheck(const ResourceError&) OVERRID
E; |
117 virtual void didFailRedirectCheck() OVERRIDE; | 113 virtual void didFailRedirectCheck() OVERRIDE; |
(...skipping 13 matching lines...) Expand all Loading... |
131 WorkerThreadableLoader(WorkerGlobalScope&, PassRefPtr<ThreadableLoaderCl
ientWrapper>, PassOwnPtr<ThreadableLoaderClient>, const ResourceRequest&, const
ThreadableLoaderOptions&, const ResourceLoaderOptions&); | 127 WorkerThreadableLoader(WorkerGlobalScope&, PassRefPtr<ThreadableLoaderCl
ientWrapper>, PassOwnPtr<ThreadableLoaderClient>, const ResourceRequest&, const
ThreadableLoaderOptions&, const ResourceLoaderOptions&); |
132 | 128 |
133 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; | 129 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; |
134 RefPtr<ThreadableLoaderClientWrapper> m_workerClientWrapper; | 130 RefPtr<ThreadableLoaderClientWrapper> m_workerClientWrapper; |
135 MainThreadBridge& m_bridge; | 131 MainThreadBridge& m_bridge; |
136 }; | 132 }; |
137 | 133 |
138 } // namespace WebCore | 134 } // namespace WebCore |
139 | 135 |
140 #endif // WorkerThreadableLoader_h | 136 #endif // WorkerThreadableLoader_h |
OLD | NEW |