| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ipc/mojo/scoped_ipc_support.h" | 5 #include "ipc/mojo/scoped_ipc_support.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/synchronization/condition_variable.h" | 11 #include "base/synchronization/condition_variable.h" |
| 12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 14 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 15 |
| 16 #if defined(USE_CHROME_EDK) |
| 17 #include "mojo/edk/embedder/embedder.h" |
| 18 #include "mojo/edk/embedder/process_delegate.h" |
| 19 #else |
| 15 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" | 20 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" |
| 16 #include "third_party/mojo/src/mojo/edk/embedder/process_delegate.h" | 21 #include "third_party/mojo/src/mojo/edk/embedder/process_delegate.h" |
| 22 #endif |
| 17 | 23 |
| 18 namespace IPC { | 24 namespace IPC { |
| 19 | 25 |
| 20 namespace { | 26 namespace { |
| 21 | 27 #if defined(USE_CHROME_EDK) |
| 28 class IPCSupportInitializer : public mojo::edk::ProcessDelegate { |
| 29 #else |
| 22 class IPCSupportInitializer : public mojo::embedder::ProcessDelegate { | 30 class IPCSupportInitializer : public mojo::embedder::ProcessDelegate { |
| 31 #endif |
| 23 public: | 32 public: |
| 24 IPCSupportInitializer() | 33 IPCSupportInitializer() |
| 25 : init_count_(0), | 34 : init_count_(0), |
| 26 shutting_down_(false), | 35 shutting_down_(false), |
| 27 was_shut_down_(false), | 36 was_shut_down_(false), |
| 28 observer_(nullptr) {} | 37 observer_(nullptr) {} |
| 29 | 38 |
| 30 ~IPCSupportInitializer() override { DCHECK(!observer_); } | 39 ~IPCSupportInitializer() override { DCHECK(!observer_); } |
| 31 | 40 |
| 32 void Init(scoped_refptr<base::TaskRunner> io_thread_task_runner); | 41 void Init(scoped_refptr<base::TaskRunner> io_thread_task_runner); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 return; | 107 return; |
| 99 } | 108 } |
| 100 | 109 |
| 101 init_count_++; | 110 init_count_++; |
| 102 if (init_count_ == 1) { | 111 if (init_count_ == 1) { |
| 103 was_shut_down_ = false; | 112 was_shut_down_ = false; |
| 104 observer_ = new MessageLoopObserver(this); | 113 observer_ = new MessageLoopObserver(this); |
| 105 io_thread_task_runner_ = io_thread_task_runner; | 114 io_thread_task_runner_ = io_thread_task_runner; |
| 106 io_thread_task_runner_->PostTask( | 115 io_thread_task_runner_->PostTask( |
| 107 FROM_HERE, base::Bind(&WatchMessageLoopOnIOThread, observer_)); | 116 FROM_HERE, base::Bind(&WatchMessageLoopOnIOThread, observer_)); |
| 117 |
| 118 #if defined(USE_CHROME_EDK) |
| 119 mojo::edk::InitIPCSupport( |
| 120 io_thread_task_runner_, this, io_thread_task_runner_, |
| 121 mojo::edk::ScopedPlatformHandle()); |
| 122 #else |
| 108 mojo::embedder::InitIPCSupport( | 123 mojo::embedder::InitIPCSupport( |
| 109 mojo::embedder::ProcessType::NONE, io_thread_task_runner_, this, | 124 mojo::embedder::ProcessType::NONE, io_thread_task_runner_, this, io_thre
ad_task_runner_, |
| 110 io_thread_task_runner_, mojo::embedder::ScopedPlatformHandle()); | 125 mojo::embedder::ScopedPlatformHandle()); |
| 126 #endif |
| 111 } | 127 } |
| 112 } | 128 } |
| 113 | 129 |
| 114 void IPCSupportInitializer::ShutDown() { | 130 void IPCSupportInitializer::ShutDown() { |
| 115 { | 131 { |
| 116 base::AutoLock locker(lock_); | 132 base::AutoLock locker(lock_); |
| 117 if (shutting_down_ || was_shut_down_) | 133 if (shutting_down_ || was_shut_down_) |
| 118 return; | 134 return; |
| 119 DCHECK(init_count_ > 0); | 135 DCHECK(init_count_ > 0); |
| 120 if (init_count_ > 1) { | 136 if (init_count_ > 1) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 137 } else { | 153 } else { |
| 138 io_thread_task_runner_->PostTask( | 154 io_thread_task_runner_->PostTask( |
| 139 FROM_HERE, base::Bind(&IPCSupportInitializer::ShutDownOnIOThread, | 155 FROM_HERE, base::Bind(&IPCSupportInitializer::ShutDownOnIOThread, |
| 140 base::Unretained(this))); | 156 base::Unretained(this))); |
| 141 } | 157 } |
| 142 } | 158 } |
| 143 | 159 |
| 144 void IPCSupportInitializer::ShutDownOnIOThread() { | 160 void IPCSupportInitializer::ShutDownOnIOThread() { |
| 145 base::AutoLock locker(lock_); | 161 base::AutoLock locker(lock_); |
| 146 if (shutting_down_ && !was_shut_down_) { | 162 if (shutting_down_ && !was_shut_down_) { |
| 163 #if defined(USE_CHROME_EDK) |
| 164 mojo::edk::ShutdownIPCSupportOnIOThread(); |
| 165 #else |
| 147 mojo::embedder::ShutdownIPCSupportOnIOThread(); | 166 mojo::embedder::ShutdownIPCSupportOnIOThread(); |
| 167 #endif |
| 148 init_count_ = 0; | 168 init_count_ = 0; |
| 149 shutting_down_ = false; | 169 shutting_down_ = false; |
| 150 io_thread_task_runner_ = nullptr; | 170 io_thread_task_runner_ = nullptr; |
| 151 was_shut_down_ = true; | 171 was_shut_down_ = true; |
| 152 if (observer_) { | 172 if (observer_) { |
| 153 delete observer_; | 173 delete observer_; |
| 154 observer_ = nullptr; | 174 observer_ = nullptr; |
| 155 } | 175 } |
| 156 } | 176 } |
| 157 } | 177 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 169 ScopedIPCSupport::ScopedIPCSupport( | 189 ScopedIPCSupport::ScopedIPCSupport( |
| 170 scoped_refptr<base::TaskRunner> io_thread_task_runner) { | 190 scoped_refptr<base::TaskRunner> io_thread_task_runner) { |
| 171 ipc_support_initializer.Get().Init(io_thread_task_runner); | 191 ipc_support_initializer.Get().Init(io_thread_task_runner); |
| 172 } | 192 } |
| 173 | 193 |
| 174 ScopedIPCSupport::~ScopedIPCSupport() { | 194 ScopedIPCSupport::~ScopedIPCSupport() { |
| 175 ipc_support_initializer.Get().ShutDown(); | 195 ipc_support_initializer.Get().ShutDown(); |
| 176 } | 196 } |
| 177 | 197 |
| 178 } // namespace IPC | 198 } // namespace IPC |
| OLD | NEW |