mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-09 12:51:09 +02:00
The inclusions were removed with the following very crude script and the
resulting breakage was fixed up by hand. The manual fixups did either
revert the changes done by the script, replace a generic header with a more
specific one or replace a header with a forward declaration.
find . -name "*.idl" | grep -v web-platform | grep -v third_party | while read path; do
interfaces=$(grep "^\(class\|interface\).*:.*" "$path" | cut -d' ' -f2)
if [ -n "$interfaces" ]; then
if [[ "$interfaces" == *$'\n'* ]]; then
regexp="\("
for i in $interfaces; do regexp="$regexp$i\|"; done
regexp="${regexp%%\\\|}\)"
else
regexp="$interfaces"
fi
interface=$(basename "$path")
rg -l "#include.*${interface%%.idl}.h" . | while read path2; do
hits=$(grep -v "#include.*${interface%%.idl}.h" "$path2" | grep -c "$regexp" )
if [ $hits -eq 0 ]; then
echo "Removing ${interface} from ${path2}"
grep -v "#include.*${interface%%.idl}.h" "$path2" > "$path2".tmp
mv -f "$path2".tmp "$path2"
fi
done
fi
done
Differential Revision: https://phabricator.services.mozilla.com/D55444
--HG--
extra : moz-landing-system : lando
209 lines
6.4 KiB
C++
209 lines
6.4 KiB
C++
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "Shutdown.h"
|
|
#include "mozilla/Unused.h"
|
|
#include "nsIWritablePropertyBag2.h"
|
|
|
|
namespace mozilla {
|
|
namespace places {
|
|
|
|
uint16_t PlacesShutdownBlocker::sCounter = 0;
|
|
Atomic<bool> PlacesShutdownBlocker::sIsStarted(false);
|
|
|
|
PlacesShutdownBlocker::PlacesShutdownBlocker(const nsString& aName)
|
|
: mName(aName), mState(NOT_STARTED), mCounter(sCounter++) {
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
// During tests, we can end up with the Database singleton being resurrected.
|
|
// Make sure that each instance of DatabaseShutdown has a unique name.
|
|
if (mCounter > 1) {
|
|
mName.AppendInt(mCounter);
|
|
}
|
|
// Create a barrier that will be exposed to clients through GetClient(), so
|
|
// they can block Places shutdown.
|
|
nsCOMPtr<nsIAsyncShutdownService> asyncShutdown =
|
|
services::GetAsyncShutdown();
|
|
MOZ_ASSERT(asyncShutdown);
|
|
if (asyncShutdown) {
|
|
nsCOMPtr<nsIAsyncShutdownBarrier> barrier;
|
|
nsresult rv = asyncShutdown->MakeBarrier(mName, getter_AddRefs(barrier));
|
|
MOZ_ALWAYS_SUCCEEDS(rv);
|
|
if (NS_SUCCEEDED(rv) && barrier) {
|
|
mBarrier = new nsMainThreadPtrHolder<nsIAsyncShutdownBarrier>(
|
|
"PlacesShutdownBlocker::mBarrier", barrier);
|
|
}
|
|
}
|
|
}
|
|
|
|
// nsIAsyncShutdownBlocker
|
|
NS_IMETHODIMP
|
|
PlacesShutdownBlocker::GetName(nsAString& aName) {
|
|
aName = mName;
|
|
return NS_OK;
|
|
}
|
|
|
|
// nsIAsyncShutdownBlocker
|
|
NS_IMETHODIMP
|
|
PlacesShutdownBlocker::GetState(nsIPropertyBag** _state) {
|
|
NS_ENSURE_ARG_POINTER(_state);
|
|
|
|
nsCOMPtr<nsIWritablePropertyBag2> bag =
|
|
do_CreateInstance("@mozilla.org/hash-property-bag;1");
|
|
NS_ENSURE_TRUE(bag, NS_ERROR_OUT_OF_MEMORY);
|
|
bag.forget(_state);
|
|
|
|
// Put `mState` in field `progress`
|
|
RefPtr<nsVariant> progress = new nsVariant();
|
|
nsresult rv = progress->SetAsUint8(mState);
|
|
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
|
|
rv = static_cast<nsIWritablePropertyBag2*>(*_state)->SetPropertyAsInterface(
|
|
NS_LITERAL_STRING("progress"), progress);
|
|
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
|
|
|
|
// Put `mBarrier`'s state in field `barrier`, if possible
|
|
if (!mBarrier) {
|
|
return NS_OK;
|
|
}
|
|
nsCOMPtr<nsIPropertyBag> barrierState;
|
|
rv = mBarrier->GetState(getter_AddRefs(barrierState));
|
|
if (NS_FAILED(rv)) {
|
|
return NS_OK;
|
|
}
|
|
|
|
RefPtr<nsVariant> barrier = new nsVariant();
|
|
rv = barrier->SetAsInterface(NS_GET_IID(nsIPropertyBag), barrierState);
|
|
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
|
|
rv = static_cast<nsIWritablePropertyBag2*>(*_state)->SetPropertyAsInterface(
|
|
NS_LITERAL_STRING("Barrier"), barrier);
|
|
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
already_AddRefed<nsIAsyncShutdownClient> PlacesShutdownBlocker::GetClient() {
|
|
nsCOMPtr<nsIAsyncShutdownClient> client;
|
|
if (mBarrier) {
|
|
MOZ_ALWAYS_SUCCEEDS(mBarrier->GetClient(getter_AddRefs(client)));
|
|
}
|
|
return client.forget();
|
|
}
|
|
|
|
// nsIAsyncShutdownBlocker
|
|
NS_IMETHODIMP
|
|
PlacesShutdownBlocker::BlockShutdown(nsIAsyncShutdownClient* aParentClient) {
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
mParentClient = new nsMainThreadPtrHolder<nsIAsyncShutdownClient>(
|
|
"ClientsShutdownBlocker::mParentClient", aParentClient);
|
|
mState = RECEIVED_BLOCK_SHUTDOWN;
|
|
|
|
if (NS_WARN_IF(!mBarrier)) {
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
}
|
|
|
|
// Wait until all the clients have removed their blockers.
|
|
MOZ_ALWAYS_SUCCEEDS(mBarrier->Wait(this));
|
|
|
|
mState = CALLED_WAIT_CLIENTS;
|
|
return NS_OK;
|
|
}
|
|
|
|
// nsIAsyncShutdownCompletionCallback
|
|
NS_IMETHODIMP
|
|
PlacesShutdownBlocker::Done() {
|
|
MOZ_ASSERT(false, "Should always be overridden");
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMPL_ISUPPORTS(PlacesShutdownBlocker, nsIAsyncShutdownBlocker,
|
|
nsIAsyncShutdownCompletionCallback)
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
ClientsShutdownBlocker::ClientsShutdownBlocker()
|
|
: PlacesShutdownBlocker(NS_LITERAL_STRING("Places Clients shutdown")) {
|
|
// Do nothing.
|
|
}
|
|
|
|
// nsIAsyncShutdownCompletionCallback
|
|
NS_IMETHODIMP
|
|
ClientsShutdownBlocker::Done() {
|
|
// At this point all the clients are done, we can stop blocking the shutdown
|
|
// phase.
|
|
mState = RECEIVED_DONE;
|
|
|
|
// mParentClient is nullptr in tests.
|
|
if (mParentClient) {
|
|
nsresult rv = mParentClient->RemoveBlocker(this);
|
|
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
|
|
mParentClient = nullptr;
|
|
}
|
|
mBarrier = nullptr;
|
|
return NS_OK;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
ConnectionShutdownBlocker::ConnectionShutdownBlocker(Database* aDatabase)
|
|
: PlacesShutdownBlocker(NS_LITERAL_STRING("Places Connection shutdown")),
|
|
mDatabase(aDatabase) {
|
|
// Do nothing.
|
|
}
|
|
|
|
// nsIAsyncShutdownCompletionCallback
|
|
NS_IMETHODIMP
|
|
ConnectionShutdownBlocker::Done() {
|
|
// At this point all the clients are done, we can stop blocking the shutdown
|
|
// phase.
|
|
mState = RECEIVED_DONE;
|
|
|
|
// Annotate that Database shutdown started.
|
|
sIsStarted = true;
|
|
|
|
// At this stage, any use of this database is forbidden. Get rid of
|
|
// `gDatabase`. Note, however, that the database could be
|
|
// resurrected. This can happen in particular during tests.
|
|
MOZ_ASSERT(Database::gDatabase == nullptr ||
|
|
Database::gDatabase == mDatabase);
|
|
Database::gDatabase = nullptr;
|
|
|
|
// Database::Shutdown will invoke Complete once the connection is closed.
|
|
mDatabase->Shutdown();
|
|
mState = CALLED_STORAGESHUTDOWN;
|
|
mBarrier = nullptr;
|
|
return NS_OK;
|
|
}
|
|
|
|
// mozIStorageCompletionCallback
|
|
NS_IMETHODIMP
|
|
ConnectionShutdownBlocker::Complete(nsresult, nsISupports*) {
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
mState = RECEIVED_STORAGESHUTDOWN_COMPLETE;
|
|
|
|
// The connection is closed, the Database has no more use, so we can break
|
|
// possible cycles.
|
|
mDatabase = nullptr;
|
|
|
|
// Notify the connection has gone.
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
|
MOZ_ASSERT(os);
|
|
if (os) {
|
|
MOZ_ALWAYS_SUCCEEDS(
|
|
os->NotifyObservers(nullptr, TOPIC_PLACES_CONNECTION_CLOSED, nullptr));
|
|
}
|
|
mState = NOTIFIED_OBSERVERS_PLACES_CONNECTION_CLOSED;
|
|
|
|
// mParentClient is nullptr in tests
|
|
if (mParentClient) {
|
|
nsresult rv = mParentClient->RemoveBlocker(this);
|
|
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
|
|
mParentClient = nullptr;
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(ConnectionShutdownBlocker, PlacesShutdownBlocker,
|
|
mozIStorageCompletionCallback)
|
|
|
|
} // namespace places
|
|
} // namespace mozilla
|