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 namespace { | |
13 | |
14 class ViewerIOThread : public base::Thread { | |
15 public: | |
16 explicit ViewerIOThread(const char* name); | |
17 virtual ~ViewerIOThread(); | |
18 | |
19 protected: | |
20 virtual void CleanUp(); | |
tfarina
2012/08/28 01:19:45
OVERRIDE?
| |
21 | |
22 private: | |
23 DISALLOW_COPY_AND_ASSIGN(ViewerIOThread); | |
24 }; | |
25 | |
26 ViewerIOThread::ViewerIOThread(const char* name) : base::Thread(name) {} | |
27 ViewerIOThread::~ViewerIOThread() { | |
tfarina
2012/08/28 01:19:45
can you add a blank line above?
| |
28 Stop(); | |
29 } | |
30 | |
31 void ViewerIOThread::CleanUp() { | |
32 } | |
33 | |
34 } // namespace | |
35 | |
36 ViewerProcess::ViewerProcess() | |
37 : shutdown_event_(true, false), | |
38 main_message_loop_(NULL) { | |
39 DCHECK(!g_viewer_process); | |
40 g_viewer_process = this; | |
41 } | |
42 | |
43 ViewerProcess::~ViewerProcess() { | |
44 Teardown(); | |
45 g_viewer_process = NULL; | |
46 } | |
47 | |
48 bool ViewerProcess::Initialize(MessageLoop* message_loop, | |
49 const CommandLine& command_line) { | |
50 main_message_loop_ = message_loop; | |
51 base::Thread::Options options; | |
52 options.message_loop_type = MessageLoop::TYPE_IO; | |
53 io_thread_.reset(new ViewerIOThread("ViewerProcess_IO")); | |
54 if (!io_thread_->StartWithOptions(options)) { | |
55 NOTREACHED(); | |
56 Teardown(); | |
57 return false; | |
58 } | |
59 | |
60 VLOG(1) << "Starting Viewer Process IPC Server"; | |
61 // TODO(scottmg): Channel name should be per user-data-dir. | |
62 ipc_server_.reset(new ViewerIPCServer("viewer_ipc")); | |
63 ipc_server_->Init(); | |
64 | |
65 // TODO(scottmg): I guess the whole thing should be made Windows-only at | |
66 // some point. | |
67 #if defined(OS_WIN) | |
68 viewer_host_win_.reset(new ViewerHostWin); | |
69 #endif | |
70 | |
71 // TODO(scottmg): Ask for a handle here, maybe start a browser, all that | |
72 // jazz. | |
73 | |
74 return true; | |
75 } | |
76 | |
77 bool ViewerProcess::Teardown() { | |
78 ipc_server_.reset(); | |
79 io_thread_.reset(); | |
80 return true; | |
81 } | |
82 | |
83 bool ViewerProcess::HandleClientDisconnect() { | |
84 Terminate(); | |
85 return false; | |
86 } | |
87 | |
88 void ViewerProcess::Terminate() { | |
89 main_message_loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | |
90 } | |
OLD | NEW |