Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromecast/browser/cast_browser_main_parts.h" | 5 #include "chromecast/browser/cast_browser_main_parts.h" |
| 6 | 6 |
| 7 #include <signal.h> | 7 #include <signal.h> |
| 8 #include <sys/prctl.h> | 8 #include <sys/prctl.h> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 #include "media/base/media_switches.h" | 37 #include "media/base/media_switches.h" |
| 38 | 38 |
| 39 #if defined(OS_ANDROID) | 39 #if defined(OS_ANDROID) |
| 40 #include "chromecast/crash/android/crash_handler.h" | 40 #include "chromecast/crash/android/crash_handler.h" |
| 41 #include "components/crash/browser/crash_dump_manager_android.h" | 41 #include "components/crash/browser/crash_dump_manager_android.h" |
| 42 #include "net/android/network_change_notifier_factory_android.h" | 42 #include "net/android/network_change_notifier_factory_android.h" |
| 43 #endif | 43 #endif |
| 44 | 44 |
| 45 namespace { | 45 namespace { |
| 46 | 46 |
| 47 #if !defined(OS_ANDROID) | |
| 47 int kSignalsToRunClosure[] = { SIGTERM, SIGINT, }; | 48 int kSignalsToRunClosure[] = { SIGTERM, SIGINT, }; |
| 48 | 49 |
| 49 // Closure to run on SIGTERM and SIGINT. | 50 // Closure to run on SIGTERM and SIGINT. |
| 50 base::Closure* g_signal_closure = NULL; | 51 base::Closure* g_signal_closure = NULL; |
| 51 | 52 |
| 52 void RunClosureOnSignal(int signum) { | 53 void RunClosureOnSignal(int signum) { |
| 53 LOG(ERROR) << "Got signal " << signum; | 54 LOG(ERROR) << "Got signal " << signum; |
| 54 DCHECK(g_signal_closure); | 55 DCHECK(g_signal_closure); |
| 55 // Expect main thread got this signal. Otherwise, weak_ptr of run_loop will | 56 // Expect main thread got this signal. Otherwise, weak_ptr of run_loop will |
| 56 // crash the process. | 57 // crash the process. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 75 if (sigaction(kSignalsToRunClosure[i], &sa_new, &sa_old) == -1) { | 76 if (sigaction(kSignalsToRunClosure[i], &sa_new, &sa_old) == -1) { |
| 76 NOTREACHED(); | 77 NOTREACHED(); |
| 77 } else { | 78 } else { |
| 78 DCHECK_EQ(sa_old.sa_handler, SIG_DFL); | 79 DCHECK_EQ(sa_old.sa_handler, SIG_DFL); |
| 79 } | 80 } |
| 80 } | 81 } |
| 81 | 82 |
| 82 // Get the first signal to exit when the parent process dies. | 83 // Get the first signal to exit when the parent process dies. |
| 83 prctl(PR_SET_PDEATHSIG, kSignalsToRunClosure[0]); | 84 prctl(PR_SET_PDEATHSIG, kSignalsToRunClosure[0]); |
| 84 } | 85 } |
| 86 #endif // !defined(OS_ANDROID) | |
| 85 | 87 |
| 86 } // namespace | 88 } // namespace |
| 87 | 89 |
| 88 namespace chromecast { | 90 namespace chromecast { |
| 89 namespace shell { | 91 namespace shell { |
| 90 | 92 |
| 91 namespace { | 93 namespace { |
| 92 | 94 |
| 93 struct DefaultCommandLineSwitch { | 95 struct DefaultCommandLineSwitch { |
| 94 const char* const switch_name; | 96 const char* const switch_name; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 cast_browser_process_->metrics_service_client(), | 240 cast_browser_process_->metrics_service_client(), |
| 239 url_request_context_factory_->GetSystemGetter())); | 241 url_request_context_factory_->GetSystemGetter())); |
| 240 cast_browser_process_->cast_service()->Initialize(); | 242 cast_browser_process_->cast_service()->Initialize(); |
| 241 | 243 |
| 242 // Initializing metrics service and network delegates must happen after cast | 244 // Initializing metrics service and network delegates must happen after cast |
| 243 // service is intialized because CastMetricsServiceClient and | 245 // service is intialized because CastMetricsServiceClient and |
| 244 // CastNetworkDelegate may use components initialized by cast service. | 246 // CastNetworkDelegate may use components initialized by cast service. |
| 245 cast_browser_process_->metrics_service_client() | 247 cast_browser_process_->metrics_service_client() |
| 246 ->Initialize(cast_browser_process_->cast_service()); | 248 ->Initialize(cast_browser_process_->cast_service()); |
| 247 url_request_context_factory_->InitializeNetworkDelegates(); | 249 url_request_context_factory_->InitializeNetworkDelegates(); |
| 250 | |
| 251 cast_browser_process_->cast_service()->Start(); | |
| 248 } | 252 } |
| 249 | 253 |
| 250 bool CastBrowserMainParts::MainMessageLoopRun(int* result_code) { | 254 bool CastBrowserMainParts::MainMessageLoopRun(int* result_code) { |
| 251 cast_browser_process_->cast_service()->Start(); | 255 #if defined(OS_ANDROID) |
| 252 | 256 // Android does not use native main MessageLoop. |
| 257 NOTREACHED(); | |
| 258 return true; | |
| 259 #else | |
| 253 base::RunLoop run_loop; | 260 base::RunLoop run_loop; |
| 254 base::Closure quit_closure(run_loop.QuitClosure()); | 261 base::Closure quit_closure(run_loop.QuitClosure()); |
| 255 RegisterClosureOnSignal(quit_closure); | 262 RegisterClosureOnSignal(quit_closure); |
| 256 | 263 |
| 257 // If parameters_.ui_task is not NULL, we are running browser tests. | 264 // If parameters_.ui_task is not NULL, we are running browser tests. |
| 258 if (parameters_.ui_task) { | 265 if (parameters_.ui_task) { |
| 259 base::MessageLoop* message_loop = base::MessageLoopForUI::current(); | 266 base::MessageLoop* message_loop = base::MessageLoopForUI::current(); |
| 260 message_loop->PostTask(FROM_HERE, *parameters_.ui_task); | 267 message_loop->PostTask(FROM_HERE, *parameters_.ui_task); |
| 261 message_loop->PostTask(FROM_HERE, quit_closure); | 268 message_loop->PostTask(FROM_HERE, quit_closure); |
| 262 } | 269 } |
| 263 | 270 |
| 264 run_loop.Run(); | 271 run_loop.Run(); |
| 265 | 272 |
| 266 cast_browser_process_->cast_service()->Stop(); | 273 cast_browser_process_->cast_service()->Stop(); |
| 267 return true; | 274 return true; |
| 275 #endif | |
| 268 } | 276 } |
| 269 | 277 |
| 270 void CastBrowserMainParts::PostMainMessageLoopRun() { | 278 void CastBrowserMainParts::PostMainMessageLoopRun() { |
| 279 #if defined(OS_ANDROID) | |
| 280 // Android does not use native main MessageLoop. | |
| 281 NOTREACHED(); | |
| 282 #else | |
| 271 cast_browser_process_->cast_service()->Finalize(); | 283 cast_browser_process_->cast_service()->Finalize(); |
| 272 cast_browser_process_->metrics_service_client()->Finalize(); | 284 cast_browser_process_->metrics_service_client()->Finalize(); |
| 273 cast_browser_process_.reset(); | 285 cast_browser_process_.reset(); |
|
lcwu1
2015/02/25 21:48:27
Where does the tear-down of the cast objects take
gunsch
2015/02/25 21:58:57
It doesn't. For a similar comment, see:
https://co
| |
| 286 #endif | |
| 274 } | 287 } |
| 275 | 288 |
| 276 } // namespace shell | 289 } // namespace shell |
| 277 } // namespace chromecast | 290 } // namespace chromecast |
| OLD | NEW |