cast_browser_main_parts.cc revision 6e8cce623b6e4fe0c9e4af605d675dd9d0338c38
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. 4 5#include "chromecast/shell/browser/cast_browser_main_parts.h" 6 7#include "base/command_line.h" 8#include "base/prefs/pref_registry_simple.h" 9#include "chromecast/common/chromecast_config.h" 10#include "chromecast/net/network_change_notifier_cast.h" 11#include "chromecast/net/network_change_notifier_factory_cast.h" 12#include "chromecast/service/cast_service.h" 13#include "chromecast/shell/browser/cast_browser_context.h" 14#include "chromecast/shell/browser/devtools/remote_debugging_server.h" 15#include "chromecast/shell/browser/url_request_context_factory.h" 16#include "chromecast/shell/browser/webui/webui_cast.h" 17#include "content/public/common/content_switches.h" 18 19namespace chromecast { 20namespace shell { 21 22namespace { 23 24struct DefaultCommandLineSwitch { 25 const char* const switch_name; 26 const char* const switch_value; 27}; 28 29DefaultCommandLineSwitch g_default_switches[] = { 30 { switches::kDisableApplicationCache, "" }, 31 { switches::kDisablePlugins, "" }, 32 { NULL, NULL }, // Termination 33}; 34 35void AddDefaultCommandLineSwitches(CommandLine* command_line) { 36 int i = 0; 37 while (g_default_switches[i].switch_name != NULL) { 38 command_line->AppendSwitchASCII( 39 std::string(g_default_switches[i].switch_name), 40 std::string(g_default_switches[i].switch_value)); 41 ++i; 42 } 43} 44 45} // namespace 46 47CastBrowserMainParts::CastBrowserMainParts( 48 const content::MainFunctionParams& parameters, 49 URLRequestContextFactory* url_request_context_factory) 50 : BrowserMainParts(), 51 url_request_context_factory_(url_request_context_factory) { 52 CommandLine* command_line = CommandLine::ForCurrentProcess(); 53 AddDefaultCommandLineSwitches(command_line); 54} 55 56CastBrowserMainParts::~CastBrowserMainParts() { 57} 58 59void CastBrowserMainParts::PreMainMessageLoopStart() { 60 net::NetworkChangeNotifier::SetFactory( 61 new NetworkChangeNotifierFactoryCast()); 62} 63 64void CastBrowserMainParts::PostMainMessageLoopStart() { 65 NOTIMPLEMENTED(); 66} 67 68int CastBrowserMainParts::PreCreateThreads() { 69 ChromecastConfig::Create(new PrefRegistrySimple()); 70 return 0; 71} 72 73void CastBrowserMainParts::PreMainMessageLoopRun() { 74 url_request_context_factory_->InitializeOnUIThread(); 75 76 browser_context_.reset(new CastBrowserContext(url_request_context_factory_)); 77 dev_tools_.reset(new RemoteDebuggingServer()); 78 79 InitializeWebUI(); 80 81 cast_service_.reset(CastService::Create(browser_context_.get())); 82 cast_service_->Start(); 83} 84 85bool CastBrowserMainParts::MainMessageLoopRun(int* result_code) { 86 base::MessageLoopForUI::current()->Run(); 87 return true; 88} 89 90void CastBrowserMainParts::PostMainMessageLoopRun() { 91 cast_service_->Stop(); 92 93 cast_service_.reset(); 94 dev_tools_.reset(); 95 browser_context_.reset(); 96} 97 98} // namespace shell 99} // namespace chromecast 100