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

Side by Side Diff: athena/content/app_activity.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: Merged with trunk 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
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.h" 5 #include "athena/content/app_activity.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_registry.h"
9 #include "athena/content/public/app_content_delegate.h"
10 #include "athena/content/public/app_registry.h"
8 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
9 #include "extensions/shell/browser/shell_app_window.h" 12 #include "extensions/shell/browser/shell_app_window.h"
10 #include "ui/views/controls/webview/webview.h" 13 #include "ui/views/controls/webview/webview.h"
14 #include "ui/views/widget/widget.h"
11 15
12 namespace athena { 16 namespace athena {
13 17
14 // TODO(mukai): specifies the same accelerators of WebActivity. 18 // TODO(mukai): specifies the same accelerators of WebActivity.
15 AppActivity::AppActivity(extensions::ShellAppWindow* app_window) 19 AppActivity::AppActivity(extensions::ShellAppWindow* app_window)
16 : app_window_(app_window), 20 : app_window_(app_window),
17 web_view_(NULL), 21 web_view_(NULL),
18 current_state_(ACTIVITY_UNLOADED) { 22 current_state_(ACTIVITY_UNLOADED),
19 DCHECK(app_window_); 23 app_activity_registry_(NULL) {
20 } 24 }
21 25
22 AppActivity::~AppActivity() { 26 AppActivity::~AppActivity() {
23 if (GetCurrentState() != ACTIVITY_UNLOADED) 27 // If this activity is registered, we unregister it now.
24 SetCurrentState(ACTIVITY_UNLOADED); 28 if (app_activity_registry_)
29 app_activity_registry_->UnregisterAppActivity(this);
25 } 30 }
26 31
27 ActivityViewModel* AppActivity::GetActivityViewModel() { 32 ActivityViewModel* AppActivity::GetActivityViewModel() {
28 return this; 33 return this;
29 } 34 }
30 35
31 void AppActivity::SetCurrentState(Activity::ActivityState state) { 36 void AppActivity::SetCurrentState(Activity::ActivityState state) {
37 ActivityState current_state = state;
38 // Remember the last requested state now so that a call to GetCurrentState()
39 // returns the new state.
40 current_state_ = state;
41
32 switch (state) { 42 switch (state) {
33 case ACTIVITY_VISIBLE: 43 case ACTIVITY_VISIBLE:
34 // Fall through (for the moment). 44 // Fall through (for the moment).
35 case ACTIVITY_INVISIBLE: 45 case ACTIVITY_INVISIBLE:
36 // By clearing the overview mode image we allow the content to be shown. 46 // By clearing the overview mode image we allow the content to be shown.
37 overview_mode_image_ = gfx::ImageSkia(); 47 overview_mode_image_ = gfx::ImageSkia();
38 // TODO(skuhne): Find out how to reload an app from the extension system. 48 // Note: A reload from the unloaded state will be performed through the
49 // |AppActivityProxy| object and no further action isn't necessary here.
39 break; 50 break;
40 case ACTIVITY_BACKGROUND_LOW_PRIORITY: 51 case ACTIVITY_BACKGROUND_LOW_PRIORITY:
41 DCHECK(ACTIVITY_VISIBLE == current_state_ || 52 DCHECK(ACTIVITY_VISIBLE == current_state ||
42 ACTIVITY_INVISIBLE == current_state_); 53 ACTIVITY_INVISIBLE == current_state);
43 // TODO(skuhne): Do this. 54 // TODO(skuhne): Do this.
44 break; 55 break;
45 case ACTIVITY_PERSISTENT: 56 case ACTIVITY_PERSISTENT:
46 DCHECK_EQ(ACTIVITY_BACKGROUND_LOW_PRIORITY, current_state_); 57 DCHECK_EQ(ACTIVITY_BACKGROUND_LOW_PRIORITY, current_state);
47 // TODO(skuhne): Do this. 58 // TODO(skuhne): Do this.
48 break; 59 break;
49 case ACTIVITY_UNLOADED: 60 case ACTIVITY_UNLOADED:
50 DCHECK_NE(ACTIVITY_UNLOADED, current_state_); 61 DCHECK_NE(ACTIVITY_UNLOADED, current_state);
51 // TODO(skuhne): Find out how to evict an app from the extension system. 62 // This will cause the application to shut down, close its windows and
52 // web_view_->EvictContent(); 63 // delete this object. Instead a |AppActivityProxy| will be created as
64 // place holder.
65 if (app_activity_registry_)
66 app_activity_registry_->Unload();
53 break; 67 break;
54 } 68 }
55 // Remember the last requested state.
56 current_state_ = state;
57 } 69 }
58 70
59 Activity::ActivityState AppActivity::GetCurrentState() { 71 Activity::ActivityState AppActivity::GetCurrentState() {
60 // TODO(skuhne): Check here also eviction status.
61 if (!web_view_) { 72 if (!web_view_) {
62 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_); 73 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_);
63 return ACTIVITY_UNLOADED; 74 return ACTIVITY_UNLOADED;
64 } 75 }
65 // TODO(skuhne): This should be controlled by an observer and should not 76 // TODO(skuhne): This should be controlled by an observer and should not
66 // reside here. 77 // reside here.
67 if (IsVisible() && current_state_ != ACTIVITY_VISIBLE) 78 if (IsVisible() && current_state_ != ACTIVITY_VISIBLE)
68 SetCurrentState(ACTIVITY_VISIBLE); 79 SetCurrentState(ACTIVITY_VISIBLE);
69 // Note: If the activity is not visible it does not necessarily mean that it 80 // Note: If the activity is not visible it does not necessarily mean that it
70 // does not have GPU compositor resources (yet). 81 // does not have GPU compositor resources (yet).
71 return current_state_; 82 return current_state_;
72 } 83 }
73 84
74 bool AppActivity::IsVisible() { 85 bool AppActivity::IsVisible() {
75 return web_view_ && web_view_->IsDrawn(); 86 return web_view_ && web_view_->IsDrawn();
76 } 87 }
77 88
78 Activity::ActivityMediaState AppActivity::GetMediaState() { 89 Activity::ActivityMediaState AppActivity::GetMediaState() {
79 // TODO(skuhne): The function GetTabMediaStateForContents(WebContents), 90 // TODO(skuhne): The function GetTabMediaStateForContents(WebContents),
80 // and the AudioStreamMonitor needs to be moved from Chrome into contents to 91 // and the AudioStreamMonitor needs to be moved from Chrome into contents to
81 // make it more modular and so that we can use it from here. 92 // make it more modular and so that we can use it from here.
82 return Activity::ACTIVITY_MEDIA_STATE_NONE; 93 return Activity::ACTIVITY_MEDIA_STATE_NONE;
83 } 94 }
84 95
96 aura::Window* AppActivity::GetWindow() {
97 return !web_view_ ? NULL : web_view_->GetWidget()->GetNativeWindow();
98 }
99
85 void AppActivity::Init() { 100 void AppActivity::Init() {
86 } 101 }
87 102
88 SkColor AppActivity::GetRepresentativeColor() const { 103 SkColor AppActivity::GetRepresentativeColor() const {
89 // TODO(sad): Compute the color from the favicon. 104 // TODO(sad): Compute the color from the favicon.
90 return SK_ColorGRAY; 105 return SK_ColorGRAY;
91 } 106 }
92 107
93 base::string16 AppActivity::GetTitle() const { 108 base::string16 AppActivity::GetTitle() const {
94 return web_view_->GetWebContents()->GetTitle(); 109 return web_view_->GetWebContents()->GetTitle();
(...skipping 28 matching lines...) Expand all
123 void AppActivity::TitleWasSet(content::NavigationEntry* entry, 138 void AppActivity::TitleWasSet(content::NavigationEntry* entry,
124 bool explicit_set) { 139 bool explicit_set) {
125 ActivityManager::Get()->UpdateActivity(this); 140 ActivityManager::Get()->UpdateActivity(this);
126 } 141 }
127 142
128 void AppActivity::DidUpdateFaviconURL( 143 void AppActivity::DidUpdateFaviconURL(
129 const std::vector<content::FaviconURL>& candidates) { 144 const std::vector<content::FaviconURL>& candidates) {
130 ActivityManager::Get()->UpdateActivity(this); 145 ActivityManager::Get()->UpdateActivity(this);
131 } 146 }
132 147
148 void AppActivity::DidStartNavigationToPendingEntry(
149 const GURL& url,
150 content::NavigationController::ReloadType reload_type) {
151 if (!app_activity_registry_)
152 RegisterActivity();
153 }
154
155 // Register an |activity| with an application.
156 // Note: This should only get called once for an |app_window| of the
157 // |activity|.
158 void AppActivity::RegisterActivity() {
159 if (app_activity_registry_)
160 return;
161 content::WebContents* web_contents = app_window_->GetAssociatedWebContents();
162 AppRegistry* app_registry = AppRegistry::Get();
163 // Get the application's registry.
164 app_activity_registry_ = app_registry->GetAppActivityRegistry(
165 app_registry->GetDelegate()->GetExtensionID(web_contents),
166 web_contents->GetBrowserContext());
oshima 2014/08/18 23:14:02 looks like all information passed can be obtained
Mr4D (OOO till 08-26) 2014/08/19 14:21:10 This was done to allow unit tests to work. They ca
oshima 2014/08/19 21:22:24 Ok, I'm fine for now, but when we introduced the (
Mr4D (OOO till 08-26) 2014/08/20 14:34:39 Sure.
167 DCHECK(app_activity_registry_);
168 // Register the activity.
169 app_activity_registry_->RegisterAppActivity(this);
170 }
171
133 } // namespace athena 172 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698