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

Unified Diff: Source/modules/fetch/GlobalFetch.cpp

Issue 1065093006: FetchAPI: Make GlobalFetch available from other components Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/fetch/GlobalFetch.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/fetch/GlobalFetch.cpp
diff --git a/Source/modules/fetch/GlobalFetch.cpp b/Source/modules/fetch/GlobalFetch.cpp
index 4e9f9530fd66782aaace923fbf743dd680f06034..9fa26560b9ad73b97dc40488a2662a86d826a23c 100644
--- a/Source/modules/fetch/GlobalFetch.cpp
+++ b/Source/modules/fetch/GlobalFetch.cpp
@@ -17,109 +17,72 @@
namespace blink {
-namespace {
-
-class GlobalFetchImpl final : public NoBaseWillBeGarbageCollectedFinalized<GlobalFetchImpl>, public WillBeHeapSupplement<LocalDOMWindow>, public WillBeHeapSupplement<WorkerGlobalScope> {
- WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(GlobalFetchImpl);
-public:
- static GlobalFetchImpl& from(LocalDOMWindow& supplementable, ExecutionContext* executionContext)
- {
- GlobalFetchImpl* supplement = static_cast<GlobalFetchImpl*>(WillBeHeapSupplement<LocalDOMWindow>::from(supplementable, name()));
- if (!supplement) {
- supplement = new GlobalFetchImpl(executionContext);
- WillBeHeapSupplement<LocalDOMWindow>::provideTo(supplementable, name(), adoptPtrWillBeNoop(supplement));
- }
- return *supplement;
- }
-
- static GlobalFetchImpl& from(WorkerGlobalScope& supplementable, ExecutionContext* executionContext)
- {
- GlobalFetchImpl* supplement = static_cast<GlobalFetchImpl*>(WillBeHeapSupplement<WorkerGlobalScope>::from(supplementable, name()));
- if (!supplement) {
- supplement = new GlobalFetchImpl(executionContext);
- WillBeHeapSupplement<WorkerGlobalScope>::provideTo(supplementable, name(), adoptPtrWillBeNoop(supplement));
- }
- return *supplement;
- }
-
- ScriptPromise fetch(ScriptState* scriptState, const RequestInfo& input, const Dictionary& init, ExceptionState& exceptionState)
- {
- if (m_fetchManager->isStopped()) {
- exceptionState.throwTypeError("The global scope is shutting down.");
- return ScriptPromise();
- }
-
- // "Let |r| be the associated request of the result of invoking the
- // initial value of Request as constructor with |input| and |init| as
- // arguments. If this throws an exception, reject |p| with it."
- Request* r = Request::create(m_stopDetector->executionContext(), input, init, exceptionState);
- if (exceptionState.hadException())
- return ScriptPromise();
- return m_fetchManager->fetch(scriptState, r->passRequestData());
+GlobalFetch& GlobalFetch::from(LocalDOMWindow& supplementable, ExecutionContext* executionContext)
+{
+ GlobalFetch* supplement = static_cast<GlobalFetch*>(WillBeHeapSupplement<LocalDOMWindow>::from(supplementable, name()));
+ if (!supplement) {
+ supplement = new GlobalFetch(executionContext);
+ WillBeHeapSupplement<LocalDOMWindow>::provideTo(supplementable, name(), adoptPtrWillBeNoop(supplement));
}
+ return *supplement;
+}
- DEFINE_INLINE_VIRTUAL_TRACE()
- {
- visitor->trace(m_fetchManager);
- visitor->trace(m_stopDetector);
- WillBeHeapSupplement<LocalDOMWindow>::trace(visitor);
- WillBeHeapSupplement<WorkerGlobalScope>::trace(visitor);
+GlobalFetch& GlobalFetch::from(WorkerGlobalScope& supplementable, ExecutionContext* executionContext)
+{
+ GlobalFetch* supplement = static_cast<GlobalFetch*>(WillBeHeapSupplement<WorkerGlobalScope>::from(supplementable, name()));
+ if (!supplement) {
+ supplement = new GlobalFetch(executionContext);
+ WillBeHeapSupplement<WorkerGlobalScope>::provideTo(supplementable, name(), adoptPtrWillBeNoop(supplement));
}
+ return *supplement;
+}
-private:
- class StopDetector final : public NoBaseWillBeGarbageCollectedFinalized<StopDetector>, public ActiveDOMObject {
- WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(StopDetector);
- public:
- static PassOwnPtrWillBeRawPtr<StopDetector> create(ExecutionContext* executionContext, FetchManager* fetchManager)
- {
- return adoptPtrWillBeNoop(new StopDetector(executionContext, fetchManager));
- }
-
- void stop() override { m_fetchManager->stop(); }
-
- DEFINE_INLINE_TRACE()
- {
- visitor->trace(m_fetchManager);
- ActiveDOMObject::trace(visitor);
- }
-
- private:
- StopDetector(ExecutionContext* executionContext, FetchManager* fetchManager)
- : ActiveDOMObject(executionContext)
- , m_fetchManager(fetchManager)
- {
- suspendIfNeeded();
- }
-
- // Having a raw pointer is safe, because |m_fetchManager| is owned by
- // the owner of this object.
- RawPtrWillBeMember<FetchManager> m_fetchManager;
- };
-
- explicit GlobalFetchImpl(ExecutionContext* executionContext)
- : m_fetchManager(FetchManager::create(executionContext))
- , m_stopDetector(StopDetector::create(executionContext, m_fetchManager.get()))
- {
+ScriptPromise GlobalFetch::fetch(ScriptState* scriptState, const RequestInfo& input, const Dictionary& init, ExceptionState& exceptionState)
+{
+ if (m_fetchManager->isStopped()) {
+ exceptionState.throwTypeError("The global scope is shutting down.");
+ return ScriptPromise();
}
- static const char* name() { return "GlobalFetch"; }
- OwnPtrWillBeMember<FetchManager> m_fetchManager;
- OwnPtrWillBeMember<StopDetector> m_stopDetector;
-};
-
-} // namespace
+ // "Let |r| be the associated request of the result of invoking the
+ // initial value of Request as constructor with |input| and |init| as
+ // arguments. If this throws an exception, reject |p| with it."
+ Request* r = Request::create(m_stopDetector->executionContext(), input, init, exceptionState);
+ if (exceptionState.hadException())
+ return ScriptPromise();
+ return m_fetchManager->fetch(scriptState, r->passRequestData());
+}
ScriptPromise GlobalFetch::fetch(ScriptState* scriptState, DOMWindow& window, const RequestInfo& input, const Dictionary& init, ExceptionState& exceptionState)
{
UseCounter::count(window.executionContext(), UseCounter::Fetch);
- return GlobalFetchImpl::from(toLocalDOMWindow(window), window.executionContext()).fetch(scriptState, input, init, exceptionState);
+ return GlobalFetch::from(toLocalDOMWindow(window), window.executionContext()).fetch(scriptState, input, init, exceptionState);
}
ScriptPromise GlobalFetch::fetch(ScriptState* scriptState, WorkerGlobalScope& worker, const RequestInfo& input, const Dictionary& init, ExceptionState& exceptionState)
{
// Note that UseCounter doesn't work with SharedWorker or ServiceWorker.
UseCounter::count(worker.executionContext(), UseCounter::Fetch);
- return GlobalFetchImpl::from(worker, worker.executionContext()).fetch(scriptState, input, init, exceptionState);
+ return GlobalFetch::from(worker, worker.executionContext()).fetch(scriptState, input, init, exceptionState);
+}
+
+GlobalFetch::GlobalFetch(ExecutionContext* executionContext)
+ : m_fetchManager(FetchManager::create(executionContext)), m_stopDetector(StopDetector::create(executionContext, m_fetchManager.get())) { }
+
+PassOwnPtrWillBeRawPtr<GlobalFetch::StopDetector> GlobalFetch::StopDetector::create(ExecutionContext* executionContext, FetchManager* fetchManager)
+{
+ return adoptPtrWillBeNoop(new StopDetector(executionContext, fetchManager));
+}
+
+void GlobalFetch::StopDetector::stop()
+{
+ m_fetchManager->stop();
+}
+
+GlobalFetch::StopDetector::StopDetector(ExecutionContext* executionContext, FetchManager* fetchManager)
+ : ActiveDOMObject(executionContext), m_fetchManager(fetchManager)
+{
+ suspendIfNeeded();
}
} // namespace blink
« no previous file with comments | « Source/modules/fetch/GlobalFetch.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698