Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Side by Side Diff: chrome/browser/extensions/api/messaging/native_message_port.cc

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
12 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h" 12 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h"
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 14
15 namespace extensions { 15 namespace extensions {
16 16
17 // Handles jumping between the |host_task_runner| and the 17 // Handles jumping between the |host_task_runner| and the
18 // |message_service_task_runner|. 18 // |message_service_task_runner|.
19 // All methods on the host interface should be called on |host_task_runner|. 19 // All methods on the host interface should be called on |host_task_runner|.
20 // All methods on |port| (that calls into MessageServices) should be called 20 // All methods on |port| (that calls into MessageServices) should be called
21 // on |message_service_task_runner|. 21 // on |message_service_task_runner|.
22 class NativeMessagePort::Core : public NativeMessageHost::Client { 22 class NativeMessagePort::Core : public NativeMessageHost::Client {
23 public: 23 public:
24 Core( 24 Core(
25 scoped_ptr<NativeMessageHost> host, 25 std::unique_ptr<NativeMessageHost> host,
26 base::WeakPtr<NativeMessagePort> port, 26 base::WeakPtr<NativeMessagePort> port,
27 scoped_refptr<base::SingleThreadTaskRunner> message_service_task_runner_); 27 scoped_refptr<base::SingleThreadTaskRunner> message_service_task_runner_);
28 ~Core() override; 28 ~Core() override;
29 29
30 void OnMessageFromChrome(const std::string& message); 30 void OnMessageFromChrome(const std::string& message);
31 31
32 // NativeMessageHost::Client implementation. 32 // NativeMessageHost::Client implementation.
33 void PostMessageFromNativeHost(const std::string& message) override; 33 void PostMessageFromNativeHost(const std::string& message) override;
34 void CloseChannel(const std::string& error_message) override; 34 void CloseChannel(const std::string& error_message) override;
35 35
36 private: 36 private:
37 scoped_ptr<NativeMessageHost> host_; 37 std::unique_ptr<NativeMessageHost> host_;
38 base::WeakPtr<NativeMessagePort> port_; 38 base::WeakPtr<NativeMessagePort> port_;
39 39
40 scoped_refptr<base::SingleThreadTaskRunner> message_service_task_runner_; 40 scoped_refptr<base::SingleThreadTaskRunner> message_service_task_runner_;
41 scoped_refptr<base::SingleThreadTaskRunner> host_task_runner_; 41 scoped_refptr<base::SingleThreadTaskRunner> host_task_runner_;
42 }; 42 };
43 43
44 NativeMessagePort::Core::Core( 44 NativeMessagePort::Core::Core(
45 scoped_ptr<NativeMessageHost> host, 45 std::unique_ptr<NativeMessageHost> host,
46 base::WeakPtr<NativeMessagePort> port, 46 base::WeakPtr<NativeMessagePort> port,
47 scoped_refptr<base::SingleThreadTaskRunner> message_service_task_runner) 47 scoped_refptr<base::SingleThreadTaskRunner> message_service_task_runner)
48 : host_(std::move(host)), 48 : host_(std::move(host)),
49 port_(port), 49 port_(port),
50 message_service_task_runner_(message_service_task_runner), 50 message_service_task_runner_(message_service_task_runner),
51 host_task_runner_(host_->task_runner()) { 51 host_task_runner_(host_->task_runner()) {
52 DCHECK(message_service_task_runner_->BelongsToCurrentThread()); 52 DCHECK(message_service_task_runner_->BelongsToCurrentThread());
53 host_task_runner_->PostTask(FROM_HERE, 53 host_task_runner_->PostTask(FROM_HERE,
54 base::Bind(&NativeMessageHost::Start, 54 base::Bind(&NativeMessageHost::Start,
55 base::Unretained(host_.get()), 55 base::Unretained(host_.get()),
(...skipping 24 matching lines...) Expand all
80 void NativeMessagePort::Core::CloseChannel(const std::string& error_message) { 80 void NativeMessagePort::Core::CloseChannel(const std::string& error_message) {
81 DCHECK(host_task_runner_->BelongsToCurrentThread()); 81 DCHECK(host_task_runner_->BelongsToCurrentThread());
82 message_service_task_runner_->PostTask( 82 message_service_task_runner_->PostTask(
83 FROM_HERE, 83 FROM_HERE,
84 base::Bind(&NativeMessagePort::CloseChannel, port_, error_message)); 84 base::Bind(&NativeMessagePort::CloseChannel, port_, error_message));
85 } 85 }
86 86
87 NativeMessagePort::NativeMessagePort( 87 NativeMessagePort::NativeMessagePort(
88 base::WeakPtr<MessageService> message_service, 88 base::WeakPtr<MessageService> message_service,
89 int port_id, 89 int port_id,
90 scoped_ptr<NativeMessageHost> native_message_host) 90 std::unique_ptr<NativeMessageHost> native_message_host)
91 : weak_message_service_(message_service), 91 : weak_message_service_(message_service),
92 host_task_runner_(native_message_host->task_runner()), 92 host_task_runner_(native_message_host->task_runner()),
93 port_id_(port_id), 93 port_id_(port_id),
94 weak_factory_(this) { 94 weak_factory_(this) {
95 core_.reset(new Core(std::move(native_message_host), 95 core_.reset(new Core(std::move(native_message_host),
96 weak_factory_.GetWeakPtr(), 96 weak_factory_.GetWeakPtr(),
97 base::ThreadTaskRunnerHandle::Get())); 97 base::ThreadTaskRunnerHandle::Get()));
98 } 98 }
99 99
100 NativeMessagePort::~NativeMessagePort() { 100 NativeMessagePort::~NativeMessagePort() {
(...skipping 24 matching lines...) Expand all
125 } 125 }
126 126
127 void NativeMessagePort::CloseChannel(const std::string& error_message) { 127 void NativeMessagePort::CloseChannel(const std::string& error_message) {
128 DCHECK(thread_checker_.CalledOnValidThread()); 128 DCHECK(thread_checker_.CalledOnValidThread());
129 if (weak_message_service_) { 129 if (weak_message_service_) {
130 weak_message_service_->CloseChannel(port_id_, error_message); 130 weak_message_service_->CloseChannel(port_id_, error_message);
131 } 131 }
132 } 132 }
133 133
134 } // namespace extensions 134 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698