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/browser/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 metrics::CastMetricsServiceClient
* metrics_service_client
)
17 : browser_context_(browser_context
),
18 pref_service_(pref_service
),
19 metrics_service_client_(metrics_service_client
),
21 thread_checker_(new base::ThreadChecker()) {
24 CastService::~CastService() {
25 DCHECK(thread_checker_
->CalledOnValidThread());
29 void CastService::Initialize() {
30 DCHECK(thread_checker_
->CalledOnValidThread());
34 void CastService::Finalize() {
35 DCHECK(thread_checker_
->CalledOnValidThread());
37 // Consume any pending tasks which may access components being destroyed soon.
38 base::RunLoop().RunUntilIdle();
41 void CastService::Start() {
42 DCHECK(thread_checker_
->CalledOnValidThread());
47 void CastService::Stop() {
48 DCHECK(thread_checker_
->CalledOnValidThread());
50 // Consume any pending tasks which should be done before destroying in-process
51 // renderer process, for example, destroying web_contents.
52 base::RunLoop().RunUntilIdle();
56 } // namespace chromecast