Commit 92753e23 authored by sigbjornf@opera.com's avatar sigbjornf@opera.com

Oilpan: avoid using WeakPtr<> for heap residing objects.

GlobalFetch::ScopedFetcher instances are heap objects, so avoid using
WeakPtr<>s over those.

Also switch over to using WeakPtr* transition types where possible.

R=haraken
BUG=509911

Review URL: https://codereview.chromium.org/1320563003

git-svn-id: svn://svn.chromium.org/blink/trunk@201305 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent d951679b
......@@ -48,11 +48,7 @@ public:
void run() override;
private:
#if ENABLE(OILPAN)
CrossThreadWeakPersistent<MainThreadTaskRunner> m_runner;
#else
WeakPtr<MainThreadTaskRunner> m_runner;
#endif
WeakPtrWillBeCrossThreadWeakPersistent<MainThreadTaskRunner> m_runner;
OwnPtr<ExecutionContextTask> m_task;
bool m_isInspectorTask;
};
......
......@@ -162,11 +162,7 @@ void FormAssociatedElement::setForm(HTMLFormElement* newForm)
#endif
m_form->associate(*this);
} else {
#if ENABLE(OILPAN)
m_form = nullptr;
#else
m_form = WeakPtr<HTMLFormElement>();
#endif
}
didChangeForm();
}
......
......@@ -126,11 +126,7 @@ private:
void resetFormAttributeTargetObserver();
OwnPtrWillBeMember<FormAttributeTargetObserver> m_formAttributeTargetObserver;
#if ENABLE(OILPAN)
Member<HTMLFormElement> m_form;
#else
WeakPtr<HTMLFormElement> m_form;
#endif
WeakPtrWillBeMember<HTMLFormElement> m_form;
OwnPtrWillBeMember<ValidityState> m_validityState;
String m_customValidationMessage;
// Non-Oilpan: Even if m_formWasSetByParser is true, m_form can be null
......
......@@ -157,11 +157,7 @@ private:
OwnPtrWillBeMember<HTMLImageLoader> m_imageLoader;
RefPtrWillBeMember<ViewportChangeListener> m_listener;
#if ENABLE(OILPAN)
Member<HTMLFormElement> m_form;
#else
WeakPtr<HTMLFormElement> m_form;
#endif
WeakPtrWillBeMember<HTMLFormElement> m_form;
AtomicString m_bestFitImageURL;
float m_imageDevicePixelRatio;
unsigned m_formWasSetByParser : 1;
......
......@@ -277,7 +277,7 @@ private:
WebServiceWorkerResponse m_webResponse;
};
Cache* Cache::create(WeakPtr<GlobalFetch::ScopedFetcher> fetcher, PassOwnPtr<WebServiceWorkerCache> webCache)
Cache* Cache::create(WeakPtrWillBeRawPtr<GlobalFetch::ScopedFetcher> fetcher, PassOwnPtr<WebServiceWorkerCache> webCache)
{
return new Cache(fetcher, webCache);
}
......@@ -389,9 +389,16 @@ WebServiceWorkerCache::QueryParams Cache::toWebQueryParams(const CacheQueryOptio
return webQueryParams;
}
Cache::Cache(WeakPtr<GlobalFetch::ScopedFetcher> fetcher, PassOwnPtr<WebServiceWorkerCache> webCache)
Cache::Cache(WeakPtrWillBeRawPtr<GlobalFetch::ScopedFetcher> fetcher, PassOwnPtr<WebServiceWorkerCache> webCache)
: m_scopedFetcher(fetcher)
, m_webCache(webCache) { }
, m_webCache(webCache)
{
}
DEFINE_TRACE(Cache)
{
visitor->trace(m_scopedFetcher);
}
ScriptPromise Cache::matchImpl(ScriptState* scriptState, const Request* request, const CacheQueryOptions& options)
{
......
......@@ -32,7 +32,7 @@ class MODULES_EXPORT Cache final : public GarbageCollectedFinalized<Cache>, publ
DEFINE_WRAPPERTYPEINFO();
WTF_MAKE_NONCOPYABLE(Cache);
public:
static Cache* create(WeakPtr<GlobalFetch::ScopedFetcher>, PassOwnPtr<WebServiceWorkerCache>);
static Cache* create(WeakPtrWillBeRawPtr<GlobalFetch::ScopedFetcher>, PassOwnPtr<WebServiceWorkerCache>);
// From Cache.idl:
ScriptPromise match(ScriptState*, const RequestInfo&, const CacheQueryOptions&, ExceptionState&);
......@@ -47,14 +47,14 @@ public:
static WebServiceWorkerCache::QueryParams toWebQueryParams(const CacheQueryOptions&);
DEFINE_INLINE_TRACE() { }
DECLARE_TRACE();
private:
class BarrierCallbackForPut;
class BlobHandleCallbackForPut;
class FetchResolvedForAdd;
friend class FetchResolvedForAdd;
Cache(WeakPtr<GlobalFetch::ScopedFetcher>, PassOwnPtr<WebServiceWorkerCache>);
Cache(WeakPtrWillBeRawPtr<GlobalFetch::ScopedFetcher>, PassOwnPtr<WebServiceWorkerCache>);
ScriptPromise matchImpl(ScriptState*, const Request*, const CacheQueryOptions&);
ScriptPromise matchAllImpl(ScriptState*);
......@@ -67,7 +67,7 @@ private:
WebServiceWorkerCache* webCache() const;
WeakPtr<GlobalFetch::ScopedFetcher> m_scopedFetcher;
WeakPtrWillBeMember<GlobalFetch::ScopedFetcher> m_scopedFetcher;
OwnPtr<WebServiceWorkerCache> m_webCache;
};
......
......@@ -203,7 +203,7 @@ private:
Persistent<ScriptPromiseResolver> m_resolver;
};
CacheStorage* CacheStorage::create(WeakPtr<GlobalFetch::ScopedFetcher> fetcher, WebServiceWorkerCacheStorage* webCacheStorage)
CacheStorage* CacheStorage::create(WeakPtrWillBeRawPtr<GlobalFetch::ScopedFetcher> fetcher, WebServiceWorkerCacheStorage* webCacheStorage)
{
return new CacheStorage(fetcher, adoptPtr(webCacheStorage));
}
......@@ -313,7 +313,7 @@ ScriptPromise CacheStorage::matchImpl(ScriptState* scriptState, const Request* r
return promise;
}
CacheStorage::CacheStorage(WeakPtr<GlobalFetch::ScopedFetcher> fetcher, PassOwnPtr<WebServiceWorkerCacheStorage> webCacheStorage)
CacheStorage::CacheStorage(WeakPtrWillBeRawPtr<GlobalFetch::ScopedFetcher> fetcher, PassOwnPtr<WebServiceWorkerCacheStorage> webCacheStorage)
: m_scopedFetcher(fetcher)
, m_webCacheStorage(webCacheStorage)
{
......@@ -330,6 +330,7 @@ void CacheStorage::dispose()
DEFINE_TRACE(CacheStorage)
{
visitor->trace(m_scopedFetcher);
visitor->trace(m_nameToCacheMap);
}
......
......@@ -25,7 +25,7 @@ class CacheStorage final : public GarbageCollectedFinalized<CacheStorage>, publi
DEFINE_WRAPPERTYPEINFO();
WTF_MAKE_NONCOPYABLE(CacheStorage);
public:
static CacheStorage* create(WeakPtr<GlobalFetch::ScopedFetcher>, WebServiceWorkerCacheStorage*);
static CacheStorage* create(WeakPtrWillBeRawPtr<GlobalFetch::ScopedFetcher>, WebServiceWorkerCacheStorage*);
~CacheStorage();
void dispose();
......@@ -47,10 +47,10 @@ private:
friend class WithCacheCallbacks;
friend class DeleteCallbacks;
CacheStorage(WeakPtr<GlobalFetch::ScopedFetcher>, PassOwnPtr<WebServiceWorkerCacheStorage>);
CacheStorage(WeakPtrWillBeRawPtr<GlobalFetch::ScopedFetcher>, PassOwnPtr<WebServiceWorkerCacheStorage>);
ScriptPromise matchImpl(ScriptState*, const Request*, const CacheQueryOptions&);
WeakPtr<GlobalFetch::ScopedFetcher> m_scopedFetcher;
WeakPtrWillBeMember<GlobalFetch::ScopedFetcher> m_scopedFetcher;
OwnPtr<WebServiceWorkerCacheStorage> m_webCacheStorage;
HeapHashMap<String, Member<Cache>> m_nameToCacheMap;
};
......
......@@ -33,13 +33,12 @@ namespace {
const char kNotImplementedString[] = "NotSupportedError: Method is not implemented.";
class ScopedFetcherForTests final : public GlobalFetch::ScopedFetcher {
class ScopedFetcherForTests final : public NoBaseWillBeGarbageCollectedFinalized<ScopedFetcherForTests>, public GlobalFetch::ScopedFetcher {
WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(ScopedFetcherForTests);
public:
ScopedFetcherForTests()
: m_fetchCount(0)
, m_expectedUrl(nullptr)
, m_weakFactory(this)
static PassOwnPtrWillBeRawPtr<ScopedFetcherForTests> create()
{
return adoptPtrWillBeNoop(new ScopedFetcherForTests);
}
ScriptPromise fetch(ScriptState* scriptState, const RequestInfo& requestInfo, const Dictionary&, ExceptionState&) override
......@@ -63,9 +62,13 @@ public:
return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(scriptState->isolate(), "Unexpected call to fetch, no response available."));
}
WeakPtr<GlobalFetch::ScopedFetcher> weakPtr()
WeakPtrWillBeRawPtr<GlobalFetch::ScopedFetcher> weakPtr()
{
#if ENABLE(OILPAN)
return this;
#else
return m_weakFactory.createWeakPtr();
#endif
}
// This does not take ownership of its parameter. The provided sample object is used to check the parameter when called.
......@@ -74,12 +77,29 @@ public:
int fetchCount() const { return m_fetchCount; }
DEFINE_INLINE_TRACE()
{
visitor->trace(m_response);
GlobalFetch::ScopedFetcher::trace(visitor);
}
private:
ScopedFetcherForTests()
: m_fetchCount(0)
, m_expectedUrl(nullptr)
#if !ENABLE(OILPAN)
, m_weakFactory(this)
#endif
{
}
int m_fetchCount;
const String* m_expectedUrl;
Persistent<Response> m_response;
PersistentWillBeMember<Response> m_response;
#if !ENABLE(OILPAN)
WeakPtrFactory<GlobalFetch::ScopedFetcher> m_weakFactory;
#endif
};
// A test implementation of the WebServiceWorkerCache interface which returns a (provided) error for every operation, and optionally checks arguments
......@@ -322,7 +342,7 @@ RequestInfo requestToRequestInfo(Request* value)
TEST_F(CacheStorageTest, Basics)
{
ScriptState::Scope scope(scriptState());
OwnPtr<ScopedFetcherForTests> fetcher = adoptPtr(new ScopedFetcherForTests());
OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::create();
ErrorWebCacheForTests* testCache;
Cache* cache = createCache(fetcher.get(), testCache = new NotImplementedErrorCache());
ASSERT(cache);
......@@ -348,7 +368,7 @@ TEST_F(CacheStorageTest, Basics)
TEST_F(CacheStorageTest, BasicArguments)
{
ScriptState::Scope scope(scriptState());
OwnPtr<ScopedFetcherForTests> fetcher = adoptPtr(new ScopedFetcherForTests());
OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::create();
ErrorWebCacheForTests* testCache;
Cache* cache = createCache(fetcher.get(), testCache = new NotImplementedErrorCache());
ASSERT(cache);
......@@ -404,7 +424,7 @@ TEST_F(CacheStorageTest, BasicArguments)
TEST_F(CacheStorageTest, BatchOperationArguments)
{
ScriptState::Scope scope(scriptState());
OwnPtr<ScopedFetcherForTests> fetcher = adoptPtr(new ScopedFetcherForTests());
OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::create();
ErrorWebCacheForTests* testCache;
Cache* cache = createCache(fetcher.get(), testCache = new NotImplementedErrorCache());
ASSERT(cache);
......@@ -484,7 +504,7 @@ private:
TEST_F(CacheStorageTest, MatchResponseTest)
{
ScriptState::Scope scope(scriptState());
OwnPtr<ScopedFetcherForTests> fetcher = adoptPtr(new ScopedFetcherForTests());
OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::create();
const String requestUrl = "http://request.url/";
const String responseUrl = "http://match.response.test/";
......@@ -520,7 +540,7 @@ private:
TEST_F(CacheStorageTest, KeysResponseTest)
{
ScriptState::Scope scope(scriptState());
OwnPtr<ScopedFetcherForTests> fetcher = adoptPtr(new ScopedFetcherForTests());
OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::create();
const String url1 = "http://first.request/";
const String url2 = "http://second.request/";
......@@ -571,7 +591,7 @@ private:
TEST_F(CacheStorageTest, MatchAllAndBatchResponseTest)
{
ScriptState::Scope scope(scriptState());
OwnPtr<ScopedFetcherForTests> fetcher = adoptPtr(new ScopedFetcherForTests());
OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::create();
const String url1 = "http://first.response/";
const String url2 = "http://second.response/";
......@@ -609,7 +629,7 @@ TEST_F(CacheStorageTest, MatchAllAndBatchResponseTest)
TEST_F(CacheStorageTest, Add)
{
ScriptState::Scope scope(scriptState());
OwnPtr<ScopedFetcherForTests> fetcher = adoptPtr(new ScopedFetcherForTests());
OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::create();
const String url = "http://www.cacheadd.test/";
const KURL kurl(ParsedURLString, url);
......
......@@ -23,14 +23,18 @@ template <typename T>
class GlobalFetchImpl final : public NoBaseWillBeGarbageCollectedFinalized<GlobalFetchImpl<T>>, public GlobalFetch::ScopedFetcher, public WillBeHeapSupplement<T> {
WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(GlobalFetchImpl);
public:
static WeakPtr<ScopedFetcher> from(T& supplementable, ExecutionContext* executionContext)
static WeakPtrWillBeRawPtr<ScopedFetcher> from(T& supplementable, ExecutionContext* executionContext)
{
GlobalFetchImpl* supplement = static_cast<GlobalFetchImpl*>(WillBeHeapSupplement<T>::from(supplementable, name()));
GlobalFetchImpl* supplement = static_cast<GlobalFetchImpl*>(WillBeHeapSupplement<T>::from(supplementable, supplementName()));
if (!supplement) {
supplement = new GlobalFetchImpl(executionContext);
WillBeHeapSupplement<T>::provideTo(supplementable, name(), adoptPtrWillBeNoop(supplement));
WillBeHeapSupplement<T>::provideTo(supplementable, supplementName(), adoptPtrWillBeNoop(supplement));
}
#if ENABLE(OILPAN)
return supplement;
#else
return supplement->m_weakFactory.createWeakPtr();
#endif
}
ScriptPromise fetch(ScriptState* scriptState, const RequestInfo& input, const Dictionary& init, ExceptionState& exceptionState) override
......@@ -90,14 +94,18 @@ private:
explicit GlobalFetchImpl(ExecutionContext* executionContext)
: m_fetchManager(FetchManager::create(executionContext))
, m_stopDetector(StopDetector::create(executionContext, m_fetchManager.get()))
#if !ENABLE(OILPAN)
, m_weakFactory(this)
#endif
{
}
static const char* name() { return "GlobalFetch"; }
static const char* supplementName() { return "GlobalFetch"; }
OwnPtrWillBeMember<FetchManager> m_fetchManager;
OwnPtrWillBeMember<StopDetector> m_stopDetector;
#if !ENABLE(OILPAN)
WeakPtrFactory<ScopedFetcher> m_weakFactory;
#endif
};
} // namespace
......@@ -106,12 +114,12 @@ GlobalFetch::ScopedFetcher::~ScopedFetcher()
{
}
WeakPtr<GlobalFetch::ScopedFetcher> GlobalFetch::ScopedFetcher::from(DOMWindow& window)
WeakPtrWillBeRawPtr<GlobalFetch::ScopedFetcher> GlobalFetch::ScopedFetcher::from(DOMWindow& window)
{
return GlobalFetchImpl<LocalDOMWindow>::from(toLocalDOMWindow(window), window.executionContext());
}
WeakPtr<GlobalFetch::ScopedFetcher> GlobalFetch::ScopedFetcher::from(WorkerGlobalScope& worker)
WeakPtrWillBeRawPtr<GlobalFetch::ScopedFetcher> GlobalFetch::ScopedFetcher::from(WorkerGlobalScope& worker)
{
return GlobalFetchImpl<WorkerGlobalScope>::from(worker, worker.executionContext());
}
......
......@@ -20,14 +20,14 @@ class WorkerGlobalScope;
class GlobalFetch {
public:
class MODULES_EXPORT ScopedFetcher {
class MODULES_EXPORT ScopedFetcher : public WillBeGarbageCollectedMixin {
public:
virtual ~ScopedFetcher();
virtual ScriptPromise fetch(ScriptState*, const RequestInfo&, const Dictionary&, ExceptionState&) = 0;
static WeakPtr<ScopedFetcher> from(DOMWindow&);
static WeakPtr<ScopedFetcher> from(WorkerGlobalScope&);
static WeakPtrWillBeRawPtr<ScopedFetcher> from(DOMWindow&);
static WeakPtrWillBeRawPtr<ScopedFetcher> from(WorkerGlobalScope&);
DECLARE_VIRTUAL_TRACE();
};
......
......@@ -759,6 +759,7 @@ public:
#define OwnPtrWillBePersistent blink::Persistent
#define OwnPtrWillBeRawPtr WTF::RawPtr
#define PassOwnPtrWillBeRawPtr WTF::RawPtr
#define WeakPtrWillBeCrossThreadWeakPersistent blink::CrossThreadWeakPersistent
#define WeakPtrWillBeMember blink::Member
#define WeakPtrWillBeRawPtr WTF::RawPtr
#define WeakPtrWillBeWeakMember blink::WeakMember
......@@ -841,6 +842,7 @@ template<typename T> T* adoptPtrWillBeNoop(T* ptr)
#define OwnPtrWillBePersistent WTF::OwnPtr
#define OwnPtrWillBeRawPtr WTF::OwnPtr
#define PassOwnPtrWillBeRawPtr WTF::PassOwnPtr
#define WeakPtrWillBeCrossThreadWeakPersistent WTF::WeakPtr
#define WeakPtrWillBeMember WTF::WeakPtr
#define WeakPtrWillBeRawPtr WTF::WeakPtr
#define WeakPtrWillBeWeakMember WTF::WeakPtr
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment