Skip to content

Commit

Permalink
Roll WebRTC 13978:13983 (5 commits)
Browse files Browse the repository at this point in the history
Changes: https://chromium.googlesource.com/external/webrtc/trunk/webrtc.git/+log/854d164..e5dcf5c

$ git log 854d164..e5dcf5c --date=short --no-merges --format=%ad %ae %s
2016-08-30 perkj@webrtc.org Do not build task_queue.cc and include from webrtc_overrides in Chrome. This is step 2 of the plan below.
2016-08-30 honghaiz@webrtc.org Add a switch to redetermine role when ICE restarts.
2016-08-30 hbos@webrtc.org Making hbos and hta OWNERS of webrtc/api/rtcstats*.
2016-08-30 kjellander@webrtc.org MB: Flip iOS bots to GN by default
2016-08-30 hbos@webrtc.org RTCStatsCollector and RTCPeerConnectionStats added.

Override webrtc task_queue.cc and task_queue.h.
This is step 3 of the plan below.

The modified plan
1. First land unmodified task_queue.h into webrtc_override in Chrome
2. Modify build files in the webrtc repo to include the task_queue.h and task_queue.cc from webrtc_overrides. This will breaks webrtc Chrome FYI.
3. Combine a roll of webrtc to Chrome and this cl  into one  cl.
The combined cl will roll in build files from  2 and  add task_queue.cc in webrtc_overrides and build task_queue_unittest.cc as part of content_unittests to test task_queue.cc in webrtc_overrides.
4... Start using task queues in webrtc........

TBR=tommi@chromium.org

CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_chromium_archive_rel_ng;master.tryserver.chromium.mac:mac_chromium_archive_rel_ng

BUG=webrtc:5687

Review-Url: https://codereview.chromium.org/2295723004
Cr-Commit-Position: refs/heads/master@{#415579}
  • Loading branch information
perkj authored and Commit bot committed Aug 31, 2016
1 parent 85f727b commit 103f054
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 67 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ deps = {
Var('chromium_git') + '/native_client/src/third_party/scons-2.0.1.git' + '@' + '1c1550e17fc26355d08627fbdec13d8291227067',

'src/third_party/webrtc':
Var('chromium_git') + '/external/webrtc/trunk/webrtc.git' + '@' + '854d164fae9b0d4a2703d0bfb105bd4151b60ed3', # commit position 13978
Var('chromium_git') + '/external/webrtc/trunk/webrtc.git' + '@' + 'e5dcf5c76c793e7355be2876cd9141e4289f8c9f', # commit position 13983

'src/third_party/openmax_dl':
Var('chromium_git') + '/external/webrtc/deps/third_party/openmax.git' + '@' + Var('openmax_dl_revision'),
Expand Down
2 changes: 2 additions & 0 deletions content/content_tests.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,8 @@
],
# WebRTC-specific sources. Put WebRTC plugin-related stuff further below.
'content_unittests_webrtc_sources': [
# |task_queue_unittest.cc| is added to test the webrtc_override of TaskQueue.
'../third_party/webrtc/base/task_queue_unittest.cc',
'browser/renderer_host/p2p/socket_host_tcp_server_unittest.cc',
'browser/renderer_host/p2p/socket_host_tcp_unittest.cc',
'browser/renderer_host/p2p/socket_host_test_utils.cc',
Expand Down
135 changes: 135 additions & 0 deletions third_party/webrtc_overrides/webrtc/base/task_queue.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Copyright 2016 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/

#include "third_party/webrtc_overrides/webrtc/base/task_queue.h"

#include "base/bind.h"
#include "base/lazy_instance.h"
#include "base/threading/thread.h"
#include "base/threading/thread_local.h"

namespace rtc {
namespace {

void RunTask(std::unique_ptr<QueuedTask> task) {
if (!task->Run())
task.release();
}

class PostAndReplyTask : public QueuedTask {
public:
PostAndReplyTask(
std::unique_ptr<QueuedTask> task,
std::unique_ptr<QueuedTask> reply,
const scoped_refptr<base::SingleThreadTaskRunner>& reply_task_runner)
: task_(std::move(task)),
reply_(std::move(reply)),
reply_task_runner_(reply_task_runner) {}

~PostAndReplyTask() override {}

private:
bool Run() override {
if (!task_->Run())
task_.release();

reply_task_runner_->PostTask(FROM_HERE,
base::Bind(&RunTask, base::Passed(&reply_)));
return true;
}

std::unique_ptr<QueuedTask> task_;
std::unique_ptr<QueuedTask> reply_;
scoped_refptr<base::SingleThreadTaskRunner> reply_task_runner_;
};

// A lazily created thread local storage for quick access to a TaskQueue.
base::LazyInstance<base::ThreadLocalPointer<TaskQueue>>::Leaky lazy_tls_ptr =
LAZY_INSTANCE_INITIALIZER;

} // namespace

bool TaskQueue::IsCurrent() const {
return Current() == this;
}

class TaskQueue::WorkerThread : public base::Thread {
public:
WorkerThread(const char* queue_name, TaskQueue* queue);
~WorkerThread() override;

private:
virtual void Init() override;

TaskQueue* const queue_;
};

TaskQueue::WorkerThread::WorkerThread(const char* queue_name, TaskQueue* queue)
: base::Thread(queue_name), queue_(queue) {}

void TaskQueue::WorkerThread::Init() {
lazy_tls_ptr.Pointer()->Set(queue_);
}

TaskQueue::WorkerThread::~WorkerThread() {
DCHECK(!Thread::IsRunning());
}

TaskQueue::TaskQueue(const char* queue_name)
: thread_(
std::unique_ptr<WorkerThread>(new WorkerThread(queue_name, this))) {
DCHECK(queue_name);
bool result = thread_->Start();
CHECK(result);
}

TaskQueue::~TaskQueue() {
DCHECK(!IsCurrent());
thread_->Stop();
}

// static
TaskQueue* TaskQueue::Current() {
return lazy_tls_ptr.Pointer()->Get();
}

// static
bool TaskQueue::IsCurrent(const char* queue_name) {
TaskQueue* current = Current();
return current && current->thread_->thread_name().compare(queue_name) == 0;
}

void TaskQueue::PostTask(std::unique_ptr<QueuedTask> task) {
thread_->task_runner()->PostTask(FROM_HERE,
base::Bind(&RunTask, base::Passed(&task)));
}

void TaskQueue::PostDelayedTask(std::unique_ptr<QueuedTask> task,
uint32_t milliseconds) {
thread_->task_runner()->PostDelayedTask(
FROM_HERE, base::Bind(&RunTask, base::Passed(&task)),
base::TimeDelta::FromMilliseconds(milliseconds));
}

void TaskQueue::PostTaskAndReply(std::unique_ptr<QueuedTask> task,
std::unique_ptr<QueuedTask> reply,
TaskQueue* reply_queue) {
PostTask(std::unique_ptr<QueuedTask>(new PostAndReplyTask(
std::move(task), std::move(reply), reply_queue->thread_->task_runner())));
}

void TaskQueue::PostTaskAndReply(std::unique_ptr<QueuedTask> task,
std::unique_ptr<QueuedTask> reply) {
thread_->task_runner()->PostTaskAndReply(
FROM_HERE, base::Bind(&RunTask, base::Passed(&task)),
base::Bind(&RunTask, base::Passed(&reply)));
}

} // namespace rtc
73 changes: 7 additions & 66 deletions third_party/webrtc_overrides/webrtc/base/task_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,11 @@
#ifndef WEBRTC_BASE_TASK_QUEUE_H_
#define WEBRTC_BASE_TASK_QUEUE_H_

#include <list>
#include <memory>
#include <unordered_map>
#include <stdint.h>

#if defined(WEBRTC_MAC) && !defined(WEBRTC_BUILD_LIBEVENT)
#include <dispatch/dispatch.h>
#endif

#include "third_party/webrtc/base/constructormagic.h"
#include "third_party/webrtc/base/criticalsection.h"

#if defined(WEBRTC_WIN) || defined(WEBRTC_BUILD_LIBEVENT)
#include "third_party/webrtc/base/platform_thread.h"
#endif

#if defined(WEBRTC_BUILD_LIBEVENT)
struct event_base;
struct event;
#endif
#include "base/macros.h"
#include "third_party/webrtc/base/thread_annotations.h"

namespace rtc {

Expand All @@ -49,7 +35,7 @@ class QueuedTask {
virtual bool Run() = 0;

private:
RTC_DISALLOW_COPY_AND_ASSIGN(QueuedTask);
DISALLOW_COPY_AND_ASSIGN(QueuedTask);
};

// Simple implementation of QueuedTask for use with rtc::Bind and lambdas.
Expand Down Expand Up @@ -225,55 +211,10 @@ class LOCKABLE TaskQueue {
}

private:
#if defined(WEBRTC_BUILD_LIBEVENT)
static bool ThreadMain(void* context);
static void OnWakeup(int socket, short flags, void* context); // NOLINT
static void RunTask(int fd, short flags, void* context); // NOLINT
static void RunTimer(int fd, short flags, void* context); // NOLINT

class PostAndReplyTask;
class SetTimerTask;

void PrepareReplyTask(PostAndReplyTask* reply_task);
void ReplyTaskDone(PostAndReplyTask* reply_task);

struct QueueContext;

int wakeup_pipe_in_ = -1;
int wakeup_pipe_out_ = -1;
event_base* event_base_;
std::unique_ptr<event> wakeup_event_;
PlatformThread thread_;
rtc::CriticalSection pending_lock_;
std::list<std::unique_ptr<QueuedTask>> pending_ GUARDED_BY(pending_lock_);
std::list<PostAndReplyTask*> pending_replies_ GUARDED_BY(pending_lock_);
#elif defined(WEBRTC_MAC)
struct QueueContext;
struct TaskContext;
struct PostTaskAndReplyContext;
dispatch_queue_t queue_;
QueueContext* const context_;
#elif defined(WEBRTC_WIN)
typedef std::unordered_map<UINT_PTR, std::unique_ptr<QueuedTask>>
DelayedTasks;
static bool ThreadMain(void* context);
static bool ProcessQueuedMessages(DelayedTasks* delayed_tasks);

class WorkerThread : public PlatformThread {
public:
WorkerThread(ThreadRunFunction func, void* obj, const char* thread_name)
: PlatformThread(func, obj, thread_name) {}

bool QueueAPC(PAPCFUNC apc_function, ULONG_PTR data) {
return PlatformThread::QueueAPC(apc_function, data);
}
};
WorkerThread thread_;
#else
#error not supported.
#endif
class WorkerThread;

RTC_DISALLOW_COPY_AND_ASSIGN(TaskQueue);
std::unique_ptr<WorkerThread> thread_;
DISALLOW_COPY_AND_ASSIGN(TaskQueue);
};

} // namespace rtc
Expand Down

0 comments on commit 103f054

Please sign in to comment.