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