Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: athena/content/app_activity_registry.cc

Issue 477523002: Athena: Adding basic resource management framework (un-/re-loading) of V2 applications (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "athena/content/app_activity_registry.h"
6
7 #include "athena/activity/public/activity_manager.h"
8 #include "athena/content/app_activity.h"
9 #include "athena/content/app_activity_proxy.h"
10 #include "athena/content/public/app_content_delegate.h"
11 #include "athena/content/public/app_registry.h"
12 #include "ui/aura/window.h"
13 #include "ui/views/view.h"
14 #include "ui/views/widget/widget.h"
15
16 namespace athena {
17
18 AppActivityRegistry::AppActivityRegistry(
19 const std::string& app_id,
20 content::BrowserContext* browser_context) :
21 app_id_(app_id),
22 browser_context_(browser_context),
23 unloaded_activity_proxy_(NULL) {}
24
25 AppActivityRegistry::~AppActivityRegistry() {
26 CHECK(activity_list_.empty());
27 if (unloaded_activity_proxy_)
28 ActivityManager::Get()->RemoveActivity(unloaded_activity_proxy_);
29 DCHECK(!unloaded_activity_proxy_);
30 }
31
32 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.
41 CHECK(std::find(activity_list_.begin(),
42 activity_list_.end(),
43 app_activity) == activity_list_.end());
44 activity_list_.push_back(app_activity);
45 }
46
47 void AppActivityRegistry::UnregisterAppActivity(AppActivity* app_activity) {
48 // It is possible that a detach gets called without ever being attached.
49 std::vector<AppActivity*>::iterator it =
50 std::find(activity_list_.begin(), activity_list_.end(), app_activity);
51 if (it == activity_list_.end())
52 return;
53
54 activity_list_.erase(it);
55 // When the last window gets destroyed and there is no proxy to restart, we
56 // delete ourselves.
57 if (activity_list_.empty() && !unloaded_activity_proxy_) {
58 AppRegistry::Get()->RemoveAppActivityRegistry(this);
59 // after this call this object should be gone.
60 }
61 }
62
63 void AppActivityRegistry::Unload() {
64 CHECK(!unloaded_activity_proxy_);
65 DCHECK(!activity_list_.empty());
66
67 // In order to allow an entire application to unload we require that all of
68 // its activities are marked as unloaded.
69 for (std::vector<AppActivity*>::iterator it = activity_list_.begin();
70 it != activity_list_.end(); ++it) {
71 if ((*it)->GetCurrentState() != Activity::ACTIVITY_UNLOADED)
72 return;
73 }
74
75 // Create an activity proxy which can be used to re-activate the app. Insert
76 // the proxy then into the activity stream at the location of the (newest)
77 // current activity.
78 unloaded_activity_proxy_ =
79 new AppActivityProxy(activity_list_[0]->GetActivityViewModel(), this);
80 ActivityManager::Get()->AddActivity(unloaded_activity_proxy_);
81 // The new activity should be in the place of the most recently used app
82 // window. To get it there, we get the most recently used application window
83 // and place the proxy activities window in front or behind, so that when the
84 // activity disappears it takes its place.
85 // Note: Since the new app window is newer, it should be over the mru app
86 // window and therefore we move it below it.
87 aura::Window* window = unloaded_activity_proxy_->GetWindow();
88 aura::Window* mru_app_window = FindMruApplicationWindow();
89 DCHECK_EQ(window->parent(), mru_app_window->parent());
90 window->parent()->StackChildBelow(window, mru_app_window);
91
92 // Unload the application. This operation will be asynchronous.
93 if (!AppRegistry::Get()->GetDelegate()->UnloadApplication(app_id_,
94 browser_context_)) {
95 activity_list_.clear();
96 }
97 }
98
99 void AppActivityRegistry::ProxyDestroyed(AppActivityProxy* proxy) {
100 DCHECK_EQ(unloaded_activity_proxy_, proxy);
101 unloaded_activity_proxy_ = NULL;
102 }
103
104 void AppActivityRegistry::RestartApplication(AppActivityProxy* proxy) {
105 DCHECK_EQ(unloaded_activity_proxy_, proxy);
106 // First remove the activity from the Activity manager.
107 ActivityManager::Get()->RemoveActivity(unloaded_activity_proxy_);
108 // Restart the application.
109 AppRegistry::Get()->GetDelegate()->RestartApplication(app_id_,
110 browser_context_);
111 }
112
113 aura::Window* AppActivityRegistry::FindMruApplicationWindow() {
114 DCHECK(activity_list_.size());
115 const aura::Window::Windows children =
116 activity_list_[0]->GetWindow()->parent()->children();
oshima 2014/08/15 15:15:59 This should use WindowListProvider (which you prob
Mr4D (OOO till 08-26) 2014/08/18 16:09:32 Hmm... So the order of windows within the children
oshima 2014/08/18 17:51:43 The code above has too much knowledge/assumption t
Mr4D (OOO till 08-26) 2014/08/18 22:36:31 I added a comment to change this once we have a be
oshima 2014/08/18 23:14:01 It's ok to add athena/wm to content/DEPS. It doesn
117 // Find the first window in the container which is part of the application.
118 for (aura::Window::Windows::const_iterator child_iterator = children.begin();
119 child_iterator != children.end(); ++child_iterator) {
120 for (std::vector<AppActivity*>::iterator app_iterator =
121 activity_list_.begin();
122 app_iterator != activity_list_.end(); ++app_iterator) {
123 if (*child_iterator == (*app_iterator)->GetWindow())
124 return *child_iterator;
125 }
126 }
127 NOTREACHED() << "The application does not have a window in this container";
128 return NULL;
129 }
130
131 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698