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