taskparent.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright 2004 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 THIRD_PARTY_LIBJINGLE_XMPP_TASK_RUNNER_TASKPARENT_H_
  11. #define THIRD_PARTY_LIBJINGLE_XMPP_TASK_RUNNER_TASKPARENT_H_
  12. #include <memory>
  13. #include <set>
  14. #include "base/check_op.h"
  15. #include "base/macros.h"
  16. namespace jingle_xmpp {
  17. class Task;
  18. class TaskRunner;
  19. class TaskParent {
  20. public:
  21. TaskParent(Task *derived_instance, TaskParent *parent);
  22. explicit TaskParent(TaskRunner *derived_instance);
  23. virtual ~TaskParent();
  24. TaskParent *GetParent() { return parent_; }
  25. TaskRunner *GetRunner() { return runner_; }
  26. bool AllChildrenDone();
  27. bool AnyChildError();
  28. #if DCHECK_IS_ON
  29. bool IsChildTask(Task *task);
  30. #endif
  31. protected:
  32. void OnStopped(Task *task);
  33. void AbortAllChildren();
  34. TaskParent *parent() {
  35. return parent_;
  36. }
  37. private:
  38. void Initialize();
  39. void OnChildStopped(Task *child);
  40. void AddChild(Task *child);
  41. TaskParent *parent_;
  42. TaskRunner *runner_;
  43. bool child_error_;
  44. typedef std::set<Task *> ChildSet;
  45. std::unique_ptr<ChildSet> children_;
  46. DISALLOW_COPY_AND_ASSIGN(TaskParent);
  47. };
  48. } // namespace jingle_xmpp
  49. #endif // THIRD_PARTY_LIBJINGLE_XMPP_TASK_RUNNER_TASKPARENT_H_