tor-browser

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

resource.h (2220B)


      1 /*
      2 *  Copyright 2019 The WebRTC Project Authors. All rights reserved.
      3 *
      4 *  Use of this source code is governed by a BSD-style license
      5 *  that can be found in the LICENSE file in the root of the source
      6 *  tree. An additional intellectual property rights grant can be found
      7 *  in the file PATENTS.  All contributing project authors may
      8 *  be found in the AUTHORS file in the root of the source tree.
      9 */
     10 
     11 #ifndef API_ADAPTATION_RESOURCE_H_
     12 #define API_ADAPTATION_RESOURCE_H_
     13 
     14 #include <string>
     15 
     16 #include "api/ref_count.h"
     17 #include "api/scoped_refptr.h"
     18 #include "rtc_base/system/rtc_export.h"
     19 
     20 namespace webrtc {
     21 
     22 class Resource;
     23 
     24 enum class ResourceUsageState {
     25  // Action is needed to minimze the load on this resource.
     26  kOveruse,
     27  // Increasing the load on this resource is desired, if possible.
     28  kUnderuse,
     29 };
     30 
     31 RTC_EXPORT const char* ResourceUsageStateToString(
     32    ResourceUsageState usage_state);
     33 
     34 class RTC_EXPORT ResourceListener {
     35 public:
     36  virtual ~ResourceListener();
     37 
     38  virtual void OnResourceUsageStateMeasured(scoped_refptr<Resource> resource,
     39                                            ResourceUsageState usage_state) = 0;
     40 };
     41 
     42 // A Resource monitors an implementation-specific resource. It may report
     43 // kOveruse or kUnderuse when resource usage is high or low enough that we
     44 // should perform some sort of mitigation to fulfil the resource's constraints.
     45 //
     46 // The methods on this interface are invoked on the adaptation task queue.
     47 // Resource usage measurements may be performed on an any task queue.
     48 //
     49 // The Resource is reference counted to prevent use-after-free when posting
     50 // between task queues. As such, the implementation MUST NOT make any
     51 // assumptions about which task queue Resource is destructed on.
     52 class RTC_EXPORT Resource : public RefCountInterface {
     53 public:
     54  Resource();
     55  // Destruction may happen on any task queue.
     56  ~Resource() override;
     57 
     58  virtual std::string Name() const = 0;
     59  // The `listener` may be informed of resource usage measurements on any task
     60  // queue, but not after this method is invoked with the null argument.
     61  virtual void SetResourceListener(ResourceListener* listener) = 0;
     62 };
     63 
     64 }  // namespace webrtc
     65 
     66 #endif  // API_ADAPTATION_RESOURCE_H_