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

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

Issue 1264453002: Split the constructor of ThreadableLoader into two methods (ctor and start()) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 4 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 Thread ableLoaderClientWrapper::ResourceTimingClient { 53 class WorkerThreadableLoader final : public ThreadableLoader, private Thread ableLoaderClientWrapper::ResourceTimingClient {
54 WTF_MAKE_FAST_ALLOCATED(WorkerThreadableLoader); 54 WTF_MAKE_FAST_ALLOCATED(WorkerThreadableLoader);
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 ThreadableLoaderOptions& options, const ResourceLoaderOptions& resourceLoaderOptions)
58 { 58 {
59 return adoptRef(new WorkerThreadableLoader(workerGlobalScope, client Wrapper, clientBridge, request, options, resourceLoaderOptions)); 59 return adoptRef(new WorkerThreadableLoader(workerGlobalScope, client Wrapper, 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 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 createCrossThreadTask), so the ThreadableLoaderClientWrapp er instance is there until all 88 // done in createCrossThreadTask), so the ThreadableLoaderClientWrapp er 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>, PassRefPtr<WorkerLoaderProxy>, const ResourceRequest &, const ThreadableLoaderOptions&, const ResourceLoaderOptions&, const ReferrerP olicy, const String& outgoingReferrer); 93 MainThreadBridge(PassRefPtr<ThreadableLoaderClientWrapper>, PassOwnP tr<ThreadableLoaderClient>, PassRefPtr<WorkerLoaderProxy>, const ThreadableLoade rOptions&, const ResourceLoaderOptions&);
94 void start(const ResourceRequest&, const ReferrerPolicy, const Strin g&);
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<CrossThreadResourceRequestDat a>, ThreadableLoaderOptions, ResourceLoaderOptions, const ReferrerPolicy, const String& outgoingReferrer, ExecutionContext*); 107 void mainThreadCreateLoader(ThreadableLoaderOptions, ResourceLoaderO ptions, ExecutionContext*);
108 void mainThreadStart(PassOwnPtr<CrossThreadResourceRequestData>, con st ReferrerPolicy, const String&);
hiroshige 2015/07/30 12:07:21 nit: add the name "outgoingReferrer" to the last a
tyoshino (SeeGerritForStatus) 2015/07/31 08:00:42 Done.
105 void mainThreadOverrideTimeout(unsigned long timeoutMilliseconds, Ex ecutionContext*); 109 void mainThreadOverrideTimeout(unsigned long timeoutMilliseconds, Ex ecutionContext*);
106 void mainThreadCancel(ExecutionContext*); 110 void mainThreadCancel(ExecutionContext*);
107 void didSendData(unsigned long long bytesSent, unsigned long long to talBytesToBeSent) override; 111 void didSendData(unsigned long long bytesSent, unsigned long long to talBytesToBeSent) override;
108 void didReceiveResponse(unsigned long identifier, const ResourceResp onse&, PassOwnPtr<WebDataConsumerHandle>) override; 112 void didReceiveResponse(unsigned long identifier, const ResourceResp onse&, 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) o verride; 116 void didFinishLoading(unsigned long identifier, double finishTime) o verride;
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 thread. 126 // ThreadableLoaderClientWrapper is to be used on the worker context thread.
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<ThreadableLoaderCl ientWrapper>, PassOwnPtr<ThreadableLoaderClient>, const ResourceRequest&, const ThreadableLoaderOptions&, const ResourceLoaderOptions&); 134 WorkerThreadableLoader(WorkerGlobalScope&, PassRefPtr<ThreadableLoaderCl ientWrapper>, PassOwnPtr<ThreadableLoaderClient>, const ThreadableLoaderOptions& , const 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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698