Commit 2dff55da authored by estade@chromium.org's avatar estade@chromium.org

MediaStreamCaptureIndicator: fix crash due to destruction on wrong thread

BUG=141831

Review URL: https://chromiumcodereview.appspot.com/10825313

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151565 0039d316-1c4b-4281-b951-d872f2087c98
parent 0d5778fe
......@@ -122,7 +122,6 @@ MediaStreamCaptureIndicator::MediaStreamCaptureIndicator()
mic_image_(NULL),
camera_image_(NULL),
balloon_image_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)),
request_index_(0) {
}
......@@ -274,7 +273,8 @@ void MediaStreamCaptureIndicator::ShowBalloon(
pending_messages_[request_index_++] =
l10n_util::GetStringFUTF16(message_id,
UTF8ToUTF16(extension->name()));
tracker_.LoadImage(
EnsureImageLoadingTracker();
tracker_->LoadImage(
extension,
extension->GetIconResource(32, ExtensionIconSet::MATCH_BIGGER),
gfx::Size(32, 32),
......@@ -307,6 +307,10 @@ void MediaStreamCaptureIndicator::OnImageLoaded(
void MediaStreamCaptureIndicator::Hide() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(tabs_.empty());
// We have to destroy |tracker_| on the UI thread.
tracker_.reset();
if (!status_icon_)
return;
......@@ -445,3 +449,12 @@ void MediaStreamCaptureIndicator::RemoveCaptureDeviceTab(
UpdateStatusTrayIconContextMenu();
}
void MediaStreamCaptureIndicator::EnsureImageLoadingTracker() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (tracker_.get())
return;
tracker_.reset(new ImageLoadingTracker(this));
pending_messages_.clear();
request_index_ = 0;
}
......@@ -9,6 +9,7 @@
#include <vector>
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/extensions/image_loading_tracker.h"
#include "content/public/common/media_stream_request.h"
#include "ui/base/models/simple_menu_model.h"
......@@ -127,6 +128,9 @@ class MediaStreamCaptureIndicator
// UpdateStatusTrayIconContextMenu().
void UpdateStatusTrayIconDisplay(bool audio, bool video);
// Initializes image loading state.
void EnsureImageLoadingTracker();
// Reference to our status icon - owned by the StatusTray. If null,
// the platform doesn't support status icons.
StatusIcon* status_icon_;
......@@ -141,7 +145,7 @@ class MediaStreamCaptureIndicator
CaptureDeviceTabs tabs_;
// Tracks the load of extension icons.
ImageLoadingTracker tracker_;
scoped_ptr<ImageLoadingTracker> tracker_;
// The messages to display when extension images are loaded. The index
// corresponds to the index of the associated LoadImage request.
std::map<int, string16> pending_messages_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment