OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 "ui/viewer/viewer_process.h" |
| 6 |
| 7 #include "ui/viewer/viewer_ipc_server.h" |
| 8 #include "ui/viewer/viewer_host_win.h" |
| 9 |
| 10 ViewerProcess* g_viewer_process = NULL; |
| 11 |
| 12 ViewerProcess::ViewerProcess() |
| 13 : shutdown_event_(true, false), |
| 14 main_message_loop_(NULL) { |
| 15 DCHECK(!g_viewer_process); |
| 16 g_viewer_process = this; |
| 17 } |
| 18 |
| 19 ViewerProcess::~ViewerProcess() { |
| 20 Teardown(); |
| 21 g_viewer_process = NULL; |
| 22 } |
| 23 |
| 24 bool ViewerProcess::Initialize(MessageLoop* message_loop, |
| 25 const CommandLine& command_line) { |
| 26 main_message_loop_ = message_loop; |
| 27 |
| 28 base::Thread::Options options; |
| 29 options.message_loop_type = MessageLoop::TYPE_IO; |
| 30 io_thread_.reset(new base::Thread("ViewerProcess_IO")); |
| 31 if (!io_thread_->StartWithOptions(options)) { |
| 32 NOTREACHED(); |
| 33 Teardown(); |
| 34 return false; |
| 35 } |
| 36 |
| 37 VLOG(1) << "Starting Viewer Process IPC Server"; |
| 38 // TODO(scottmg): Channel name should be per user-data-dir. |
| 39 ipc_server_.reset(new ViewerIPCServer("viewer_ipc")); |
| 40 ipc_server_->Init(); |
| 41 |
| 42 // TODO(scottmg): I guess the whole thing should be made Windows-only at |
| 43 // some point. |
| 44 #if defined(OS_WIN) |
| 45 viewer_host_win_.reset(new ViewerHostWin); |
| 46 #endif |
| 47 |
| 48 // TODO(scottmg): Ask for a handle here, maybe start a browser, all that |
| 49 // jazz. |
| 50 |
| 51 return true; |
| 52 } |
| 53 |
| 54 bool ViewerProcess::Teardown() { |
| 55 ipc_server_.reset(); |
| 56 io_thread_.reset(); |
| 57 return true; |
| 58 } |
| 59 |
| 60 bool ViewerProcess::HandleClientDisconnect() { |
| 61 Terminate(); |
| 62 return false; |
| 63 } |
| 64 |
| 65 void ViewerProcess::Terminate() { |
| 66 main_message_loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 67 } |
OLD | NEW |