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 // Unload the application asynchronously to avoid the activity destruction |
83 if (!ExtensionsDelegate::Get(browser_context_)->UnloadApp(app_id_)) { | 87 // while we are in an observerloop. |
sadrul
2014/09/12 16:30:14
I am not sure what this means, but if you mean whi
Mr4D (OOO till 08-26)
2014/09/12 20:11:26
Updated the comment.
But I do not remember exactl
| |
84 while(!activity_list_.empty()) | 88 base::ThreadTaskRunnerHandle::Get()->PostTask( |
85 Activity::Delete(activity_list_.back()); | 89 FROM_HERE, |
86 } | 90 base::Bind(&AppActivityRegistry::DelayedUnload, base::Unretained(this))); |
87 } | 91 } |
88 | 92 |
89 void AppActivityRegistry::ProxyDestroyed(AppActivityProxy* proxy) { | 93 void AppActivityRegistry::ProxyDestroyed(AppActivityProxy* proxy) { |
90 DCHECK_EQ(unloaded_activity_proxy_, proxy); | 94 DCHECK_EQ(unloaded_activity_proxy_, proxy); |
91 unloaded_activity_proxy_ = NULL; | 95 unloaded_activity_proxy_ = NULL; |
92 if (activity_list_.empty()) { | 96 if (activity_list_.empty()) { |
93 AppRegistry::Get()->RemoveAppActivityRegistry(this); | 97 AppRegistry::Get()->RemoveAppActivityRegistry(this); |
94 // |This| is gone now. | 98 // |This| is gone now. |
95 } | 99 } |
96 } | 100 } |
97 | 101 |
98 void AppActivityRegistry::RestartApplication(AppActivityProxy* proxy) { | 102 void AppActivityRegistry::RestartApplication(AppActivityProxy* proxy) { |
99 DCHECK_EQ(unloaded_activity_proxy_, proxy); | 103 DCHECK_EQ(unloaded_activity_proxy_, proxy); |
100 // Restart the application. Note that the first created app window will make | 104 // 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 | 105 // sure that the proxy gets deleted - after - the new activity got moved |
102 // to the proxies activity location. | 106 // to the proxies activity location. |
103 ExtensionsDelegate::Get(browser_context_)->LaunchApp(app_id_); | 107 ExtensionsDelegate::Get(browser_context_)->LaunchApp(app_id_); |
104 } | 108 } |
105 | 109 |
110 void AppActivityRegistry::DelayedUnload() { | |
111 if (!ExtensionsDelegate::Get(browser_context_)->UnloadApp(app_id_)) { | |
112 while(!activity_list_.empty()) | |
113 Activity::Delete(activity_list_.back()); | |
114 } | |
115 } | |
116 | |
106 AppActivity* AppActivityRegistry::GetMruActivity() { | 117 AppActivity* AppActivityRegistry::GetMruActivity() { |
107 DCHECK(activity_list_.size()); | 118 DCHECK(activity_list_.size()); |
108 WindowListProvider* window_list_provider = | 119 WindowListProvider* window_list_provider = |
109 WindowManager::GetInstance()->GetWindowListProvider(); | 120 WindowManager::GetInstance()->GetWindowListProvider(); |
110 const aura::Window::Windows children = | 121 const aura::Window::Windows children = |
111 window_list_provider->GetWindowList(); | 122 window_list_provider->GetWindowList(); |
112 // Find the first window in the container which is part of the application. | 123 // Find the first window in the container which is part of the application. |
113 for (aura::Window::Windows::const_iterator child_iterator = children.begin(); | 124 for (aura::Window::Windows::const_iterator child_iterator = children.begin(); |
114 child_iterator != children.end(); ++child_iterator) { | 125 child_iterator != children.end(); ++child_iterator) { |
115 for (std::vector<AppActivity*>::iterator app_iterator = | 126 for (std::vector<AppActivity*>::iterator app_iterator = |
116 activity_list_.begin(); | 127 activity_list_.begin(); |
117 app_iterator != activity_list_.end(); ++app_iterator) { | 128 app_iterator != activity_list_.end(); ++app_iterator) { |
118 if (*child_iterator == (*app_iterator)->GetWindow()) | 129 if (*child_iterator == (*app_iterator)->GetWindow()) |
119 return *app_iterator; | 130 return *app_iterator; |
120 } | 131 } |
121 } | 132 } |
122 NOTREACHED() << "The application does not get tracked by the mru list"; | 133 NOTREACHED() << "The application does not get tracked by the mru list"; |
123 return NULL; | 134 return NULL; |
124 } | 135 } |
125 | 136 |
126 } // namespace athena | 137 } // namespace athena |
OLD | NEW |