tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SandboxProfilerObserver.h (1803B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
      4 
      5 #ifndef SANDBOX_PROFILER_STARTUP_H
      6 #define SANDBOX_PROFILER_STARTUP_H
      7 
      8 #include "mozilla/Services.h"
      9 #include "nsCOMPtr.h"
     10 #include "nsIObserver.h"
     11 #include "nsIObserverService.h"
     12 #include "nsISupportsImpl.h"
     13 
     14 /*
     15 * This code is here to help bring up SandboxProfiler whenever the profiler
     16 * is started by the user. We cannot have that code live within
     17 * SandboxProfiler.cpp itself because we rely on libxul facilities, while the
     18 * sandbox code lives within libmozsandbox.
     19 */
     20 
     21 namespace {
     22 
     23 class ProfilerStartupObserverForSandboxProfiler final : public nsIObserver {
     24  ~ProfilerStartupObserverForSandboxProfiler() = default;
     25 
     26 public:
     27  NS_DECL_ISUPPORTS
     28  NS_DECL_NSIOBSERVER
     29 };
     30 
     31 NS_IMPL_ISUPPORTS(ProfilerStartupObserverForSandboxProfiler, nsIObserver)
     32 
     33 NS_IMETHODIMP ProfilerStartupObserverForSandboxProfiler::Observe(
     34    nsISupports* aSubject, const char* aTopic, const char16_t* aData) {
     35  if (strcmp(aTopic, "profiler-started") == 0) {
     36    mozilla::CreateSandboxProfiler();
     37    return NS_OK;
     38  }
     39 
     40  if (strcmp(aTopic, "profiler-stopped") == 0) {
     41    mozilla::DestroySandboxProfiler();
     42    return NS_OK;
     43  }
     44 
     45  return NS_OK;
     46 }
     47 
     48 }  // anonymous namespace
     49 
     50 inline void RegisterProfilerObserversForSandboxProfiler() {
     51  nsCOMPtr<nsIObserverService> obsServ(mozilla::services::GetObserverService());
     52  MOZ_ASSERT(!!obsServ);
     53  if (!obsServ) {
     54    return;
     55  }
     56 
     57  nsCOMPtr<nsIObserver> obs(new ProfilerStartupObserverForSandboxProfiler());
     58  obsServ->AddObserver(obs, "profiler-started", false);
     59  obsServ->AddObserver(obs, "profiler-stopped", false);
     60 }
     61 
     62 #endif  // SANDBOX_PROFILER_STARTUP_H