Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: third_party/WebKit/WebCore/loader/WorkerThreadableLoader.h

Issue 20076: WebKit merge 40500:40539 [WebKit side] (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef WorkerThreadableLoader_h
32 #define WorkerThreadableLoader_h
33
34 #if ENABLE(WORKERS)
35
36 #include "ThreadableLoader.h"
37 #include "ThreadableLoaderClient.h"
38 #include "ThreadableLoaderClientWrapper.h"
39
40 #include <memory>
41 #include <wtf/PassRefPtr.h>
42 #include <wtf/RefCounted.h>
43 #include <wtf/RefPtr.h>
44 #include <wtf/Threading.h>
45
46 namespace WebCore {
47
48 class ResourceRequest;
49 class WorkerContext;
50 class WorkerMessagingProxy;
51 struct CrossThreadResourceResponseData;
52 struct CrossThreadResourceRequestData;
53
54 class WorkerThreadableLoader : public RefCounted<WorkerThreadableLoader>, pu blic ThreadableLoader {
55 public:
56 static PassRefPtr<WorkerThreadableLoader> create(WorkerContext* worker, ThreadableLoaderClient* client, const ResourceRequest& request, LoadCallbacks ca llbacksSetting, ContentSniff contentSniff)
57 {
58 return adoptRef(new WorkerThreadableLoader(worker, client, request, callbacksSetting, contentSniff));
59 }
60
61 ~WorkerThreadableLoader();
62
63 virtual void cancel();
64
65 using RefCounted<WorkerThreadableLoader>::ref;
66 using RefCounted<WorkerThreadableLoader>::deref;
67
68 protected:
69 virtual void refThreadableLoader() { ref(); }
70 virtual void derefThreadableLoader() { deref(); }
71
72 private:
73 // Creates a loader on the main thread and bridges communication between
74 // the main thread and the worker context's thread where WorkerThreadabl eLoader runs.
75 //
76 // Regarding the bridge and lifetimes of items used in callbacks, there are a few cases:
77 //
78 // all cases. All tasks posted from the worker context's thread are ok b ecause
79 // the last task posted always is "mainThreadDestroy", so MainThreadB ridge is
80 // around for all tasks that use it on the mian thread.
81 //
82 // case 1. worker.terminate is called.
83 // In this case, no more tasks are posted from the worker object's th read to the worker
84 // context's thread -- WorkerMessagingProxy enforces this.
85 //
86 // case 2. xhr gets aborted and the worker context continues running.
87 // The ThreadableLoaderClientWrapper has the underlying client cleare d, so no more calls
88 // go through it. All tasks posted from the worker object's thread t o the worker context's
89 // thread do "ThreadableLoaderClientWrapper::ref" (automatically insi de of the cross thread copy
90 // done in createCallbackTask), so the ThreadableLoaderClientWrapper instance is there until all
91 // tasks are executed.
92 class MainThreadBridge : ThreadableLoaderClient {
93 public:
94 // All executed on the worker context's thread.
95 MainThreadBridge(ThreadableLoaderClient*, WorkerMessagingProxy&, con st ResourceRequest&, LoadCallbacks, ContentSniff);
96 void cancel();
97 void destroy();
98
99 private:
100 // Executed on the worker context's thread.
101 void clearClientWrapper();
102
103 // All executed on the main thread.
104 static void mainThreadDestroy(ScriptExecutionContext*, MainThreadBri dge*);
105 ~MainThreadBridge();
106
107 static void mainThreadCreateLoader(ScriptExecutionContext*, MainThre adBridge*, std::auto_ptr<CrossThreadResourceRequestData>, LoadCallbacks, Content Sniff);
108 static void mainThreadCancel(ScriptExecutionContext*, MainThreadBrid ge*);
109 virtual void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent);
110 virtual void didReceiveResponse(const ResourceResponse&);
111 virtual void didReceiveData(const char*, int lengthReceived);
112 virtual void didFinishLoading(int identifier);
113 virtual void didFail();
114 virtual void didGetCancelled();
115 virtual void didReceiveAuthenticationCancellation(const ResourceResp onse&);
116
117 // Only to be used on the main thread.
118 RefPtr<ThreadableLoader> m_mainThreadLoader;
119
120 // ThreadableLoaderClientWrapper is to be used on the worker context thread.
121 // The ref counting is done on either thread.
122 RefPtr<ThreadSafeShared<ThreadableLoaderClientWrapper> > m_workerCli entWrapper;
123
124 // May be used on either thread.
125 WorkerMessagingProxy& m_messagingProxy;
126 };
127
128 WorkerThreadableLoader(WorkerContext*, ThreadableLoaderClient*, const Re sourceRequest&, LoadCallbacks, ContentSniff);
129
130 RefPtr<WorkerContext> m_workerContext;
131 MainThreadBridge& m_bridge;
132 };
133
134 } // namespace WebCore
135
136 #endif // ENABLE(WORKERS)
137
138 #endif // WorkerThreadableLoader_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698