blob: c639f884b621cecab29faab9d419e7f7f84ffd9d [file] [log] [blame]
Alex Deymo53556ec2014-03-17 10:05:57 -07001// Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// TODO(deymo): These functions interact with the glib's main loop. This should
6// be replaced by the libbase main loop once the process is migrated to that
7// main loop.
8
Gilad Arnold48415f12014-06-27 07:10:58 -07009#ifndef UPDATE_ENGINE_UPDATE_MANAGER_EVENT_LOOP_H_
10#define UPDATE_ENGINE_UPDATE_MANAGER_EVENT_LOOP_H_
Alex Deymo53556ec2014-03-17 10:05:57 -070011
12#include <glib.h>
13
14#include <base/callback.h>
Alex Vakulenko75039d72014-03-25 12:36:28 -070015#include <base/time/time.h>
Alex Deymo53556ec2014-03-17 10:05:57 -070016
Alex Deymo63784a52014-05-28 10:46:14 -070017namespace chromeos_update_manager {
Alex Deymo53556ec2014-03-17 10:05:57 -070018
19typedef guint EventId;
20
Alex Vakulenko072359c2014-07-18 11:41:07 -070021// A null EventId doesn't identify any valid event.
Alex Deymo53556ec2014-03-17 10:05:57 -070022static constexpr EventId kEventIdNull = 0;
23
24// Schedules the passed |callback| to run from the GLib's main loop after a
25// timeout if it is given.
26EventId RunFromMainLoop(const base::Closure& callback);
27EventId RunFromMainLoopAfterTimeout(const base::Closure& callback,
28 base::TimeDelta timeout);
29
30// Removes the pending call |event| from the main loop. The value passed is the
31// one returned by the functions RunFromMainLoop*() when the call was scheduled.
32// Returns whether the event was found and removed.
33bool CancelMainLoopEvent(EventId event);
34
Alex Deymo63784a52014-05-28 10:46:14 -070035} // namespace chromeos_update_manager
Alex Deymo53556ec2014-03-17 10:05:57 -070036
Gilad Arnold48415f12014-06-27 07:10:58 -070037#endif // UPDATE_ENGINE_UPDATE_MANAGER_EVENT_LOOP_H_