Commit 52f885d0 authored by bshe@chromium.org's avatar bshe@chromium.org

Fix memory leak on Chromium OS Heapcheck and Chromium OS (valgrind)

Memcheck:Leak
   fun:_Znw*
   fun:_ZN3ash27DesktopBackgroundController16InstallComponentEPN4aura10RootWindowE
   fun:_ZN3ash27DesktopBackgroundController29InstallComponentForAllWindowsEv
   fun:_ZN3ash27DesktopBackgroundController29SetDesktopBackgroundImageModeEv
   fun:_ZN3ash27DesktopBackgroundController20CreateEmptyWallpaperEv
   fun:_ZN3ash12_GLOBAL__N_126DummyUserWallpaperDelegate19InitializeWallpaperEv
   fun:_ZN3ash5Shell4InitEv
   fun:_ZN3ash5Shell14CreateInstanceEPNS_13ShellDelegateE
   fun:_ZN3ash4test11AshTestBase5SetUpEv

http://build.chromium.org/p/chromium.memory.fyi/builders/Chromium%20OS%20%28valgrind%29%284%29/builds/12953

BUG=141563, 141676, 142042

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151746 0039d316-1c4b-4281-b951-d872f2087c98
parent f16aabfd
...@@ -239,10 +239,10 @@ void DesktopBackgroundController::MoveDesktopToUnlockedContainer() { ...@@ -239,10 +239,10 @@ void DesktopBackgroundController::MoveDesktopToUnlockedContainer() {
} }
void DesktopBackgroundController::OnWindowDestroying(aura::Window* window) { void DesktopBackgroundController::OnWindowDestroying(aura::Window* window) {
window->SetProperty(internal::kWindowDesktopComponent, window->SetProperty(internal::kWindowDesktopComponent,
static_cast<internal::DesktopBackgroundWidgetController*>(NULL)); static_cast<internal::DesktopBackgroundWidgetController*>(NULL));
window->SetProperty(internal::kComponentWrapper, window->SetProperty(internal::kComponentWrapper,
static_cast<internal::ComponentWrapper*>(NULL)); static_cast<internal::ComponentWrapper*>(NULL));
} }
void DesktopBackgroundController::SetDesktopBackgroundImageMode() { void DesktopBackgroundController::SetDesktopBackgroundImageMode() {
...@@ -319,7 +319,13 @@ void DesktopBackgroundController::ReparentBackgroundWidgets(int src_container, ...@@ -319,7 +319,13 @@ void DesktopBackgroundController::ReparentBackgroundWidgets(int src_container,
aura::RootWindow* root_window = *iter; aura::RootWindow* root_window = *iter;
if (root_window->GetProperty(internal::kComponentWrapper)) { if (root_window->GetProperty(internal::kComponentWrapper)) {
internal::DesktopBackgroundWidgetController* component = root_window-> internal::DesktopBackgroundWidgetController* component = root_window->
GetProperty(internal::kComponentWrapper)->component(); GetProperty(internal::kWindowDesktopComponent);
// Wallpaper animation may not finish at this point. Try to get component
// from kComponentWrapper instead.
if (!component) {
component = root_window->GetProperty(internal::kComponentWrapper)->
GetComponent(false);
}
DCHECK(component); DCHECK(component);
component->Reparent(root_window, component->Reparent(root_window,
src_container, src_container,
......
...@@ -51,7 +51,7 @@ class ShowWallpaperAnimationObserver : public ui::ImplicitAnimationObserver { ...@@ -51,7 +51,7 @@ class ShowWallpaperAnimationObserver : public ui::ImplicitAnimationObserver {
// animation. // animation.
if (root_window_->GetProperty(kComponentWrapper)) { if (root_window_->GetProperty(kComponentWrapper)) {
internal::DesktopBackgroundWidgetController* component = internal::DesktopBackgroundWidgetController* component =
root_window_->GetProperty(kComponentWrapper)->component(); root_window_->GetProperty(kComponentWrapper)->GetComponent(true);
root_window_->SetProperty(kWindowDesktopComponent, component); root_window_->SetProperty(kWindowDesktopComponent, component);
} }
......
...@@ -55,7 +55,15 @@ void DesktopBackgroundWidgetController::Reparent(aura::RootWindow* root_window, ...@@ -55,7 +55,15 @@ void DesktopBackgroundWidgetController::Reparent(aura::RootWindow* root_window,
} }
ComponentWrapper::ComponentWrapper( ComponentWrapper::ComponentWrapper(
DesktopBackgroundWidgetController* component) : component_(component) { DesktopBackgroundWidgetController* component) {
component_.reset(component);
}
DesktopBackgroundWidgetController* ComponentWrapper::GetComponent(
bool pass_ownership) {
if (pass_ownership)
return component_.release();
return component_.get();
} }
} // namespace internal } // namespace internal
......
...@@ -58,10 +58,13 @@ class ComponentWrapper { ...@@ -58,10 +58,13 @@ class ComponentWrapper {
explicit ComponentWrapper( explicit ComponentWrapper(
DesktopBackgroundWidgetController* component); DesktopBackgroundWidgetController* component);
~ComponentWrapper() {} ~ComponentWrapper() {}
DesktopBackgroundWidgetController* component() { return component_; }
// Gets the wrapped DesktopBackgroundWidgetController pointer. Caller should
// take ownership of the pointer if |pass_ownership| is true.
DesktopBackgroundWidgetController* GetComponent(bool pass_ownership);
private: private:
DesktopBackgroundWidgetController* component_; scoped_ptr<DesktopBackgroundWidgetController> component_;
DISALLOW_COPY_AND_ASSIGN(ComponentWrapper); DISALLOW_COPY_AND_ASSIGN(ComponentWrapper);
}; };
......
...@@ -39,11 +39,12 @@ void RootWindowLayoutManager::OnWindowResized() { ...@@ -39,11 +39,12 @@ void RootWindowLayoutManager::OnWindowResized() {
for (j = (*i)->children().begin(); j != (*i)->children().end(); ++j) for (j = (*i)->children().begin(); j != (*i)->children().end(); ++j)
(*j)->SetBounds(fullscreen_bounds); (*j)->SetBounds(fullscreen_bounds);
} }
internal::DesktopBackgroundWidgetController* background = NULL; internal::DesktopBackgroundWidgetController* background =
internal::ComponentWrapper* wrapper = owner_->GetProperty(internal::kWindowDesktopComponent);
owner_->GetProperty(internal::kComponentWrapper); if (!background && owner_->GetProperty(internal::kComponentWrapper)) {
if (wrapper) background = owner_->GetProperty(internal::kComponentWrapper)->
background = wrapper->component(); GetComponent(false);
}
if (background) if (background)
background->SetBounds(fullscreen_bounds); background->SetBounds(fullscreen_bounds);
} }
......
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