Index: athena/content/app_activity_registry.cc |
diff --git a/athena/content/app_activity_registry.cc b/athena/content/app_activity_registry.cc |
index 5a6402f0e714711f3771c0464a697ac27ca62c3f..99ab808bd1a088b652c95746a9554534ba66b0e0 100644 |
--- a/athena/content/app_activity_registry.cc |
+++ b/athena/content/app_activity_registry.cc |
@@ -10,7 +10,6 @@ |
#include "athena/content/public/app_registry.h" |
#include "athena/extensions/public/extensions_delegate.h" |
#include "athena/resource_manager/public/resource_manager.h" |
-#include "athena/wm/public/window_list_provider.h" |
#include "athena/wm/public/window_manager.h" |
#include "base/bind.h" |
#include "base/location.h" |
@@ -72,26 +71,27 @@ void AppActivityRegistry::Unload() { |
DCHECK(!activity_list_.empty()); |
// In order to allow an entire application to unload we require that all of |
// its activities are marked as unloaded. |
- for (std::vector<AppActivity*>::iterator it = activity_list_.begin(); |
- it != activity_list_.end(); ++it) { |
- if ((*it)->GetCurrentState() != Activity::ACTIVITY_UNLOADED) |
+ for (AppActivity* activity : activity_list_) { |
+ if (activity->GetCurrentState() != Activity::ACTIVITY_UNLOADED) |
return; |
} |
// Create an activity proxy which can be used to re-activate the app. Insert |
// the proxy then into the activity stream at the location of the (newest) |
// current activity. |
- unloaded_activity_proxy_ = new AppActivityProxy(GetMruActivity(), this); |
- ActivityManager::Get()->AddActivity(unloaded_activity_proxy_); |
+ AppActivity* mru_activity = GetMruActivity(); |
+ CHECK(mru_activity); |
+ unloaded_activity_proxy_ = new AppActivityProxy(mru_activity, this); |
+ ScopedActivity removed_activity = |
+ ActivityManager::Get()->ReplaceActivity(mru_activity, |
+ unloaded_activity_proxy_); |
unloaded_activity_proxy_->GetWindow()->SetName("AppActivityProxy"); |
- // This function can be called through an observer call. When that happens, |
- // several activities will be closed / started. That can then cause a crash. |
- // We postpone therefore the activity destruction till after the observer is |
- // done. |
- base::ThreadTaskRunnerHandle::Get()->PostTask( |
- FROM_HERE, |
- base::Bind(&AppActivityRegistry::DelayedUnload, base::Unretained(this))); |
+ if (!ExtensionsDelegate::Get(browser_context_)->UnloadApp(app_id_)) { |
+ removed_activity.reset(); |
+ while(!activity_list_.empty()) |
+ Activity::Delete(activity_list_.back()); |
+ } |
} |
void AppActivityRegistry::ProxyDestroyed(AppActivityProxy* proxy) { |
@@ -111,28 +111,15 @@ void AppActivityRegistry::RestartApplication(AppActivityProxy* proxy) { |
ExtensionsDelegate::Get(browser_context_)->LaunchApp(app_id_); |
} |
-void AppActivityRegistry::DelayedUnload() { |
- if (!ExtensionsDelegate::Get(browser_context_)->UnloadApp(app_id_)) { |
- while(!activity_list_.empty()) |
- Activity::Delete(activity_list_.back()); |
- } |
-} |
- |
AppActivity* AppActivityRegistry::GetMruActivity() { |
DCHECK(activity_list_.size()); |
- WindowListProvider* window_list_provider = |
- WindowManager::Get()->GetWindowListProvider(); |
- const aura::Window::Windows& children = |
- window_list_provider->GetWindowList(); |
- // Find the first window in the container which is part of the application. |
- for (aura::Window::Windows::const_iterator child_iterator = children.begin(); |
- child_iterator != children.end(); ++child_iterator) { |
- for (std::vector<AppActivity*>::iterator app_iterator = |
- activity_list_.begin(); |
- app_iterator != activity_list_.end(); ++app_iterator) { |
- if (*child_iterator == (*app_iterator)->GetWindow()) |
- return *app_iterator; |
- } |
+ const ActivityList& all_activities = |
+ ActivityManager::Get()->GetActivityList(); |
+ for (Activity* activity : all_activities) { |
+ std::vector<AppActivity*>::const_iterator iter = |
+ std::find(activity_list_.begin(), activity_list_.end(), activity); |
+ if (iter != activity_list_.end()) |
+ return *iter; |
} |
NOTREACHED() << "The application does not get tracked by the mru list"; |
return nullptr; |