summaryrefslogtreecommitdiffstats
path: root/chromecast/service/cast_service.cc
blob: c42043920a99569e2cc0ff3be765a36e1725995e (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
44
45
46
47
48
49
50
51
52
// Copyright 2014 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 "chromecast/service/cast_service.h"

#include "base/logging.h"
#include "base/run_loop.h"
#include "base/threading/thread_checker.h"

namespace chromecast {

CastService::CastService(
    content::BrowserContext* browser_context,
    PrefService* pref_service)
    : browser_context_(browser_context),
      pref_service_(pref_service),
      stopped_(true),
      thread_checker_(new base::ThreadChecker()) {
}

CastService::~CastService() {
  DCHECK(thread_checker_->CalledOnValidThread());
  DCHECK(stopped_);
}

void CastService::Initialize() {
  DCHECK(thread_checker_->CalledOnValidThread());
  InitializeInternal();
}

void CastService::Finalize() {
  DCHECK(thread_checker_->CalledOnValidThread());
  FinalizeInternal();
}

void CastService::Start() {
  DCHECK(thread_checker_->CalledOnValidThread());
  stopped_ = false;
  StartInternal();
}

void CastService::Stop() {
  DCHECK(thread_checker_->CalledOnValidThread());
  StopInternal();
  // Consume any pending tasks which should be done before destroying in-process
  // renderer process, for example, destroying web_contents.
  base::RunLoop().RunUntilIdle();
  stopped_ = true;
}

}  // namespace chromecast