| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "athena/content/app_activity_registry.h" | 5 #include "athena/content/app_activity_registry.h" |
| 6 | 6 |
| 7 #include "athena/activity/public/activity_manager.h" | 7 #include "athena/activity/public/activity_manager.h" |
| 8 #include "athena/content/app_activity.h" | 8 #include "athena/content/app_activity.h" |
| 9 #include "athena/content/app_activity_proxy.h" | 9 #include "athena/content/app_activity_proxy.h" |
| 10 #include "athena/content/public/app_registry.h" | 10 #include "athena/content/public/app_registry.h" |
| 11 #include "athena/extensions/public/extensions_delegate.h" | 11 #include "athena/extensions/public/extensions_delegate.h" |
| 12 #include "athena/resource_manager/public/resource_manager.h" | 12 #include "athena/resource_manager/public/resource_manager.h" |
| 13 #include "athena/wm/public/window_list_provider.h" | 13 #include "athena/wm/public/window_list_provider.h" |
| 14 #include "athena/wm/public/window_manager.h" | 14 #include "athena/wm/public/window_manager.h" |
| 15 #include "base/bind.h" |
| 16 #include "base/location.h" |
| 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/thread_task_runner_handle.h" |
| 15 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 16 #include "ui/views/view.h" | 20 #include "ui/views/view.h" |
| 17 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 18 | 22 |
| 19 namespace athena { | 23 namespace athena { |
| 20 | 24 |
| 21 AppActivityRegistry::AppActivityRegistry( | 25 AppActivityRegistry::AppActivityRegistry( |
| 22 const std::string& app_id, | 26 const std::string& app_id, |
| 23 content::BrowserContext* browser_context) : | 27 content::BrowserContext* browser_context) : |
| 24 app_id_(app_id), | 28 app_id_(app_id), |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 if ((*it)->GetCurrentState() != Activity::ACTIVITY_UNLOADED) | 76 if ((*it)->GetCurrentState() != Activity::ACTIVITY_UNLOADED) |
| 73 return; | 77 return; |
| 74 } | 78 } |
| 75 | 79 |
| 76 // Create an activity proxy which can be used to re-activate the app. Insert | 80 // Create an activity proxy which can be used to re-activate the app. Insert |
| 77 // the proxy then into the activity stream at the location of the (newest) | 81 // the proxy then into the activity stream at the location of the (newest) |
| 78 // current activity. | 82 // current activity. |
| 79 unloaded_activity_proxy_ = new AppActivityProxy(GetMruActivity(), this); | 83 unloaded_activity_proxy_ = new AppActivityProxy(GetMruActivity(), this); |
| 80 ActivityManager::Get()->AddActivity(unloaded_activity_proxy_); | 84 ActivityManager::Get()->AddActivity(unloaded_activity_proxy_); |
| 81 | 85 |
| 82 // Unload the application. This operation will be asynchronous. | 86 // This function can be called through an observer call. When that happens, |
| 83 if (!ExtensionsDelegate::Get(browser_context_)->UnloadApp(app_id_)) { | 87 // several activities will be closed / started. That can then cause a crash. |
| 84 while(!activity_list_.empty()) | 88 // We postpone therefore the activity destruction till after the observer is |
| 85 Activity::Delete(activity_list_.back()); | 89 // done. |
| 86 } | 90 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 91 FROM_HERE, |
| 92 base::Bind(&AppActivityRegistry::DelayedUnload, base::Unretained(this))); |
| 87 } | 93 } |
| 88 | 94 |
| 89 void AppActivityRegistry::ProxyDestroyed(AppActivityProxy* proxy) { | 95 void AppActivityRegistry::ProxyDestroyed(AppActivityProxy* proxy) { |
| 90 DCHECK_EQ(unloaded_activity_proxy_, proxy); | 96 DCHECK_EQ(unloaded_activity_proxy_, proxy); |
| 91 unloaded_activity_proxy_ = NULL; | 97 unloaded_activity_proxy_ = NULL; |
| 92 if (activity_list_.empty()) { | 98 if (activity_list_.empty()) { |
| 93 AppRegistry::Get()->RemoveAppActivityRegistry(this); | 99 AppRegistry::Get()->RemoveAppActivityRegistry(this); |
| 94 // |This| is gone now. | 100 // |This| is gone now. |
| 95 } | 101 } |
| 96 } | 102 } |
| 97 | 103 |
| 98 void AppActivityRegistry::RestartApplication(AppActivityProxy* proxy) { | 104 void AppActivityRegistry::RestartApplication(AppActivityProxy* proxy) { |
| 99 DCHECK_EQ(unloaded_activity_proxy_, proxy); | 105 DCHECK_EQ(unloaded_activity_proxy_, proxy); |
| 100 // Restart the application. Note that the first created app window will make | 106 // Restart the application. Note that the first created app window will make |
| 101 // sure that the proxy gets deleted - after - the new activity got moved | 107 // sure that the proxy gets deleted - after - the new activity got moved |
| 102 // to the proxies activity location. | 108 // to the proxies activity location. |
| 103 ExtensionsDelegate::Get(browser_context_)->LaunchApp(app_id_); | 109 ExtensionsDelegate::Get(browser_context_)->LaunchApp(app_id_); |
| 104 } | 110 } |
| 105 | 111 |
| 112 void AppActivityRegistry::DelayedUnload() { |
| 113 if (!ExtensionsDelegate::Get(browser_context_)->UnloadApp(app_id_)) { |
| 114 while(!activity_list_.empty()) |
| 115 Activity::Delete(activity_list_.back()); |
| 116 } |
| 117 } |
| 118 |
| 106 AppActivity* AppActivityRegistry::GetMruActivity() { | 119 AppActivity* AppActivityRegistry::GetMruActivity() { |
| 107 DCHECK(activity_list_.size()); | 120 DCHECK(activity_list_.size()); |
| 108 WindowListProvider* window_list_provider = | 121 WindowListProvider* window_list_provider = |
| 109 WindowManager::GetInstance()->GetWindowListProvider(); | 122 WindowManager::GetInstance()->GetWindowListProvider(); |
| 110 const aura::Window::Windows children = | 123 const aura::Window::Windows children = |
| 111 window_list_provider->GetWindowList(); | 124 window_list_provider->GetWindowList(); |
| 112 // Find the first window in the container which is part of the application. | 125 // Find the first window in the container which is part of the application. |
| 113 for (aura::Window::Windows::const_iterator child_iterator = children.begin(); | 126 for (aura::Window::Windows::const_iterator child_iterator = children.begin(); |
| 114 child_iterator != children.end(); ++child_iterator) { | 127 child_iterator != children.end(); ++child_iterator) { |
| 115 for (std::vector<AppActivity*>::iterator app_iterator = | 128 for (std::vector<AppActivity*>::iterator app_iterator = |
| 116 activity_list_.begin(); | 129 activity_list_.begin(); |
| 117 app_iterator != activity_list_.end(); ++app_iterator) { | 130 app_iterator != activity_list_.end(); ++app_iterator) { |
| 118 if (*child_iterator == (*app_iterator)->GetWindow()) | 131 if (*child_iterator == (*app_iterator)->GetWindow()) |
| 119 return *app_iterator; | 132 return *app_iterator; |
| 120 } | 133 } |
| 121 } | 134 } |
| 122 NOTREACHED() << "The application does not get tracked by the mru list"; | 135 NOTREACHED() << "The application does not get tracked by the mru list"; |
| 123 return NULL; | 136 return NULL; |
| 124 } | 137 } |
| 125 | 138 |
| 126 } // namespace athena | 139 } // namespace athena |
| OLD | NEW |