Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / chromecast / shell / browser / cast_browser_main_parts.cc
blob8b98918dc9ef01baeeee2c9e3fd53880fbdb50b8
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/shell/browser/cast_browser_main_parts.h"
7 #include "base/command_line.h"
8 #include "base/prefs/pref_registry_simple.h"
9 #include "chromecast/common/chromecast_config.h"
10 #include "chromecast/metrics/cast_metrics_service_client.h"
11 #include "chromecast/net/network_change_notifier_cast.h"
12 #include "chromecast/net/network_change_notifier_factory_cast.h"
13 #include "chromecast/service/cast_service.h"
14 #include "chromecast/shell/browser/cast_browser_context.h"
15 #include "chromecast/shell/browser/devtools/remote_debugging_server.h"
16 #include "chromecast/shell/browser/url_request_context_factory.h"
17 #include "chromecast/shell/browser/webui/webui_cast.h"
18 #include "content/public/common/content_switches.h"
20 namespace chromecast {
21 namespace shell {
23 namespace {
25 struct DefaultCommandLineSwitch {
26 const char* const switch_name;
27 const char* const switch_value;
30 DefaultCommandLineSwitch g_default_switches[] = {
31 { switches::kDisableApplicationCache, "" },
32 { switches::kDisablePlugins, "" },
33 { NULL, NULL }, // Termination
36 void AddDefaultCommandLineSwitches(CommandLine* command_line) {
37 int i = 0;
38 while (g_default_switches[i].switch_name != NULL) {
39 command_line->AppendSwitchASCII(
40 std::string(g_default_switches[i].switch_name),
41 std::string(g_default_switches[i].switch_value));
42 ++i;
46 } // namespace
48 CastBrowserMainParts::CastBrowserMainParts(
49 const content::MainFunctionParams& parameters,
50 URLRequestContextFactory* url_request_context_factory)
51 : BrowserMainParts(),
52 url_request_context_factory_(url_request_context_factory) {
53 CommandLine* command_line = CommandLine::ForCurrentProcess();
54 AddDefaultCommandLineSwitches(command_line);
57 CastBrowserMainParts::~CastBrowserMainParts() {
60 void CastBrowserMainParts::PreMainMessageLoopStart() {
61 net::NetworkChangeNotifier::SetFactory(
62 new NetworkChangeNotifierFactoryCast());
65 void CastBrowserMainParts::PostMainMessageLoopStart() {
66 NOTIMPLEMENTED();
69 int CastBrowserMainParts::PreCreateThreads() {
70 ChromecastConfig::Create(new PrefRegistrySimple());
71 return 0;
74 void CastBrowserMainParts::PreMainMessageLoopRun() {
75 url_request_context_factory_->InitializeOnUIThread();
77 browser_context_.reset(new CastBrowserContext(url_request_context_factory_));
78 metrics_service_client_.reset(metrics::CastMetricsServiceClient::Create(
79 ChromecastConfig::GetInstance()->pref_service(),
80 browser_context_->GetRequestContext()));
81 dev_tools_.reset(new RemoteDebuggingServer());
83 InitializeWebUI();
85 cast_service_.reset(CastService::Create(browser_context_.get()));
86 cast_service_->Start();
89 bool CastBrowserMainParts::MainMessageLoopRun(int* result_code) {
90 base::MessageLoopForUI::current()->Run();
91 return true;
94 void CastBrowserMainParts::PostMainMessageLoopRun() {
95 cast_service_->Stop();
97 cast_service_.reset();
98 dev_tools_.reset();
99 metrics_service_client_.reset();
100 browser_context_.reset();
103 } // namespace shell
104 } // namespace chromecast