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

Side by Side Diff: chrome/browser/extensions/extension_message_service.cc

Issue 8342048: Make NotificationService an interface in the content namespace, and switch callers to use it. Mov... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/extension_message_service.h" 5 #include "chrome/browser/extensions/extension_message_service.h"
6 6
7 #include "base/atomic_sequence_num.h" 7 #include "base/atomic_sequence_num.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/extensions/extension_process_manager.h" 11 #include "chrome/browser/extensions/extension_process_manager.h"
12 #include "chrome/browser/extensions/extension_tab_util.h" 12 #include "chrome/browser/extensions/extension_tab_util.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/tab_contents/tab_util.h" 14 #include "chrome/browser/tab_contents/tab_util.h"
15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
16 #include "chrome/common/extensions/extension.h" 16 #include "chrome/common/extensions/extension.h"
17 #include "chrome/common/extensions/extension_messages.h" 17 #include "chrome/common/extensions/extension_messages.h"
18 #include "content/browser/child_process_security_policy.h" 18 #include "content/browser/child_process_security_policy.h"
19 #include "content/browser/renderer_host/render_process_host.h" 19 #include "content/browser/renderer_host/render_process_host.h"
20 #include "content/browser/renderer_host/render_view_host.h" 20 #include "content/browser/renderer_host/render_view_host.h"
21 #include "content/browser/tab_contents/tab_contents.h" 21 #include "content/browser/tab_contents/tab_contents.h"
22 #include "content/common/notification_service.h" 22 #include "content/public/browser/notification_service.h"
23 #include "content/public/browser/notification_types.h" 23 #include "content/public/browser/notification_types.h"
24 24
25 // Since we have 2 ports for every channel, we just index channels by half the 25 // Since we have 2 ports for every channel, we just index channels by half the
26 // port ID. 26 // port ID.
27 #define GET_CHANNEL_ID(port_id) ((port_id) / 2) 27 #define GET_CHANNEL_ID(port_id) ((port_id) / 2)
28 #define GET_CHANNEL_OPENER_ID(channel_id) ((channel_id) * 2) 28 #define GET_CHANNEL_OPENER_ID(channel_id) ((channel_id) * 2)
29 #define GET_CHANNEL_RECEIVERS_ID(channel_id) ((channel_id) * 2 + 1) 29 #define GET_CHANNEL_RECEIVERS_ID(channel_id) ((channel_id) * 2 + 1)
30 30
31 // Port1 is always even, port2 is always odd. 31 // Port1 is always even, port2 is always odd.
32 #define IS_OPENER_PORT_ID(port_id) (((port_id) & 1) == 0) 32 #define IS_OPENER_PORT_ID(port_id) (((port_id) & 1) == 0)
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 DCHECK(GET_CHANNEL_OPENER_ID(channel_id) == port1_id); 110 DCHECK(GET_CHANNEL_OPENER_ID(channel_id) == port1_id);
111 DCHECK(GET_CHANNEL_RECEIVERS_ID(channel_id) == port2_id); 111 DCHECK(GET_CHANNEL_RECEIVERS_ID(channel_id) == port2_id);
112 112
113 *port1 = port1_id; 113 *port1 = port1_id;
114 *port2 = port2_id; 114 *port2 = port2_id;
115 } 115 }
116 116
117 ExtensionMessageService::ExtensionMessageService(Profile* profile) 117 ExtensionMessageService::ExtensionMessageService(Profile* profile)
118 : profile_(profile) { 118 : profile_(profile) {
119 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 119 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
120 NotificationService::AllBrowserContextsAndSources()); 120 content::NotificationService::AllBrowserContextsAndSources());
121 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 121 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
122 NotificationService::AllBrowserContextsAndSources()); 122 content::NotificationService::AllBrowserContextsAndSources());
123 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, 123 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_DELETED,
124 NotificationService::AllBrowserContextsAndSources()); 124 content::NotificationService::AllBrowserContextsAndSources());
125 } 125 }
126 126
127 ExtensionMessageService::~ExtensionMessageService() { 127 ExtensionMessageService::~ExtensionMessageService() {
128 STLDeleteContainerPairSecondPointers(channels_.begin(), channels_.end()); 128 STLDeleteContainerPairSecondPointers(channels_.begin(), channels_.end());
129 channels_.clear(); 129 channels_.clear();
130 } 130 }
131 131
132 void ExtensionMessageService::DestroyingProfile() { 132 void ExtensionMessageService::DestroyingProfile() {
133 profile_ = NULL; 133 profile_ = NULL;
134 if (!registrar_.IsEmpty()) 134 if (!registrar_.IsEmpty())
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 360
361 if (current->second->opener.sender == sender) { 361 if (current->second->opener.sender == sender) {
362 CloseChannelImpl(current, GET_CHANNEL_OPENER_ID(current->first), 362 CloseChannelImpl(current, GET_CHANNEL_OPENER_ID(current->first),
363 notify_other_port); 363 notify_other_port);
364 } else if (current->second->receiver.sender == sender) { 364 } else if (current->second->receiver.sender == sender) {
365 CloseChannelImpl(current, GET_CHANNEL_RECEIVERS_ID(current->first), 365 CloseChannelImpl(current, GET_CHANNEL_RECEIVERS_ID(current->first),
366 notify_other_port); 366 notify_other_port);
367 } 367 }
368 } 368 }
369 } 369 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_menu_manager_unittest.cc ('k') | chrome/browser/extensions/extension_messages_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698