tor-browser

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

time_controller.h (2563B)


      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 #ifndef API_TEST_TIME_CONTROLLER_H_
     11 #define API_TEST_TIME_CONTROLLER_H_
     12 
     13 #include <functional>
     14 #include <memory>
     15 #include <string>
     16 
     17 #include "api/task_queue/task_queue_factory.h"
     18 #include "api/units/time_delta.h"
     19 #include "rtc_base/socket_server.h"
     20 #include "rtc_base/thread.h"
     21 #include "system_wrappers/include/clock.h"
     22 
     23 namespace webrtc {
     24 // Interface for controlling time progress. This allows us to execute test code
     25 // in either real time or simulated time by using different implementation of
     26 // this interface.
     27 class TimeController {
     28 public:
     29  virtual ~TimeController() = default;
     30  // Provides a clock instance that follows implementation defined time
     31  // progress.
     32  virtual Clock* GetClock() = 0;
     33  // The returned factory will created task queues that runs in implementation
     34  // defined time domain.
     35  virtual TaskQueueFactory* GetTaskQueueFactory() = 0;
     36  // Simple helper to create an owned factory that can be used as a parameter
     37  // for PeerConnectionFactory. Note that this might depend on the underlying
     38  // time controller and therfore must be destroyed before the time controller
     39  // is destroyed.
     40  std::unique_ptr<TaskQueueFactory> CreateTaskQueueFactory();
     41 
     42  // Creates an Thread instance. If `socket_server` is nullptr, a
     43  // default noop socket server is created. Returned thread is not null and
     44  // started.
     45  virtual std::unique_ptr<Thread> CreateThread(
     46      const std::string& name,
     47      std::unique_ptr<SocketServer> socket_server = nullptr) = 0;
     48 
     49  // Creates an Thread instance that ensure that it's set as the current
     50  // thread.
     51  virtual Thread* GetMainThread() = 0;
     52  // Allow task queues and process threads created by this instance to execute
     53  // for the given `duration`.
     54  virtual void AdvanceTime(TimeDelta duration) = 0;
     55 
     56  // Waits until condition() == true, polling condition() in small time
     57  // intervals.
     58  // Returns true if condition() was evaluated to true before `max_duration`
     59  // elapsed and false otherwise.
     60  bool Wait(const std::function<bool()>& condition,
     61            TimeDelta max_duration = TimeDelta::Seconds(5));
     62 };
     63 
     64 }  // namespace webrtc
     65 #endif  // API_TEST_TIME_CONTROLLER_H_