| 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_SERVICE_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_SERVICE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_SERVICE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 // Enqueues a message on a pending channel, or sends a message to the given | 178 // Enqueues a message on a pending channel, or sends a message to the given |
| 179 // port if the channel isn't pending. | 179 // port if the channel isn't pending. |
| 180 void PostMessage(int port_id, const Message& message); | 180 void PostMessage(int port_id, const Message& message); |
| 181 | 181 |
| 182 private: | 182 private: |
| 183 friend class MockMessageService; | 183 friend class MockMessageService; |
| 184 friend class BrowserContextKeyedAPIFactory<MessageService>; | 184 friend class BrowserContextKeyedAPIFactory<MessageService>; |
| 185 struct OpenChannelParams; | 185 struct OpenChannelParams; |
| 186 | 186 |
| 187 // A map of channel ID to its channel object. | 187 // A map of channel ID to its channel object. |
| 188 typedef std::map<int, MessageChannel*> MessageChannelMap; | 188 using MessageChannelMap = std::map<int, std::unique_ptr<MessageChannel>>; |
| 189 | 189 |
| 190 typedef std::pair<int, Message> PendingMessage; | 190 using PendingMessage = std::pair<int, Message>; |
| 191 typedef std::vector<PendingMessage> PendingMessagesQueue; | 191 using PendingMessagesQueue = std::vector<PendingMessage>; |
| 192 // A set of channel IDs waiting to complete opening, and any pending messages | 192 // A set of channel IDs waiting to complete opening, and any pending messages |
| 193 // queued to be sent on those channels. | 193 // queued to be sent on those channels. |
| 194 typedef std::map<int, PendingMessagesQueue> PendingChannelMap; | 194 using PendingChannelMap = std::map<int, PendingMessagesQueue>; |
| 195 | 195 |
| 196 // A map of channel ID to information about the extension that is waiting | 196 // A map of channel ID to information about the extension that is waiting |
| 197 // for that channel to open. Used for lazy background pages. | 197 // for that channel to open. Used for lazy background pages. |
| 198 typedef std::string ExtensionID; | 198 using ExtensionID = std::string; |
| 199 typedef std::pair<content::BrowserContext*, ExtensionID> | 199 using PendingLazyBackgroundPageChannel = |
| 200 PendingLazyBackgroundPageChannel; | 200 std::pair<content::BrowserContext*, ExtensionID>; |
| 201 typedef std::map<int, PendingLazyBackgroundPageChannel> | 201 using PendingLazyBackgroundPageChannelMap = |
| 202 PendingLazyBackgroundPageChannelMap; | 202 std::map<int, PendingLazyBackgroundPageChannel>; |
| 203 | 203 |
| 204 // Common implementation for opening a channel configured by |params|. | 204 // Common implementation for opening a channel configured by |params|. |
| 205 // | 205 // |
| 206 // |target_extension| will be non-null if |params->target_extension_id| is | 206 // |target_extension| will be non-null if |params->target_extension_id| is |
| 207 // non-empty, that is, if the target is an extension, it must exist. | 207 // non-empty, that is, if the target is an extension, it must exist. |
| 208 // | 208 // |
| 209 // |did_enqueue| will be true if the channel opening was delayed while | 209 // |did_enqueue| will be true if the channel opening was delayed while |
| 210 // waiting for an event page to start, false otherwise. | 210 // waiting for an event page to start, false otherwise. |
| 211 void OpenChannelImpl(content::BrowserContext* browser_context, | 211 void OpenChannelImpl(content::BrowserContext* browser_context, |
| 212 std::unique_ptr<OpenChannelParams> params, | 212 std::unique_ptr<OpenChannelParams> params, |
| 213 const Extension* target_extension, | 213 const Extension* target_extension, |
| 214 bool did_enqueue); | 214 bool did_enqueue); |
| 215 | 215 |
| 216 void ClosePortImpl(int port_id, | 216 void ClosePortImpl(int port_id, |
| 217 int process_id, | 217 int process_id, |
| 218 int routing_id, | 218 int routing_id, |
| 219 bool force_close, | 219 bool force_close, |
| 220 const std::string& error_message); | 220 const std::string& error_message); |
| 221 | 221 |
| 222 void CloseChannelImpl(MessageChannelMap::iterator channel_iter, | 222 void CloseChannelImpl(MessageChannelMap::iterator channel_iter, |
| 223 int port_id, | 223 int port_id, |
| 224 const std::string& error_message, | 224 const std::string& error_message, |
| 225 bool notify_other_port); | 225 bool notify_other_port); |
| 226 | 226 |
| 227 // Have MessageService take ownership of |channel|, and remove any pending | 227 // Have MessageService take ownership of |channel|, and remove any pending |
| 228 // channels with the same id. | 228 // channels with the same id. |
| 229 void AddChannel(MessageChannel* channel, int receiver_port_id); | 229 void AddChannel(std::unique_ptr<MessageChannel> channel, |
| 230 int receiver_port_id); |
| 230 | 231 |
| 231 // If the channel is being opened from an incognito tab the user must allow | 232 // If the channel is being opened from an incognito tab the user must allow |
| 232 // the connection. | 233 // the connection. |
| 233 void OnOpenChannelAllowed(std::unique_ptr<OpenChannelParams> params, | 234 void OnOpenChannelAllowed(std::unique_ptr<OpenChannelParams> params, |
| 234 bool allowed); | 235 bool allowed); |
| 235 void GotChannelID(std::unique_ptr<OpenChannelParams> params, | 236 void GotChannelID(std::unique_ptr<OpenChannelParams> params, |
| 236 const std::string& tls_channel_id); | 237 const std::string& tls_channel_id); |
| 237 | 238 |
| 238 // Enqueues a message on a pending channel. | 239 // Enqueues a message on a pending channel. |
| 239 void EnqueuePendingMessage(int port_id, int channel_id, | 240 void EnqueuePendingMessage(int port_id, int channel_id, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 LazyBackgroundTaskQueue* lazy_background_task_queue_; | 316 LazyBackgroundTaskQueue* lazy_background_task_queue_; |
| 316 | 317 |
| 317 base::WeakPtrFactory<MessageService> weak_factory_; | 318 base::WeakPtrFactory<MessageService> weak_factory_; |
| 318 | 319 |
| 319 DISALLOW_COPY_AND_ASSIGN(MessageService); | 320 DISALLOW_COPY_AND_ASSIGN(MessageService); |
| 320 }; | 321 }; |
| 321 | 322 |
| 322 } // namespace extensions | 323 } // namespace extensions |
| 323 | 324 |
| 324 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_SERVICE_H_ | 325 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_SERVICE_H_ |
| OLD | NEW |