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