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

Side by Side Diff: Source/core/loader/WorkerThreadableLoader.h

Issue 273993002: Allow XHR timeout attribute to be overridden after send(), per spec (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Avoid potential race-condition between load and timeout Created 6 years, 7 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
OLDNEW
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
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&); 56 static void loadResourceSynchronously(WorkerGlobalScope&, const Resource Request&, ThreadableLoaderClient&, const ThreadableLoaderOptions&);
57 static PassRefPtr<WorkerThreadableLoader> create(WorkerGlobalScope& work erGlobalScope, PassRefPtr<ThreadableLoaderClientWrapper> clientWrapper, PassOwnP tr<ThreadableLoaderClient> clientBridge, const ResourceRequest& request, const T hreadableLoaderOptions& options) 57 static PassRefPtr<WorkerThreadableLoader> create(WorkerGlobalScope& work erGlobalScope, PassRefPtr<ThreadableLoaderClientWrapper> clientWrapper, PassOwnP tr<ThreadableLoaderClient> clientBridge, const ResourceRequest& request, const T hreadableLoaderOptions& options)
58 { 58 {
59 return adoptRef(new WorkerThreadableLoader(workerGlobalScope, client Wrapper, clientBridge, request, options)); 59 return adoptRef(new WorkerThreadableLoader(workerGlobalScope, client Wrapper, clientBridge, request, options));
60 } 60 }
61 61
62 virtual ~WorkerThreadableLoader(); 62 virtual ~WorkerThreadableLoader();
63 63
64 virtual void overrideTimeout(unsigned long timeout) OVERRIDE;
65
64 virtual void cancel() OVERRIDE; 66 virtual void cancel() OVERRIDE;
65 67
66 bool done() const { return m_workerClientWrapper->done(); } 68 bool done() const { return m_workerClientWrapper->done(); }
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 WorkerThreadabl eLoader runs. 72 // the main thread and the worker context's thread where WorkerThreadabl eLoader 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 b ecause 76 // all cases. All tasks posted from the worker context's thread are ok b ecause
75 // the last task posted always is "mainThreadDestroy", so MainThreadB ridge is 77 // the last task posted always is "mainThreadDestroy", so MainThreadB ridge 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 th read to the worker 81 // In this case, no more tasks are posted from the worker object's th read to the worker
80 // context's thread -- WorkerGlobalScopeProxy implementation enforces this. 82 // context's thread -- WorkerGlobalScopeProxy implementation enforces this.
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 cleare d, so no more calls 85 // The ThreadableLoaderClientWrapper has the underlying client cleare d, so no more calls
84 // go through it. All tasks posted from the worker object's thread t o the worker context's 86 // go through it. All tasks posted from the worker object's thread t o the worker context's
85 // thread do "ThreadableLoaderClientWrapper::ref" (automatically insi de of the cross thread copy 87 // thread do "ThreadableLoaderClientWrapper::ref" (automatically insi de of the cross thread copy
86 // done in createCallbackTask), so the ThreadableLoaderClientWrapper instance is there until all 88 // done in createCallbackTask), so the ThreadableLoaderClientWrapper instance 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>, PassOwnP tr<ThreadableLoaderClient>, WorkerLoaderProxy&, const ResourceRequest&, const Th readableLoaderOptions&, const String& outgoingReferrer); 93 MainThreadBridge(PassRefPtr<ThreadableLoaderClientWrapper>, PassOwnP tr<ThreadableLoaderClient>, WorkerLoaderProxy&, const ResourceRequest&, const Th readableLoaderOptions&, const String& outgoingReferrer);
94 void overrideTimeout(unsigned long timeoutMilliseconds);
92 void cancel(); 95 void cancel();
93 void destroy(); 96 void destroy();
94 97
95 private: 98 private:
96 // Executed on the worker context's thread. 99 // Executed on the worker context's thread.
97 void clearClientWrapper(); 100 void clearClientWrapper();
98 101
99 // All executed on the main thread. 102 // All executed on the main thread.
100 static void mainThreadDestroy(ExecutionContext*, MainThreadBridge*); 103 static void mainThreadDestroy(ExecutionContext*, MainThreadBridge*);
101 virtual ~MainThreadBridge(); 104 virtual ~MainThreadBridge();
102 105
103 static void mainThreadCreateLoader(ExecutionContext*, MainThreadBrid ge*, PassOwnPtr<CrossThreadResourceRequestData>, ThreadableLoaderOptions, const String& outgoingReferrer); 106 static void mainThreadCreateLoader(ExecutionContext*, MainThreadBrid ge*, PassOwnPtr<CrossThreadResourceRequestData>, ThreadableLoaderOptions, const String& outgoingReferrer);
107 static void mainThreadOverrideTimeout(ExecutionContext*, MainThreadB ridge*, unsigned long timeoutMilliseconds);
104 static void mainThreadCancel(ExecutionContext*, MainThreadBridge*); 108 static void mainThreadCancel(ExecutionContext*, MainThreadBridge*);
105 virtual void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent) OVERRIDE; 109 virtual void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent) OVERRIDE;
106 virtual void didReceiveResponse(unsigned long identifier, const Reso urceResponse&) OVERRIDE; 110 virtual void didReceiveResponse(unsigned long identifier, const Reso urceResponse&) OVERRIDE;
107 virtual void didReceiveData(const char*, int dataLength) OVERRIDE; 111 virtual void didReceiveData(const char*, int dataLength) OVERRIDE;
108 virtual void didDownloadData(int dataLength) OVERRIDE; 112 virtual void didDownloadData(int dataLength) OVERRIDE;
109 virtual void didReceiveCachedMetadata(const char*, int dataLength) O VERRIDE; 113 virtual void didReceiveCachedMetadata(const char*, int dataLength) O VERRIDE;
110 virtual void didFinishLoading(unsigned long identifier, double finis hTime) OVERRIDE; 114 virtual void didFinishLoading(unsigned long identifier, double finis hTime) OVERRIDE;
111 virtual void didFail(const ResourceError&) OVERRIDE; 115 virtual void didFail(const ResourceError&) OVERRIDE;
112 virtual void didFailAccessControlCheck(const ResourceError&) OVERRID E; 116 virtual void didFailAccessControlCheck(const ResourceError&) OVERRID E;
113 virtual void didFailRedirectCheck() OVERRIDE; 117 virtual void didFailRedirectCheck() OVERRIDE;
(...skipping 13 matching lines...) Expand all
127 WorkerThreadableLoader(WorkerGlobalScope&, PassRefPtr<ThreadableLoaderCl ientWrapper>, PassOwnPtr<ThreadableLoaderClient>, const ResourceRequest&, const ThreadableLoaderOptions&); 131 WorkerThreadableLoader(WorkerGlobalScope&, PassRefPtr<ThreadableLoaderCl ientWrapper>, PassOwnPtr<ThreadableLoaderClient>, const ResourceRequest&, const ThreadableLoaderOptions&);
128 132
129 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; 133 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope;
130 RefPtr<ThreadableLoaderClientWrapper> m_workerClientWrapper; 134 RefPtr<ThreadableLoaderClientWrapper> m_workerClientWrapper;
131 MainThreadBridge& m_bridge; 135 MainThreadBridge& m_bridge;
132 }; 136 };
133 137
134 } // namespace WebCore 138 } // namespace WebCore
135 139
136 #endif // WorkerThreadableLoader_h 140 #endif // WorkerThreadableLoader_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698