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_port.h" | 5 #include "chrome/browser/extensions/api/messaging/native_message_port.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h" | 9 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
11 | 11 |
12 namespace extensions { | 12 namespace extensions { |
13 | 13 |
14 // Handles jumping between the |host_task_runner| and the | 14 // Handles jumping between the |host_task_runner| and the |
15 // |message_service_task_runner|. | 15 // |message_service_task_runner|. |
16 // All methods on the host interface should be called on |host_task_runner|. | 16 // All methods on the host interface should be called on |host_task_runner|. |
17 // All methods on |port| (that calls into MessageServices) should be called | 17 // All methods on |port| (that calls into MessageServices) should be called |
18 // on |message_service_task_runner|. | 18 // on |message_service_task_runner|. |
19 class NativeMessagePort::Core : public NativeMessageHost::Client { | 19 class NativeMessagePort::Core : public NativeMessageHost::Client { |
20 public: | 20 public: |
21 Core( | 21 Core( |
22 scoped_ptr<NativeMessageHost> host, | 22 scoped_ptr<NativeMessageHost> host, |
23 base::WeakPtr<NativeMessagePort> port, | 23 base::WeakPtr<NativeMessagePort> port, |
24 scoped_refptr<base::SingleThreadTaskRunner> message_service_task_runner_); | 24 scoped_refptr<base::SingleThreadTaskRunner> message_service_task_runner_); |
25 virtual ~Core(); | 25 virtual ~Core(); |
26 | 26 |
27 void OnMessageFromChrome(const std::string& message); | 27 void OnMessageFromChrome(const std::string& message); |
28 | 28 |
29 // NativeMessageHost::Client implementation. | 29 // NativeMessageHost::Client implementation. |
30 virtual void PostMessageFromNativeHost(const std::string& message) OVERRIDE; | 30 virtual void PostMessageFromNativeHost(const std::string& message) override; |
31 virtual void CloseChannel(const std::string& error_message) OVERRIDE; | 31 virtual void CloseChannel(const std::string& error_message) override; |
32 | 32 |
33 private: | 33 private: |
34 scoped_ptr<NativeMessageHost> host_; | 34 scoped_ptr<NativeMessageHost> host_; |
35 base::WeakPtr<NativeMessagePort> port_; | 35 base::WeakPtr<NativeMessagePort> port_; |
36 | 36 |
37 scoped_refptr<base::SingleThreadTaskRunner> message_service_task_runner_; | 37 scoped_refptr<base::SingleThreadTaskRunner> message_service_task_runner_; |
38 scoped_refptr<base::SingleThreadTaskRunner> host_task_runner_; | 38 scoped_refptr<base::SingleThreadTaskRunner> host_task_runner_; |
39 }; | 39 }; |
40 | 40 |
41 NativeMessagePort::Core::Core( | 41 NativeMessagePort::Core::Core( |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 115 } |
116 | 116 |
117 void NativeMessagePort::CloseChannel(const std::string& error_message) { | 117 void NativeMessagePort::CloseChannel(const std::string& error_message) { |
118 DCHECK(thread_checker_.CalledOnValidThread()); | 118 DCHECK(thread_checker_.CalledOnValidThread()); |
119 if (weak_message_service_) { | 119 if (weak_message_service_) { |
120 weak_message_service_->CloseChannel(port_id_, error_message); | 120 weak_message_service_->CloseChannel(port_id_, error_message); |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 } // namespace extensions | 124 } // namespace extensions |
OLD | NEW |