Upstream version 6.35.132.0
[platform/framework/web/crosswalk.git] / src / xwalk / application / tools / linux / xwalk_extension_process_launcher.cc
1 // Copyright (c) 2014 Intel Corporation. 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 "base/at_exit.h"
6 #include "base/message_loop/message_loop.h"
7 #include "xwalk/application/tools/linux/xwalk_extension_process_launcher.h"
8 #include "xwalk/extensions/extension_process/xwalk_extension_process.h"
9
10 XWalkExtensionProcessLauncher::XWalkExtensionProcessLauncher()
11     : base::Thread("LauncherExtensionService"),
12       is_started_(false) {
13   exit_manager_.reset(new base::AtExitManager);
14   base::Thread::Options thread_options;
15   thread_options.message_loop_type = base::MessageLoop::TYPE_DEFAULT;
16   StartWithOptions(thread_options);
17 }
18
19 XWalkExtensionProcessLauncher::~XWalkExtensionProcessLauncher() {
20   Stop();
21 }
22
23 void XWalkExtensionProcessLauncher::CleanUp() {
24   extension_process_.reset();
25 }
26
27 void XWalkExtensionProcessLauncher::Launch(
28     const std::string& channel_id, int channel_fd) {
29   is_started_ = true;
30   message_loop()->PostTask(
31       FROM_HERE,
32       base::Bind(&XWalkExtensionProcessLauncher::StartExtensionProcess,
33                  base::Unretained(this), channel_id, channel_fd));
34 }
35
36 void XWalkExtensionProcessLauncher::StartExtensionProcess(
37     const std::string& channel_id, int channel_fd) {
38   extension_process_.reset(new xwalk::extensions::XWalkExtensionProcess(
39       IPC::ChannelHandle(channel_id, base::FileDescriptor(channel_fd, true))));
40 }