| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/extensions/api/messaging/native_message_process_host.h" | 5 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 // Size of the buffer to be allocated for each read. | 37 // Size of the buffer to be allocated for each read. |
| 38 const size_t kReadBufferSize = 4096; | 38 const size_t kReadBufferSize = 4096; |
| 39 | 39 |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 namespace extensions { | 42 namespace extensions { |
| 43 | 43 |
| 44 NativeMessageProcessHost::NativeMessageProcessHost( | 44 NativeMessageProcessHost::NativeMessageProcessHost( |
| 45 const std::string& source_extension_id, | 45 const std::string& source_extension_id, |
| 46 const std::string& native_host_name, | 46 const std::string& native_host_name, |
| 47 scoped_ptr<NativeProcessLauncher> launcher) | 47 std::unique_ptr<NativeProcessLauncher> launcher) |
| 48 : client_(NULL), | 48 : client_(NULL), |
| 49 source_extension_id_(source_extension_id), | 49 source_extension_id_(source_extension_id), |
| 50 native_host_name_(native_host_name), | 50 native_host_name_(native_host_name), |
| 51 launcher_(std::move(launcher)), | 51 launcher_(std::move(launcher)), |
| 52 closed_(false), | 52 closed_(false), |
| 53 #if defined(OS_POSIX) | 53 #if defined(OS_POSIX) |
| 54 read_file_(-1), | 54 read_file_(-1), |
| 55 #endif | 55 #endif |
| 56 read_pending_(false), | 56 read_pending_(false), |
| 57 write_pending_(false), | 57 write_pending_(false), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 73 content::BrowserThread::PostBlockingPoolTask( | 73 content::BrowserThread::PostBlockingPoolTask( |
| 74 FROM_HERE, | 74 FROM_HERE, |
| 75 base::Bind(&base::EnsureProcessTerminated, Passed(&process_))); | 75 base::Bind(&base::EnsureProcessTerminated, Passed(&process_))); |
| 76 #else | 76 #else |
| 77 base::EnsureProcessTerminated(std::move(process_)); | 77 base::EnsureProcessTerminated(std::move(process_)); |
| 78 #endif | 78 #endif |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 // static | 82 // static |
| 83 scoped_ptr<NativeMessageHost> NativeMessageHost::Create( | 83 std::unique_ptr<NativeMessageHost> NativeMessageHost::Create( |
| 84 gfx::NativeView native_view, | 84 gfx::NativeView native_view, |
| 85 const std::string& source_extension_id, | 85 const std::string& source_extension_id, |
| 86 const std::string& native_host_name, | 86 const std::string& native_host_name, |
| 87 bool allow_user_level, | 87 bool allow_user_level, |
| 88 std::string* error_message) { | 88 std::string* error_message) { |
| 89 return NativeMessageProcessHost::CreateWithLauncher( | 89 return NativeMessageProcessHost::CreateWithLauncher( |
| 90 source_extension_id, | 90 source_extension_id, |
| 91 native_host_name, | 91 native_host_name, |
| 92 NativeProcessLauncher::CreateDefault(allow_user_level, native_view)); | 92 NativeProcessLauncher::CreateDefault(allow_user_level, native_view)); |
| 93 } | 93 } |
| 94 | 94 |
| 95 // static | 95 // static |
| 96 scoped_ptr<NativeMessageHost> NativeMessageProcessHost::CreateWithLauncher( | 96 std::unique_ptr<NativeMessageHost> NativeMessageProcessHost::CreateWithLauncher( |
| 97 const std::string& source_extension_id, | 97 const std::string& source_extension_id, |
| 98 const std::string& native_host_name, | 98 const std::string& native_host_name, |
| 99 scoped_ptr<NativeProcessLauncher> launcher) { | 99 std::unique_ptr<NativeProcessLauncher> launcher) { |
| 100 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 100 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 101 | 101 |
| 102 scoped_ptr<NativeMessageHost> process(new NativeMessageProcessHost( | 102 std::unique_ptr<NativeMessageHost> process(new NativeMessageProcessHost( |
| 103 source_extension_id, native_host_name, std::move(launcher))); | 103 source_extension_id, native_host_name, std::move(launcher))); |
| 104 | 104 |
| 105 return process; | 105 return process; |
| 106 } | 106 } |
| 107 | 107 |
| 108 void NativeMessageProcessHost::LaunchHostProcess() { | 108 void NativeMessageProcessHost::LaunchHostProcess() { |
| 109 DCHECK(task_runner_->BelongsToCurrentThread()); | 109 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 110 | 110 |
| 111 GURL origin(std::string(kExtensionScheme) + "://" + source_extension_id_); | 111 GURL origin(std::string(kExtensionScheme) + "://" + source_extension_id_); |
| 112 launcher_->Launch(origin, native_host_name_, | 112 launcher_->Launch(origin, native_host_name_, |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 | 358 |
| 359 if (!closed_) { | 359 if (!closed_) { |
| 360 closed_ = true; | 360 closed_ = true; |
| 361 read_stream_.reset(); | 361 read_stream_.reset(); |
| 362 write_stream_.reset(); | 362 write_stream_.reset(); |
| 363 client_->CloseChannel(error_message); | 363 client_->CloseChannel(error_message); |
| 364 } | 364 } |
| 365 } | 365 } |
| 366 | 366 |
| 367 } // namespace extensions | 367 } // namespace extensions |
| OLD | NEW |