dom/media/systemservices/LoadMonitor.h
author Wes Kocher <wkocher@mozilla.com>
Wed, 07 Oct 2015 10:19:19 -0700
changeset 299948 41dea9df27ed995f8315ab4318c187a617937664
parent 299739 91d4539e00cecb658604e021675a923c60ef3235
child 299952 6f47f75d3136c53eaf1b1fb0f9043f64ba9be42a
permissions -rw-r--r--
Backed out changeset 91d4539e00ce (bug 1207245)

/* -*- Mode: C++; tab-width: 50; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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 _LOADMONITOR_H_
#define _LOADMONITOR_H_

#include "mozilla/Mutex.h"
#include "mozilla/CondVar.h"
#include "mozilla/nsRefPtr.h"
#include "mozilla/Atomics.h"
#include "nsAutoPtr.h"
#include "nsCOMPtr.h"
#include "nsIThread.h"
#include "nsIObserver.h"

namespace mozilla {
class LoadInfoCollectRunner;

class LoadNotificationCallback
{
public:
    virtual void LoadChanged(float aSystemLoad, float aProcessLoad) = 0;
};

class LoadMonitor final : public nsIObserver
{
public:
    NS_DECL_THREADSAFE_ISUPPORTS
    NS_DECL_NSIOBSERVER

    explicit LoadMonitor(int aLoadUpdateInterval);

    nsresult Init(nsRefPtr<LoadMonitor> &self);
    void SetLoadChangeCallback(LoadNotificationCallback* aCallback);
    void Shutdown();
    float GetSystemLoad();
    float GetProcessLoad();

    friend class LoadInfoCollectRunner;

private:
    ~LoadMonitor();

    void SetProcessLoad(float load);
    void SetSystemLoad(float load);
    void FireCallbacks();

    int                  mLoadUpdateInterval;
    mozilla::Mutex       mLock;
    mozilla::CondVar     mCondVar;
    bool                 mShutdownPending;
    nsCOMPtr<nsIThread>  mLoadInfoThread;
    float                mSystemLoad;
    float                mProcessLoad;
    LoadNotificationCallback* mLoadNotificationCallback;
};

} //namespace

#endif /* _LOADMONITOR_H_ */