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 "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
13 #include "ui/views/view.h" | 14 #include "ui/views/view.h" |
14 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
15 | 16 |
16 namespace athena { | 17 namespace athena { |
17 | 18 |
18 AppActivityRegistry::AppActivityRegistry( | 19 AppActivityRegistry::AppActivityRegistry( |
19 const std::string& app_id, | 20 const std::string& app_id, |
20 content::BrowserContext* browser_context) : | 21 content::BrowserContext* browser_context) : |
21 app_id_(app_id), | 22 app_id_(app_id), |
22 browser_context_(browser_context), | 23 browser_context_(browser_context), |
23 unloaded_activity_proxy_(NULL) {} | 24 unloaded_activity_proxy_(NULL) {} |
24 | 25 |
25 AppActivityRegistry::~AppActivityRegistry() { | 26 AppActivityRegistry::~AppActivityRegistry() { |
26 CHECK(activity_list_.empty()); | 27 CHECK(activity_list_.empty()); |
27 if (unloaded_activity_proxy_) | 28 if (unloaded_activity_proxy_) |
28 ActivityManager::Get()->RemoveActivity(unloaded_activity_proxy_); | 29 ActivityManager::Get()->RemoveActivity(unloaded_activity_proxy_); |
29 DCHECK(!unloaded_activity_proxy_); | 30 DCHECK(!unloaded_activity_proxy_); |
30 } | 31 } |
31 | 32 |
32 void AppActivityRegistry::RegisterAppActivity(AppActivity* app_activity) { | 33 void AppActivityRegistry::RegisterAppActivity(AppActivity* app_activity) { |
33 if (unloaded_activity_proxy_) { | |
34 // Since we add an application window, the activity isn't unloaded anymore. | |
35 ActivityManager::Get()->RemoveActivity(unloaded_activity_proxy_); | |
36 // With the removal the object should have been deleted and we should have | |
37 // been informed of the object's destruction. | |
38 DCHECK(!unloaded_activity_proxy_); | |
39 } | |
40 // The same window should never be added twice. | 34 // The same window should never be added twice. |
41 CHECK(std::find(activity_list_.begin(), | 35 CHECK(std::find(activity_list_.begin(), |
42 activity_list_.end(), | 36 activity_list_.end(), |
43 app_activity) == activity_list_.end()); | 37 app_activity) == activity_list_.end()); |
44 activity_list_.push_back(app_activity); | 38 activity_list_.push_back(app_activity); |
45 } | 39 } |
46 | 40 |
47 void AppActivityRegistry::UnregisterAppActivity(AppActivity* app_activity) { | 41 void AppActivityRegistry::UnregisterAppActivity(AppActivity* app_activity) { |
48 // It is possible that a detach gets called without ever being attached. | 42 // It is possible that a detach gets called without ever being attached. |
49 std::vector<AppActivity*>::iterator it = | 43 std::vector<AppActivity*>::iterator it = |
(...skipping 12 matching lines...) Expand all Loading... | |
62 | 56 |
63 AppActivity* AppActivityRegistry::GetAppActivityAt(size_t index) { | 57 AppActivity* AppActivityRegistry::GetAppActivityAt(size_t index) { |
64 if (index >= activity_list_.size()) | 58 if (index >= activity_list_.size()) |
65 return NULL; | 59 return NULL; |
66 return activity_list_[index]; | 60 return activity_list_[index]; |
67 } | 61 } |
68 | 62 |
69 void AppActivityRegistry::Unload() { | 63 void AppActivityRegistry::Unload() { |
70 CHECK(!unloaded_activity_proxy_); | 64 CHECK(!unloaded_activity_proxy_); |
71 DCHECK(!activity_list_.empty()); | 65 DCHECK(!activity_list_.empty()); |
72 | |
73 // In order to allow an entire application to unload we require that all of | 66 // In order to allow an entire application to unload we require that all of |
74 // its activities are marked as unloaded. | 67 // its activities are marked as unloaded. |
75 for (std::vector<AppActivity*>::iterator it = activity_list_.begin(); | 68 for (std::vector<AppActivity*>::iterator it = activity_list_.begin(); |
76 it != activity_list_.end(); ++it) { | 69 it != activity_list_.end(); ++it) { |
77 if ((*it)->GetCurrentState() != Activity::ACTIVITY_UNLOADED) | 70 if ((*it)->GetCurrentState() != Activity::ACTIVITY_UNLOADED) |
78 return; | 71 return; |
79 } | 72 } |
80 | 73 |
81 // Create an activity proxy which can be used to re-activate the app. Insert | 74 // Create an activity proxy which can be used to re-activate the app. Insert |
82 // the proxy then into the activity stream at the location of the (newest) | 75 // the proxy then into the activity stream at the location of the (newest) |
83 // current activity. | 76 // current activity. |
84 unloaded_activity_proxy_ = | 77 unloaded_activity_proxy_ = new AppActivityProxy(GetMruActivity(), this); |
85 new AppActivityProxy(activity_list_[0]->GetActivityViewModel(), this); | |
86 ActivityManager::Get()->AddActivity(unloaded_activity_proxy_); | 78 ActivityManager::Get()->AddActivity(unloaded_activity_proxy_); |
87 // The new activity should be in the place of the most recently used app | |
88 // window. To get it there, we get the most recently used application window | |
89 // and place the proxy activities window in front or behind, so that when the | |
90 // activity disappears it takes its place. | |
91 MoveBeforeMruApplicationWindow(unloaded_activity_proxy_->GetWindow()); | |
92 | 79 |
93 // Unload the application. This operation will be asynchronous. | 80 // Unload the application. This operation will be asynchronous. |
94 if (!ExtensionsDelegate::Get(browser_context_)->UnloadApp(app_id_)) { | 81 if (!ExtensionsDelegate::Get(browser_context_)->UnloadApp(app_id_)) { |
95 while(!activity_list_.empty()) | 82 while(!activity_list_.empty()) |
96 delete activity_list_.back(); | 83 Activity::CloseActivity(activity_list_.back()); |
97 } | 84 } |
98 } | 85 } |
99 | 86 |
100 void AppActivityRegistry::ProxyDestroyed(AppActivityProxy* proxy) { | 87 void AppActivityRegistry::ProxyDestroyed(AppActivityProxy* proxy) { |
101 DCHECK_EQ(unloaded_activity_proxy_, proxy); | 88 DCHECK_EQ(unloaded_activity_proxy_, proxy); |
102 unloaded_activity_proxy_ = NULL; | 89 unloaded_activity_proxy_ = NULL; |
103 if (activity_list_.empty()) { | 90 if (activity_list_.empty()) { |
104 AppRegistry::Get()->RemoveAppActivityRegistry(this); | 91 AppRegistry::Get()->RemoveAppActivityRegistry(this); |
105 // |This| is gone now. | 92 // |This| is gone now. |
106 } | 93 } |
107 } | 94 } |
108 | 95 |
109 void AppActivityRegistry::RestartApplication(AppActivityProxy* proxy) { | 96 void AppActivityRegistry::RestartApplication(AppActivityProxy* proxy) { |
110 DCHECK_EQ(unloaded_activity_proxy_, proxy); | 97 DCHECK_EQ(unloaded_activity_proxy_, proxy); |
111 // Restart the application. | 98 // Restart the application. Note that the first created app window will make |
99 // sure that the proxy gets deleted - after - the new activity got moved | |
100 // to the proxies activity location. | |
112 ExtensionsDelegate::Get(browser_context_)->LaunchApp(app_id_); | 101 ExtensionsDelegate::Get(browser_context_)->LaunchApp(app_id_); |
113 // Delete the activity which will also remove the it from the ActivityManager. | |
114 delete unloaded_activity_proxy_; // Will call ProxyDestroyed. | |
115 // After this call |this| might be gone if the app did not open a window yet. | |
116 } | 102 } |
117 | 103 |
118 void AppActivityRegistry::MoveBeforeMruApplicationWindow(aura::Window* window) { | 104 AppActivity* AppActivityRegistry::GetMruActivity() { |
oshima
2014/09/04 16:39:23
MruActivity may not be app activity right?
Mr4D (OOO till 08-26)
2014/09/04 19:10:57
Well - this is the MRU for *this* app (if there ar
| |
119 DCHECK(activity_list_.size()); | 105 DCHECK(activity_list_.size()); |
120 // TODO(skuhne): This needs to be changed to some kind of delegate which | 106 // TODO(skuhne): This should be a query into the window manager. |
121 // resides in the window manager. | |
122 const aura::Window::Windows children = | 107 const aura::Window::Windows children = |
123 activity_list_[0]->GetWindow()->parent()->children();; | 108 activity_list_[0]->GetWindow()->parent()->children(); |
124 // Find the first window in the container which is part of the application. | 109 // Find the first window in the container which is part of the application. |
125 for (aura::Window::Windows::const_iterator child_iterator = children.begin(); | 110 for (aura::Window::Windows::const_iterator child_iterator = children.begin(); |
126 child_iterator != children.end(); ++child_iterator) { | 111 child_iterator != children.end(); ++child_iterator) { |
127 for (std::vector<AppActivity*>::iterator app_iterator = | 112 for (std::vector<AppActivity*>::iterator app_iterator = |
128 activity_list_.begin(); | 113 activity_list_.begin(); |
129 app_iterator != activity_list_.end(); ++app_iterator) { | 114 app_iterator != activity_list_.end(); ++app_iterator) { |
130 if (*child_iterator == (*app_iterator)->GetWindow()) { | 115 if (*child_iterator == (*app_iterator)->GetWindow()) |
131 // Since "StackChildBelow" does not change the order if the window | 116 return *app_iterator; |
132 // if the window is below - but not immediately behind - the target | |
133 // window, we re-stack both ways. | |
134 window->parent()->StackChildBelow(window, *child_iterator); | |
135 window->parent()->StackChildBelow(*child_iterator, window); | |
136 return; | |
137 } | |
138 } | 117 } |
139 } | 118 } |
140 NOTREACHED() << "The application does not get tracked by the mru list"; | 119 NOTREACHED() << "The application does not get tracked by the mru list"; |
120 return NULL; | |
141 } | 121 } |
142 | 122 |
143 } // namespace athena | 123 } // namespace athena |
OLD | NEW |