Bug 822135 - Disable Profiler when there's a Private Browsing Window. r=jdm

--HG--
rename : services/crypto/cryptoComponents.manifest => services/sync/SyncComponents.manifest
extra : rebase_source : 00ee2e343815d654fc33238b49f19225f39cf074
This commit is contained in:
Benoit Girard 2012-12-17 18:25:50 -05:00
parent 82daa77cd3
commit 0313fef329
5 changed files with 80 additions and 8 deletions

View File

@ -1240,3 +1240,18 @@ void mozilla_sampler_print_location()
printf_stderr("Backtrace:\n"); printf_stderr("Backtrace:\n");
threadProfile.IterateTags(print_callback); threadProfile.IterateTags(print_callback);
} }
void mozilla_sampler_lock()
{
mozilla_sampler_stop();
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os)
os->NotifyObservers(nullptr, "profiler-locked", nullptr);
}
void mozilla_sampler_unlock()
{
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os)
os->NotifyObservers(nullptr, "profiler-unlocked", nullptr);
}

View File

@ -11,24 +11,72 @@
#include "sampler.h" #include "sampler.h"
#include "nsProfiler.h" #include "nsProfiler.h"
#include "nsMemory.h" #include "nsMemory.h"
#include "shared-libraries.h"
#include "nsString.h" #include "nsString.h"
#include "mozilla/Services.h"
#include "nsIObserverService.h"
#include "nsIInterfaceRequestor.h"
#include "nsILoadContext.h"
#include "nsIWebNavigation.h"
#include "nsIInterfaceRequestorUtils.h"
#include "shared-libraries.h"
#include "jsapi.h" #include "jsapi.h"
using std::string; using std::string;
NS_IMPL_ISUPPORTS1(nsProfiler, nsIProfiler) NS_IMPL_ISUPPORTS1(nsProfiler, nsIProfiler)
nsProfiler::nsProfiler() nsProfiler::nsProfiler()
: mLockedForPrivateBrowsing(false)
{ {
} }
nsProfiler::~nsProfiler()
{
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
if (observerService) {
observerService->RemoveObserver(this, "chrome-document-global-created");
observerService->RemoveObserver(this, "last-pb-context-exited");
}
}
nsresult
nsProfiler::Init() {
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
if (observerService) {
observerService->AddObserver(this, "chrome-document-global-created", false);
observerService->AddObserver(this, "last-pb-context-exited", false);
}
return NS_OK;
}
NS_IMETHODIMP
nsProfiler::Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *aData)
{
if (strcmp(aTopic, "chrome-document-global-created") == 0) {
nsCOMPtr<nsIInterfaceRequestor> requestor = do_QueryInterface(aSubject);
nsCOMPtr<nsIWebNavigation> parentWebNav = do_GetInterface(requestor);
nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(parentWebNav);
if (loadContext && loadContext->UsePrivateBrowsing() && !mLockedForPrivateBrowsing) {
mLockedForPrivateBrowsing = true;
mozilla_sampler_lock();
}
} else if (strcmp(aTopic, "last-pb-context-exited") == 0) {
mLockedForPrivateBrowsing = false;
mozilla_sampler_unlock();
}
return NS_OK;
}
NS_IMETHODIMP NS_IMETHODIMP
nsProfiler::StartProfiler(uint32_t aEntries, uint32_t aInterval, nsProfiler::StartProfiler(uint32_t aEntries, uint32_t aInterval,
const char** aFeatures, uint32_t aFeatureCount) const char** aFeatures, uint32_t aFeatureCount)
{ {
if (mLockedForPrivateBrowsing) {
return NS_ERROR_NOT_AVAILABLE;
}
SAMPLER_START(aEntries, aInterval, aFeatures, aFeatureCount); SAMPLER_START(aEntries, aInterval, aFeatures, aFeatureCount);
#ifdef MOZ_INSTRUMENT_EVENT_LOOP #ifdef MOZ_INSTRUMENT_EVENT_LOOP
mozilla::InitEventTracing(); mozilla::InitEventTracing();
@ -126,8 +174,6 @@ nsProfiler::GetSharedLibraryInformation(nsAString& aOutString)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsProfiler::GetProfileData(JSContext* aCx, jsval* aResult) NS_IMETHODIMP nsProfiler::GetProfileData(JSContext* aCx, jsval* aResult)
{ {
JSObject *obj = SAMPLER_GET_PROFILE_DATA(aCx); JSObject *obj = SAMPLER_GET_PROFILE_DATA(aCx);

View File

@ -7,16 +7,22 @@
#define _NSPROFILER_H_ #define _NSPROFILER_H_
#include "nsIProfiler.h" #include "nsIProfiler.h"
#include "nsIObserver.h"
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h"
class nsProfiler MOZ_FINAL : public nsIProfiler class nsProfiler MOZ_FINAL : public nsIProfiler, public nsIObserver
{ {
public: public:
nsProfiler(); nsProfiler();
~nsProfiler();
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
NS_DECL_NSIPROFILER NS_DECL_NSIPROFILER
nsresult Init();
private:
bool mLockedForPrivateBrowsing;
}; };
#endif /* _NSPROFILER_H_ */ #endif /* _NSPROFILER_H_ */

View File

@ -8,7 +8,7 @@
#include "nsProfiler.h" #include "nsProfiler.h"
#include "nsProfilerCIID.h" #include "nsProfilerCIID.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(nsProfiler) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsProfiler, Init)
NS_DEFINE_NAMED_CID(NS_PROFILER_CID); NS_DEFINE_NAMED_CID(NS_PROFILER_CID);

View File

@ -178,8 +178,13 @@ JSObject *mozilla_sampler_get_profile_data(JSContext *aCx);
const char** mozilla_sampler_get_features(); const char** mozilla_sampler_get_features();
void mozilla_sampler_init(); void mozilla_sampler_init();
void mozilla_sampler_shutdown(); void mozilla_sampler_shutdown();
void mozilla_sampler_print_location(); void mozilla_sampler_print_location();
// Lock the profiler. When locked the profiler is (1) stopped,
// (2) profile data is cleared, (3) profiler-locked is fired.
// This is used to lock down the profiler during private browsing
void mozilla_sampler_lock();
// Unlock the profiler, leaving it stopped and fires profiler-unlocked.
void mozilla_sampler_unlock();
namespace mozilla { namespace mozilla {