Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chromecast / service / cast_service.cc
blobc42043920a99569e2cc0ff3be765a36e1725995e
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chromecast/service/cast_service.h"
7 #include "base/logging.h"
8 #include "base/run_loop.h"
9 #include "base/threading/thread_checker.h"
11 namespace chromecast {
13 CastService::CastService(
14 content::BrowserContext* browser_context,
15 PrefService* pref_service)
16 : browser_context_(browser_context),
17 pref_service_(pref_service),
18 stopped_(true),
19 thread_checker_(new base::ThreadChecker()) {
22 CastService::~CastService() {
23 DCHECK(thread_checker_->CalledOnValidThread());
24 DCHECK(stopped_);
27 void CastService::Initialize() {
28 DCHECK(thread_checker_->CalledOnValidThread());
29 InitializeInternal();
32 void CastService::Finalize() {
33 DCHECK(thread_checker_->CalledOnValidThread());
34 FinalizeInternal();
37 void CastService::Start() {
38 DCHECK(thread_checker_->CalledOnValidThread());
39 stopped_ = false;
40 StartInternal();
43 void CastService::Stop() {
44 DCHECK(thread_checker_->CalledOnValidThread());
45 StopInternal();
46 // Consume any pending tasks which should be done before destroying in-process
47 // renderer process, for example, destroying web_contents.
48 base::RunLoop().RunUntilIdle();
49 stopped_ = true;
52 } // namespace chromecast