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

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

Issue 358003002: Additions to Activities to allow resource management (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changed Created 6 years, 5 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 "apps/shell/browser/shell_app_window.h" 7 #include "apps/shell/browser/shell_app_window.h"
8 #include "athena/activity/public/activity_manager.h" 8 #include "athena/activity/public/activity_manager.h"
9 #include "content/public/browser/web_contents.h" 9 #include "content/public/browser/web_contents.h"
10 #include "ui/views/controls/webview/webview.h" 10 #include "ui/views/controls/webview/webview.h"
11 11
12 namespace athena { 12 namespace athena {
13 13
14 // TODO(mukai): specifies the same accelerators of WebActivity. 14 // TODO(mukai): specifies the same accelerators of WebActivity.
15 AppActivity::AppActivity(apps::ShellAppWindow* app_window) 15 AppActivity::AppActivity(apps::ShellAppWindow* app_window)
16 : app_window_(app_window), web_view_(NULL) { 16 : app_window_(app_window),
17 web_view_(NULL),
18 current_state_(ACTIVITY_UNLOADED) {
17 DCHECK(app_window_); 19 DCHECK(app_window_);
18 } 20 }
19 21
20 AppActivity::~AppActivity() { 22 AppActivity::~AppActivity() {
23 if (GetCurrentState() != ACTIVITY_UNLOADED)
24 SetCurrentState(ACTIVITY_UNLOADED);
21 } 25 }
22 26
23 ActivityViewModel* AppActivity::GetActivityViewModel() { 27 ActivityViewModel* AppActivity::GetActivityViewModel() {
24 return this; 28 return this;
25 } 29 }
26 30
31 void AppActivity::SetCurrentState(Activity::ActivityState state) {
32 switch (state) {
33 case ACTIVITY_VISIBLE:
34 // Fall through (for the moment).
35 case ACTIVITY_INVISIBLE:
36 // By clearing the overview mode image we allow the content to be shown.
37 overview_mode_image_ = gfx::ImageSkia();
38 // TODO(skuhne): Find out how to reload an app from the extension system.
39 // If this does not work, the eviction needs to take place at a higher level.
oshima 2014/07/11 23:45:44 indent. please remove the commented out code. you
Mr4D (OOO till 08-26) 2014/07/12 01:38:38 Done.
40 // if (web_view_->IsContentEvicted()) {
41 // DCHECK_EQ(ACTIVITY_UNLOAD, last_requested_state_);
42 // web_view_->ReloadContent();
43 // }
44 break;
45 case ACTIVITY_BACKGROUND_LOW_PRIORITY:
46 DCHECK(ACTIVITY_VISIBLE == current_state_ ||
47 ACTIVITY_INVISIBLE == current_state_);
48 // TODO(skuhne): Do this.
49 break;
50 case ACTIVITY_PERSISTENT:
51 DCHECK_EQ(ACTIVITY_BACKGROUND_LOW_PRIORITY, current_state_);
52 // TODO(skuhne): Do this.
53 break;
54 case ACTIVITY_UNLOADED:
55 DCHECK_NE(ACTIVITY_UNLOADED, current_state_);
56 // TODO(skuhne): Find out how to evict an app from the extension system.
57 // web_view_->EvictContent();
58 break;
59 }
60 // Remember the last requested state.
61 current_state_ = state;
62 }
63
64 Activity::ActivityState AppActivity::GetCurrentState() {
65 // TODO(skuhne): Check here also eviction status.
66 if (!web_view_) {
67 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_);
68 return ACTIVITY_UNLOADED;
69 }
70 // TODO(skuhne): This should be controlled by an observer and should not
71 // reside here.
72 if (IsVisible() && current_state_ != ACTIVITY_VISIBLE)
73 SetCurrentState(ACTIVITY_VISIBLE);
74 // Note: If the activity is not visible it does not necessarily mean that it
75 // does not have GPU compositor resources (yet).
76 return current_state_;
77 }
78
79 bool AppActivity::IsVisible() {
80 return web_view_ && web_view_->IsDrawn();
81 }
82
83 Activity::ActivityMediaState AppActivity::GetMediaState() {
84 // TODO(skuhne): The function GetTabMediaStateForContents(WebContents),
85 // and the AudioStreamMonitor needs to be moved from Chrome into contents to
86 // make it more modular and so that we can use it from here.
87 return Activity::ACTIVITY_MEDIA_STATE_NONE;
88 }
89
27 void AppActivity::Init() { 90 void AppActivity::Init() {
28 } 91 }
29 92
30 SkColor AppActivity::GetRepresentativeColor() const { 93 SkColor AppActivity::GetRepresentativeColor() const {
31 // TODO(sad): Compute the color from the favicon. 94 // TODO(sad): Compute the color from the favicon.
32 return SK_ColorGRAY; 95 return SK_ColorGRAY;
33 } 96 }
34 97
35 base::string16 AppActivity::GetTitle() const { 98 base::string16 AppActivity::GetTitle() const {
36 return web_view_->GetWebContents()->GetTitle(); 99 return web_view_->GetWebContents()->GetTitle();
37 } 100 }
38 101
39 bool AppActivity::UsesFrame() const { 102 bool AppActivity::UsesFrame() const {
40 return false; 103 return false;
41 } 104 }
42 105
43 views::View* AppActivity::GetContentsView() { 106 views::View* AppActivity::GetContentsView() {
44 if (!web_view_) { 107 if (!web_view_) {
45 // TODO(oshima): use apps::NativeAppWindowViews 108 // TODO(oshima): use apps::NativeAppWindowViews
46 content::WebContents* web_contents = 109 content::WebContents* web_contents =
47 app_window_->GetAssociatedWebContents(); 110 app_window_->GetAssociatedWebContents();
48 web_view_ = new views::WebView(web_contents->GetBrowserContext()); 111 web_view_ = new views::WebView(web_contents->GetBrowserContext());
49 web_view_->SetWebContents(web_contents); 112 web_view_->SetWebContents(web_contents);
113 SetCurrentState(ACTIVITY_INVISIBLE);
50 Observe(web_contents); 114 Observe(web_contents);
115 overview_mode_image_ = gfx::ImageSkia();
51 } 116 }
52 return web_view_; 117 return web_view_;
53 } 118 }
54 119
120 void AppActivity::CreateOverviewModeImage() {
121 // TODO(skuhne): Implement this!
122 }
123
124 gfx::ImageSkia AppActivity::GetOverviewModeImage() {
125 return overview_mode_image_;
126 }
127
55 void AppActivity::TitleWasSet(content::NavigationEntry* entry, 128 void AppActivity::TitleWasSet(content::NavigationEntry* entry,
56 bool explicit_set) { 129 bool explicit_set) {
57 ActivityManager::Get()->UpdateActivity(this); 130 ActivityManager::Get()->UpdateActivity(this);
58 } 131 }
59 132
60 void AppActivity::DidUpdateFaviconURL( 133 void AppActivity::DidUpdateFaviconURL(
61 const std::vector<content::FaviconURL>& candidates) { 134 const std::vector<content::FaviconURL>& candidates) {
62 ActivityManager::Get()->UpdateActivity(this); 135 ActivityManager::Get()->UpdateActivity(this);
63 } 136 }
64 137
65 } // namespace athena 138 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698