Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: third_party/libjingle_xmpp/task_runner/taskparent.cc

Issue 2694903005: Add a copy of webrtc's TaskRunner abstraction, which is going to be deleted in webrtc. (Closed)
Patch Set: Delete dependencies on webrtc's rtc_task_runner. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 #include <algorithm>
12
13 #include "third_party/libjingle_xmpp/task_runner/taskparent.h"
14
15 #include "third_party/libjingle_xmpp/task_runner/taskrunner.h"
16 #include "third_party/libjingle_xmpp/task_runner/task.h"
17 #include "third_party/webrtc/base/checks.h"
18
19 namespace rtc {
20
21 TaskParent::TaskParent(Task* derived_instance, TaskParent *parent)
22 : parent_(parent) {
23 RTC_DCHECK(derived_instance != NULL);
24 RTC_DCHECK(parent != NULL);
25 runner_ = parent->GetRunner();
26 parent_->AddChild(derived_instance);
27 Initialize();
28 }
29
30 TaskParent::TaskParent(TaskRunner *derived_instance)
31 : parent_(NULL),
32 runner_(derived_instance) {
33 RTC_DCHECK(derived_instance != NULL);
34 Initialize();
35 }
36
37 TaskParent::~TaskParent() = default;
38
39 // Does common initialization of member variables
40 void TaskParent::Initialize() {
41 children_.reset(new ChildSet());
42 child_error_ = false;
43 }
44
45 void TaskParent::AddChild(Task *child) {
46 children_->insert(child);
47 }
48
49 #if RTC_DCHECK_IS_ON
50 bool TaskParent::IsChildTask(Task *task) {
51 RTC_DCHECK(task != NULL);
52 return task->parent_ == this && children_->find(task) != children_->end();
53 }
54 #endif
55
56 bool TaskParent::AllChildrenDone() {
57 for (ChildSet::iterator it = children_->begin();
58 it != children_->end();
59 ++it) {
60 if (!(*it)->IsDone())
61 return false;
62 }
63 return true;
64 }
65
66 bool TaskParent::AnyChildError() {
67 return child_error_;
68 }
69
70 void TaskParent::AbortAllChildren() {
71 if (children_->size() > 0) {
72 #if RTC_DCHECK_IS_ON
73 runner_->IncrementAbortCount();
74 #endif
75
76 ChildSet copy = *children_;
77 for (ChildSet::iterator it = copy.begin(); it != copy.end(); ++it) {
78 (*it)->Abort(true); // Note we do not wake
79 }
80
81 #if RTC_DCHECK_IS_ON
82 runner_->DecrementAbortCount();
83 #endif
84 }
85 }
86
87 void TaskParent::OnStopped(Task *task) {
88 AbortAllChildren();
89 parent_->OnChildStopped(task);
90 }
91
92 void TaskParent::OnChildStopped(Task *child) {
93 if (child->HasError())
94 child_error_ = true;
95 children_->erase(child);
96 }
97
98 } // namespace rtc
OLDNEW
« no previous file with comments | « third_party/libjingle_xmpp/task_runner/taskparent.h ('k') | third_party/libjingle_xmpp/task_runner/taskrunner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698