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