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

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

Issue 440012: Fixing 27834 by always deleting ExtensionMessageService on... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years 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
« no previous file with comments | « chrome/browser/extensions/extension_message_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/singleton.h" 8 #include "base/singleton.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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 "Port.dispatchOnDisconnect"; 108 "Port.dispatchOnDisconnect";
109 const char ExtensionMessageService::kDispatchOnMessage[] = 109 const char ExtensionMessageService::kDispatchOnMessage[] =
110 "Port.dispatchOnMessage"; 110 "Port.dispatchOnMessage";
111 const char ExtensionMessageService::kDispatchEvent[] = 111 const char ExtensionMessageService::kDispatchEvent[] =
112 "Event.dispatchJSON"; 112 "Event.dispatchJSON";
113 113
114 ExtensionMessageService::ExtensionMessageService(Profile* profile) 114 ExtensionMessageService::ExtensionMessageService(Profile* profile)
115 : profile_(profile), 115 : profile_(profile),
116 extension_devtools_manager_(NULL), 116 extension_devtools_manager_(NULL),
117 next_port_id_(0) { 117 next_port_id_(0) {
118 if (!ChromeThread::GetCurrentThreadIdentifier(&thread_id_)) {
119 // If we get created in unit test, GetCurrentThreadIdentifier fails.
120 // Assign thread_id_ to an ID not used.
121 thread_id_ = ChromeThread::ID_COUNT;
122 }
118 registrar_.Add(this, NotificationType::RENDERER_PROCESS_TERMINATED, 123 registrar_.Add(this, NotificationType::RENDERER_PROCESS_TERMINATED,
119 NotificationService::AllSources()); 124 NotificationService::AllSources());
120 registrar_.Add(this, NotificationType::RENDERER_PROCESS_CLOSED, 125 registrar_.Add(this, NotificationType::RENDERER_PROCESS_CLOSED,
121 NotificationService::AllSources()); 126 NotificationService::AllSources());
122 registrar_.Add(this, NotificationType::RENDER_VIEW_HOST_DELETED, 127 registrar_.Add(this, NotificationType::RENDER_VIEW_HOST_DELETED,
123 NotificationService::AllSources()); 128 NotificationService::AllSources());
124 129
125 extension_devtools_manager_ = profile_->GetExtensionDevToolsManager(); 130 extension_devtools_manager_ = profile_->GetExtensionDevToolsManager();
126 } 131 }
127 132
128 ExtensionMessageService::~ExtensionMessageService() { 133 ExtensionMessageService::~ExtensionMessageService() {
129 STLDeleteContainerPairSecondPointers(channels_.begin(), channels_.end()); 134 STLDeleteContainerPairSecondPointers(channels_.begin(), channels_.end());
130 channels_.clear(); 135 channels_.clear();
131 } 136 }
132 137
133 void ExtensionMessageService::ProfileDestroyed() { 138 void ExtensionMessageService::ProfileDestroyed() {
134 profile_ = NULL; 139 profile_ = NULL;
135 140 if (!registrar_.IsEmpty()) {
136 // We remove notifications here because our destructor might be called on 141 if (thread_id_ != ChromeThread::ID_COUNT)
137 // a non-UI thread. 142 CHECK(ChromeThread::CurrentlyOn(thread_id_));
Erik does not do reviews 2009/11/25 15:52:11 If GetCurrentThreadIdentifier fails, I don't see h
huanr 2009/11/25 17:16:38 If GetCurrentThreadIdentifier fails, the thread_id
Erik does not do reviews 2009/11/25 17:32:49 I think you're missing my point. CurrentlyOn uses
138 registrar_.RemoveAll(); 143 registrar_.RemoveAll();
144 }
139 } 145 }
140 146
141 void ExtensionMessageService::AddEventListener(const std::string& event_name, 147 void ExtensionMessageService::AddEventListener(const std::string& event_name,
142 int render_process_id) { 148 int render_process_id) {
143 DCHECK(RenderProcessHost::FromID(render_process_id)) << 149 DCHECK(RenderProcessHost::FromID(render_process_id)) <<
144 "Adding event listener to a non-existant RenderProcessHost."; 150 "Adding event listener to a non-existant RenderProcessHost.";
145 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); 151 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
146 DCHECK_EQ(listeners_[event_name].count(render_process_id), 0u) << event_name; 152 DCHECK_EQ(listeners_[event_name].count(render_process_id), 0u) << event_name;
147 listeners_[event_name].insert(render_process_id); 153 listeners_[event_name].insert(render_process_id);
148 154
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 528
523 if (current->second->opener.sender == sender) { 529 if (current->second->opener.sender == sender) {
524 CloseChannelImpl(current, GET_CHANNEL_OPENER_ID(current->first), 530 CloseChannelImpl(current, GET_CHANNEL_OPENER_ID(current->first),
525 notify_other_port); 531 notify_other_port);
526 } else if (current->second->receiver.sender == sender) { 532 } else if (current->second->receiver.sender == sender) {
527 CloseChannelImpl(current, GET_CHANNEL_RECEIVERS_ID(current->first), 533 CloseChannelImpl(current, GET_CHANNEL_RECEIVERS_ID(current->first),
528 notify_other_port); 534 notify_other_port);
529 } 535 }
530 } 536 }
531 } 537 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_message_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698