summaryrefslogtreecommitdiffstats
path: root/content/browser/streams/stream_handle_impl.cc
blob: ba4dee2a4900945af800f2429e0f8edf24d270b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/streams/stream_handle_impl.h"

#include "base/bind.h"
#include "base/location.h"
#include "base/thread_task_runner_handle.h"
#include "content/browser/streams/stream.h"

namespace content {

namespace {

void RunCloseListeners(const std::vector<base::Closure>& close_listeners) {
  for (size_t i = 0; i < close_listeners.size(); ++i)
    close_listeners[i].Run();
}

}  // namespace

StreamHandleImpl::StreamHandleImpl(const base::WeakPtr<Stream>& stream)
    : stream_(stream),
      url_(stream->url()),
      stream_task_runner_(base::ThreadTaskRunnerHandle::Get().get()) {
}

StreamHandleImpl::~StreamHandleImpl() {
  stream_task_runner_->PostTaskAndReply(
      FROM_HERE, base::Bind(&Stream::CloseHandle, stream_),
      base::Bind(&RunCloseListeners, close_listeners_));
}

const GURL& StreamHandleImpl::GetURL() {
  return url_;
}

void StreamHandleImpl::AddCloseListener(const base::Closure& callback) {
  close_listeners_.push_back(callback);
}

}  // namespace content