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

Side by Side Diff: chrome/browser/extensions/api/messaging/native_message_process_host.h

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 #ifndef CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PROCESS_HOST_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PROCESS_HOST_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PROCESS_HOST_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PROCESS_HOST_H_
7 7
8 #include <memory>
8 #include <queue> 9 #include <queue>
9 #include <string> 10 #include <string>
10 11
11 #include "base/files/file.h" 12 #include "base/files/file.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/process/process.h" 15 #include "base/process/process.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h" 17 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h"
18 #include "extensions/browser/api/messaging/native_message_host.h" 18 #include "extensions/browser/api/messaging/native_message_host.h"
19 #include "ui/gfx/native_widget_types.h" 19 #include "ui/gfx/native_widget_types.h"
20 20
21 namespace net { 21 namespace net {
22 22
23 class DrainableIOBuffer; 23 class DrainableIOBuffer;
(...skipping 13 matching lines...) Expand all
37 // thread. 37 // thread.
38 class NativeMessageProcessHost : 38 class NativeMessageProcessHost :
39 #if defined(OS_POSIX) 39 #if defined(OS_POSIX)
40 public base::MessageLoopForIO::Watcher, 40 public base::MessageLoopForIO::Watcher,
41 #endif // !defined(OS_POSIX) 41 #endif // !defined(OS_POSIX)
42 public NativeMessageHost { 42 public NativeMessageHost {
43 public: 43 public:
44 ~NativeMessageProcessHost() override; 44 ~NativeMessageProcessHost() override;
45 45
46 // Create using specified |launcher|. Used in tests. 46 // Create using specified |launcher|. Used in tests.
47 static scoped_ptr<NativeMessageHost> CreateWithLauncher( 47 static std::unique_ptr<NativeMessageHost> CreateWithLauncher(
48 const std::string& source_extension_id, 48 const std::string& source_extension_id,
49 const std::string& native_host_name, 49 const std::string& native_host_name,
50 scoped_ptr<NativeProcessLauncher> launcher); 50 std::unique_ptr<NativeProcessLauncher> launcher);
51 51
52 // extensions::NativeMessageHost implementation. 52 // extensions::NativeMessageHost implementation.
53 void OnMessage(const std::string& message) override; 53 void OnMessage(const std::string& message) override;
54 void Start(Client* client) override; 54 void Start(Client* client) override;
55 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const override; 55 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const override;
56 56
57 #if defined(OS_POSIX) 57 #if defined(OS_POSIX)
58 // MessageLoopForIO::Watcher interface 58 // MessageLoopForIO::Watcher interface
59 void OnFileCanReadWithoutBlocking(int fd) override; 59 void OnFileCanReadWithoutBlocking(int fd) override;
60 void OnFileCanWriteWithoutBlocking(int fd) override; 60 void OnFileCanWriteWithoutBlocking(int fd) override;
61 #endif // !defined(OS_POSIX) 61 #endif // !defined(OS_POSIX)
62 62
63 // Try and read a single message from |read_file_|. This should only be called 63 // Try and read a single message from |read_file_|. This should only be called
64 // in unittests when you know there is data in the file. 64 // in unittests when you know there is data in the file.
65 void ReadNowForTesting(); 65 void ReadNowForTesting();
66 66
67 private: 67 private:
68 NativeMessageProcessHost(const std::string& source_extension_id, 68 NativeMessageProcessHost(const std::string& source_extension_id,
69 const std::string& native_host_name, 69 const std::string& native_host_name,
70 scoped_ptr<NativeProcessLauncher> launcher); 70 std::unique_ptr<NativeProcessLauncher> launcher);
71 71
72 // Starts the host process. 72 // Starts the host process.
73 void LaunchHostProcess(); 73 void LaunchHostProcess();
74 74
75 // Callback for NativeProcessLauncher::Launch(). 75 // Callback for NativeProcessLauncher::Launch().
76 void OnHostProcessLaunched(NativeProcessLauncher::LaunchResult result, 76 void OnHostProcessLaunched(NativeProcessLauncher::LaunchResult result,
77 base::Process process, 77 base::Process process,
78 base::File read_file, 78 base::File read_file,
79 base::File write_file); 79 base::File write_file);
80 80
(...skipping 16 matching lines...) Expand all
97 // UI thread. 97 // UI thread.
98 Client* client_; 98 Client* client_;
99 99
100 // ID of the calling extension. 100 // ID of the calling extension.
101 std::string source_extension_id_; 101 std::string source_extension_id_;
102 102
103 // Name of the native messaging host. 103 // Name of the native messaging host.
104 std::string native_host_name_; 104 std::string native_host_name_;
105 105
106 // Launcher used to launch the native process. 106 // Launcher used to launch the native process.
107 scoped_ptr<NativeProcessLauncher> launcher_; 107 std::unique_ptr<NativeProcessLauncher> launcher_;
108 108
109 // Set to true after the native messaging connection has been stopped, e.g. 109 // Set to true after the native messaging connection has been stopped, e.g.
110 // due to an error. 110 // due to an error.
111 bool closed_; 111 bool closed_;
112 112
113 base::Process process_; 113 base::Process process_;
114 114
115 // Input stream reader. 115 // Input stream reader.
116 scoped_ptr<net::FileStream> read_stream_; 116 std::unique_ptr<net::FileStream> read_stream_;
117 117
118 #if defined(OS_POSIX) 118 #if defined(OS_POSIX)
119 base::PlatformFile read_file_; 119 base::PlatformFile read_file_;
120 base::MessageLoopForIO::FileDescriptorWatcher read_watcher_; 120 base::MessageLoopForIO::FileDescriptorWatcher read_watcher_;
121 #endif // !defined(OS_POSIX) 121 #endif // !defined(OS_POSIX)
122 122
123 // Write stream. 123 // Write stream.
124 scoped_ptr<net::FileStream> write_stream_; 124 std::unique_ptr<net::FileStream> write_stream_;
125 125
126 // Read buffer passed to FileStream::Read(). 126 // Read buffer passed to FileStream::Read().
127 scoped_refptr<net::IOBuffer> read_buffer_; 127 scoped_refptr<net::IOBuffer> read_buffer_;
128 128
129 // Set to true when a read is pending. 129 // Set to true when a read is pending.
130 bool read_pending_; 130 bool read_pending_;
131 131
132 // Buffer for incomplete incoming messages. 132 // Buffer for incomplete incoming messages.
133 std::string incoming_data_; 133 std::string incoming_data_;
134 134
135 // Queue for outgoing messages. 135 // Queue for outgoing messages.
136 std::queue<scoped_refptr<net::IOBufferWithSize> > write_queue_; 136 std::queue<scoped_refptr<net::IOBufferWithSize> > write_queue_;
137 137
138 // The message that's currently being sent. 138 // The message that's currently being sent.
139 scoped_refptr<net::DrainableIOBuffer> current_write_buffer_; 139 scoped_refptr<net::DrainableIOBuffer> current_write_buffer_;
140 140
141 // Set to true when a write is pending. 141 // Set to true when a write is pending.
142 bool write_pending_; 142 bool write_pending_;
143 143
144 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 144 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
145 145
146 base::WeakPtrFactory<NativeMessageProcessHost> weak_factory_; 146 base::WeakPtrFactory<NativeMessageProcessHost> weak_factory_;
147 147
148 DISALLOW_COPY_AND_ASSIGN(NativeMessageProcessHost); 148 DISALLOW_COPY_AND_ASSIGN(NativeMessageProcessHost);
149 }; 149 };
150 150
151 } // namespace extensions 151 } // namespace extensions
152 152
153 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PROCESS_HOST_H _ 153 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PROCESS_HOST_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698