mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 00:32:11 +00:00
1a1f42da37
This changeset is the result of adding modernize-use-default-member-init to tools/clang-tidy/config.yaml then proceeding to run `./mach static-analysis check netwerk/ --fix` I then went through the resulting fix and manually updated all of the member variables which were missed due to them having a non-trivial constructor. Note that the tool was only run on Linux, so code that only runs on some platforms may have been missed. The member variables that are still initialized in the contructor definition are: - bitfields (not all currently supported compilers allow default-member-init - variables that are initialized via a parameter - variables that use code not visible in the header file There are a few advantages to landing this change: - fewer lines of code - now declaration is in the same place as initialization this also makes it easier to see when looking at the header. - it makes it harder to miss initializing a member when adding a new contructor - variables that depend on an include guard look much nicer now Additionally I removed some unnecessary reinitialization of NetAddr members (it has a constructor that does that now), and changed nsWifiScannerDBus to use the thread-safe strtok_r instead of strtok. Differential Revision: https://phabricator.services.mozilla.com/D116980
122 lines
3.5 KiB
C++
122 lines
3.5 KiB
C++
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* 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/. */
|
|
|
|
#ifndef nsAsyncRedirectVerifyHelper_h
|
|
#define nsAsyncRedirectVerifyHelper_h
|
|
|
|
#include "nsIRunnable.h"
|
|
#include "nsIChannelEventSink.h"
|
|
#include "nsIAsyncVerifyRedirectCallback.h"
|
|
#include "nsINamed.h"
|
|
#include "nsCOMPtr.h"
|
|
#include "nsCycleCollectionParticipant.h"
|
|
#include "mozilla/Attributes.h"
|
|
|
|
class nsIChannel;
|
|
|
|
namespace mozilla {
|
|
namespace net {
|
|
|
|
/**
|
|
* This class simplifies call of OnChannelRedirect of IOService and
|
|
* the sink bound with the channel being redirected while the result of
|
|
* redirect decision is returned through the callback.
|
|
*/
|
|
class nsAsyncRedirectVerifyHelper final
|
|
: public nsIRunnable,
|
|
public nsINamed,
|
|
public nsIAsyncVerifyRedirectCallback {
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
NS_DECL_NSIRUNNABLE
|
|
NS_DECL_NSINAMED
|
|
NS_DECL_NSIASYNCVERIFYREDIRECTCALLBACK
|
|
|
|
public:
|
|
nsAsyncRedirectVerifyHelper() = default;
|
|
|
|
/*
|
|
* Calls AsyncOnChannelRedirect() on the given sink with the given
|
|
* channels and flags. Keeps track of number of async callbacks to expect.
|
|
*/
|
|
nsresult DelegateOnChannelRedirect(nsIChannelEventSink* sink,
|
|
nsIChannel* oldChannel,
|
|
nsIChannel* newChannel, uint32_t flags);
|
|
|
|
/**
|
|
* Initialize and run the chain of AsyncOnChannelRedirect calls. OldChannel
|
|
* is QI'ed for nsIAsyncVerifyRedirectCallback. The result of the redirect
|
|
* decision is passed through this interface back to the oldChannel.
|
|
*
|
|
* @param oldChan
|
|
* channel being redirected, MUST implement
|
|
* nsIAsyncVerifyRedirectCallback
|
|
* @param newChan
|
|
* target of the redirect channel
|
|
* @param flags
|
|
* redirect flags
|
|
* @param mainThreadEventTarget
|
|
* a labeled event target for dispatching runnables
|
|
* @param synchronize
|
|
* set to TRUE if you want the Init method wait synchronously for
|
|
* all redirect callbacks
|
|
*/
|
|
nsresult Init(nsIChannel* oldChan, nsIChannel* newChan, uint32_t flags,
|
|
nsIEventTarget* mainThreadEventTarget,
|
|
bool synchronize = false);
|
|
|
|
protected:
|
|
nsCOMPtr<nsIChannel> mOldChan;
|
|
nsCOMPtr<nsIChannel> mNewChan;
|
|
uint32_t mFlags{0};
|
|
bool mWaitingForRedirectCallback{false};
|
|
nsCOMPtr<nsIEventTarget> mCallbackEventTarget;
|
|
bool mCallbackInitiated{false};
|
|
int32_t mExpectedCallbacks{0};
|
|
nsresult mResult{NS_OK}; // value passed to callback
|
|
|
|
void InitCallback();
|
|
|
|
/**
|
|
* Calls back to |oldChan| as described in Init()
|
|
*/
|
|
void ExplicitCallback(nsresult result);
|
|
|
|
private:
|
|
~nsAsyncRedirectVerifyHelper();
|
|
|
|
bool IsOldChannelCanceled();
|
|
};
|
|
|
|
/*
|
|
* Helper to make the call-stack handle some control-flow for us
|
|
*/
|
|
class nsAsyncRedirectAutoCallback {
|
|
public:
|
|
explicit nsAsyncRedirectAutoCallback(
|
|
nsIAsyncVerifyRedirectCallback* aCallback)
|
|
: mCallback(aCallback) {
|
|
mResult = NS_OK;
|
|
}
|
|
~nsAsyncRedirectAutoCallback() {
|
|
if (mCallback) mCallback->OnRedirectVerifyCallback(mResult);
|
|
}
|
|
/*
|
|
* Call this is you want it to call back with a different result-code
|
|
*/
|
|
void SetResult(nsresult aRes) { mResult = aRes; }
|
|
/*
|
|
* Call this is you want to avoid the callback
|
|
*/
|
|
void DontCallback() { mCallback = nullptr; }
|
|
|
|
private:
|
|
nsIAsyncVerifyRedirectCallback* mCallback;
|
|
nsresult mResult;
|
|
};
|
|
|
|
} // namespace net
|
|
} // namespace mozilla
|
|
#endif
|