Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / chromecast / browser / service / cast_service.cc
blobd725abe239787fd6a378f5b7758fc5d8d656a5cf
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),
20 stopped_(true),
21 thread_checker_(new base::ThreadChecker()) {
24 CastService::~CastService() {
25 DCHECK(thread_checker_->CalledOnValidThread());
26 DCHECK(stopped_);
29 void CastService::Initialize() {
30 DCHECK(thread_checker_->CalledOnValidThread());
31 InitializeInternal();
34 void CastService::Finalize() {
35 DCHECK(thread_checker_->CalledOnValidThread());
36 FinalizeInternal();
39 void CastService::Start() {
40 DCHECK(thread_checker_->CalledOnValidThread());
41 stopped_ = false;
42 StartInternal();
45 void CastService::Stop() {
46 DCHECK(thread_checker_->CalledOnValidThread());
47 StopInternal();
48 // Consume any pending tasks which should be done before destroying in-process
49 // renderer process, for example, destroying web_contents.
50 base::RunLoop().RunUntilIdle();
51 stopped_ = true;
54 } // namespace chromecast