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

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

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 DCHECK(GET_CHANNEL_ID(port1_id) == channel_id); 109 DCHECK(GET_CHANNEL_ID(port1_id) == channel_id);
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, NotificationType::RENDERER_PROCESS_TERMINATED, 119 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
120 NotificationService::AllSources()); 120 NotificationService::AllSources());
121 registrar_.Add(this, NotificationType::RENDERER_PROCESS_CLOSED, 121 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
122 NotificationService::AllSources()); 122 NotificationService::AllSources());
123 registrar_.Add(this, NotificationType::RENDER_VIEW_HOST_DELETED, 123 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_DELETED,
124 NotificationService::AllSources()); 124 NotificationService::AllSources());
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;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 if (iter == channels_.end()) 317 if (iter == channels_.end())
318 return; 318 return;
319 319
320 // Figure out which port the ID corresponds to. 320 // Figure out which port the ID corresponds to.
321 int dest_port_id = GET_OPPOSITE_PORT_ID(source_port_id); 321 int dest_port_id = GET_OPPOSITE_PORT_ID(source_port_id);
322 const MessagePort& port = IS_OPENER_PORT_ID(dest_port_id) ? 322 const MessagePort& port = IS_OPENER_PORT_ID(dest_port_id) ?
323 iter->second->opener : iter->second->receiver; 323 iter->second->opener : iter->second->receiver;
324 324
325 DispatchOnMessage(port, message, dest_port_id); 325 DispatchOnMessage(port, message, dest_port_id);
326 } 326 }
327 void ExtensionMessageService::Observe(NotificationType type, 327 void ExtensionMessageService::Observe(int type,
328 const NotificationSource& source, 328 const NotificationSource& source,
329 const NotificationDetails& details) { 329 const NotificationDetails& details) {
330 switch (type.value) { 330 switch (type) {
331 case NotificationType::RENDERER_PROCESS_TERMINATED: 331 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED:
332 case NotificationType::RENDERER_PROCESS_CLOSED: { 332 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: {
333 RenderProcessHost* renderer = Source<RenderProcessHost>(source).ptr(); 333 RenderProcessHost* renderer = Source<RenderProcessHost>(source).ptr();
334 OnSenderClosed(renderer); 334 OnSenderClosed(renderer);
335 break; 335 break;
336 } 336 }
337 case NotificationType::RENDER_VIEW_HOST_DELETED: 337 case content::NOTIFICATION_RENDER_VIEW_HOST_DELETED:
338 OnSenderClosed(Source<RenderViewHost>(source).ptr()); 338 OnSenderClosed(Source<RenderViewHost>(source).ptr());
339 break; 339 break;
340 default: 340 default:
341 NOTREACHED(); 341 NOTREACHED();
342 return; 342 return;
343 } 343 }
344 } 344 }
345 345
346 void ExtensionMessageService::OnSenderClosed(IPC::Message::Sender* sender) { 346 void ExtensionMessageService::OnSenderClosed(IPC::Message::Sender* sender) {
347 // Close any channels that share this renderer. We notify the opposite 347 // Close any channels that share this renderer. We notify the opposite
348 // port that his pair has closed. 348 // port that his pair has closed.
349 for (MessageChannelMap::iterator it = channels_.begin(); 349 for (MessageChannelMap::iterator it = channels_.begin();
350 it != channels_.end(); ) { 350 it != channels_.end(); ) {
351 MessageChannelMap::iterator current = it++; 351 MessageChannelMap::iterator current = it++;
352 // If both sides are the same renderer, and it is closing, there is no 352 // If both sides are the same renderer, and it is closing, there is no
353 // "other" port, so there's no need to notify it. 353 // "other" port, so there's no need to notify it.
354 bool notify_other_port = 354 bool notify_other_port =
355 current->second->opener.sender != current->second->receiver.sender; 355 current->second->opener.sender != current->second->receiver.sender;
356 356
357 if (current->second->opener.sender == sender) { 357 if (current->second->opener.sender == sender) {
358 CloseChannelImpl(current, GET_CHANNEL_OPENER_ID(current->first), 358 CloseChannelImpl(current, GET_CHANNEL_OPENER_ID(current->first),
359 notify_other_port); 359 notify_other_port);
360 } else if (current->second->receiver.sender == sender) { 360 } else if (current->second->receiver.sender == sender) {
361 CloseChannelImpl(current, GET_CHANNEL_RECEIVERS_ID(current->first), 361 CloseChannelImpl(current, GET_CHANNEL_RECEIVERS_ID(current->first),
362 notify_other_port); 362 notify_other_port);
363 } 363 }
364 } 364 }
365 } 365 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_message_service.h ('k') | chrome/browser/extensions/extension_messages_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698