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

Side by Side Diff: chrome/browser/media/media_stream_capture_indicator.cc

Issue 10825313: MediaStreamCaptureIndicator: fix crash due to destruction on wrong thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
« no previous file with comments | « chrome/browser/media/media_stream_capture_indicator.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) 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 #include "chrome/browser/media/media_stream_capture_indicator.h" 5 #include "chrome/browser/media/media_stream_capture_indicator.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 const MediaStreamCaptureIndicator::CaptureDeviceTab& tab) { 115 const MediaStreamCaptureIndicator::CaptureDeviceTab& tab) {
116 return (render_process_id_ == tab.render_process_id && 116 return (render_process_id_ == tab.render_process_id &&
117 render_view_id_ == tab.render_view_id); 117 render_view_id_ == tab.render_view_id);
118 } 118 }
119 119
120 MediaStreamCaptureIndicator::MediaStreamCaptureIndicator() 120 MediaStreamCaptureIndicator::MediaStreamCaptureIndicator()
121 : status_icon_(NULL), 121 : status_icon_(NULL),
122 mic_image_(NULL), 122 mic_image_(NULL),
123 camera_image_(NULL), 123 camera_image_(NULL),
124 balloon_image_(NULL), 124 balloon_image_(NULL),
125 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)),
126 request_index_(0) { 125 request_index_(0) {
127 } 126 }
128 127
129 MediaStreamCaptureIndicator::~MediaStreamCaptureIndicator() { 128 MediaStreamCaptureIndicator::~MediaStreamCaptureIndicator() {
130 // The user is responsible for cleaning up by closing all the opened devices. 129 // The user is responsible for cleaning up by closing all the opened devices.
131 DCHECK(tabs_.empty()); 130 DCHECK(tabs_.empty());
132 } 131 }
133 132
134 bool MediaStreamCaptureIndicator::IsCommandIdChecked( 133 bool MediaStreamCaptureIndicator::IsCommandIdChecked(
135 int command_id) const { 134 int command_id) const {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 message_id = IDS_MEDIA_STREAM_STATUS_TRAY_BALLOON_BODY_AUDIO_ONLY; 267 message_id = IDS_MEDIA_STREAM_STATUS_TRAY_BALLOON_BODY_AUDIO_ONLY;
269 else if (!audio && video) 268 else if (!audio && video)
270 message_id = IDS_MEDIA_STREAM_STATUS_TRAY_BALLOON_BODY_VIDEO_ONLY; 269 message_id = IDS_MEDIA_STREAM_STATUS_TRAY_BALLOON_BODY_VIDEO_ONLY;
271 270
272 const extensions::Extension* extension = 271 const extensions::Extension* extension =
273 GetExtension(render_process_id, render_view_id); 272 GetExtension(render_process_id, render_view_id);
274 if (extension) { 273 if (extension) {
275 pending_messages_[request_index_++] = 274 pending_messages_[request_index_++] =
276 l10n_util::GetStringFUTF16(message_id, 275 l10n_util::GetStringFUTF16(message_id,
277 UTF8ToUTF16(extension->name())); 276 UTF8ToUTF16(extension->name()));
278 tracker_.LoadImage( 277 EnsureImageLoadingTracker();
278 tracker_->LoadImage(
279 extension, 279 extension,
280 extension->GetIconResource(32, ExtensionIconSet::MATCH_BIGGER), 280 extension->GetIconResource(32, ExtensionIconSet::MATCH_BIGGER),
281 gfx::Size(32, 32), 281 gfx::Size(32, 32),
282 ImageLoadingTracker::CACHE); 282 ImageLoadingTracker::CACHE);
283 return; 283 return;
284 } 284 }
285 285
286 string16 title = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); 286 string16 title = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
287 string16 body = l10n_util::GetStringFUTF16(message_id, 287 string16 body = l10n_util::GetStringFUTF16(message_id,
288 GetSecurityOrigin(render_process_id, render_view_id)); 288 GetSecurityOrigin(render_process_id, render_view_id));
(...skipping 11 matching lines...) Expand all
300 status_icon_->DisplayBalloon( 300 status_icon_->DisplayBalloon(
301 !image.IsEmpty() ? *image.ToImageSkia() : 301 !image.IsEmpty() ? *image.ToImageSkia() :
302 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 302 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
303 IDR_APP_DEFAULT_ICON), 303 IDR_APP_DEFAULT_ICON),
304 string16(), 304 string16(),
305 message); 305 message);
306 } 306 }
307 307
308 void MediaStreamCaptureIndicator::Hide() { 308 void MediaStreamCaptureIndicator::Hide() {
309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
310
311 // We have to destroy |tracker_| on the UI thread.
312 tracker_.reset();
313
310 if (!status_icon_) 314 if (!status_icon_)
311 return; 315 return;
312 316
313 // If there is no browser process, we should not do anything. 317 // If there is no browser process, we should not do anything.
314 if (!g_browser_process) 318 if (!g_browser_process)
315 return; 319 return;
316 320
317 StatusTray* status_tray = g_browser_process->status_tray(); 321 StatusTray* status_tray = g_browser_process->status_tray();
318 if (status_tray != NULL) { 322 if (status_tray != NULL) {
319 status_tray->RemoveStatusIcon(status_icon_); 323 status_tray->RemoveStatusIcon(status_icon_);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 // Remove the tab if all the devices have been closed. 442 // Remove the tab if all the devices have been closed.
439 if (iter->audio_ref_count == 0 && iter->video_ref_count == 0) 443 if (iter->audio_ref_count == 0 && iter->video_ref_count == 0)
440 tabs_.erase(iter); 444 tabs_.erase(iter);
441 445
442 if (tabs_.empty()) 446 if (tabs_.empty())
443 Hide(); 447 Hide();
444 else 448 else
445 UpdateStatusTrayIconContextMenu(); 449 UpdateStatusTrayIconContextMenu();
446 } 450 }
447 451
452 void MediaStreamCaptureIndicator::EnsureImageLoadingTracker() {
453 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
454 if (tracker_.get())
455 return;
456
457 tracker_.reset(new ImageLoadingTracker(this));
458 pending_messages_.clear();
459 request_index_ = 0;
460 }
OLDNEW
« no previous file with comments | « chrome/browser/media/media_stream_capture_indicator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698