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

Unified Diff: athena/content/web_activity.cc

Issue 358003002: Additions to Activities to allow resource management (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
« athena/activity/public/activity.h ('K') | « athena/content/web_activity.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: athena/content/web_activity.cc
diff --git a/athena/content/web_activity.cc b/athena/content/web_activity.cc
index 0385b47460f797f543e033690cf7167da9d038b9..afaa52c2a0f3155a0028c9b9b84da851dc1d486c 100644
--- a/athena/content/web_activity.cc
+++ b/athena/content/web_activity.cc
@@ -116,15 +116,54 @@ class WebActivityController : public AcceleratorHandler {
DISALLOW_COPY_AND_ASSIGN(WebActivityController);
};
-// A web view for athena's web activity.
+// A web view for athena's web activity. Note that AthenaWebView will create its
+// own content so that it can eject and reload it.
class AthenaWebView : public views::WebView {
public:
AthenaWebView(content::BrowserContext* context)
- : views::WebView(context), controller_(new WebActivityController(this)) {}
- virtual ~AthenaWebView() {}
+ : views::WebView(context), controller_(new WebActivityController(this)) {
+ // We create the first web contents ourselves to allow us to replace it
+ // later on.
+ SetWebContents(WebContents::Create(WebContents::CreateParams(context)));
+ // TODO(skuhne): Add content observer to detect renderer crash and set
+ // content status to unloaded if that happens.
+ }
+ virtual ~AthenaWebView() {
+ // |WebView| does not own the content, so we need to destroy it here.
+ WebContents* current_contents = web_view_->GetWebContents();
+ web_view_->SetWebContents(NULL);
+ delete current_contents;
+ }
void InstallAccelerators() { controller_->InstallAccelerators(); }
+ void EvictContent() {
+ WebContents* old_contents = GetWebContents();
+ evicted_web_contents_.reset(
+ WebContents::Create(WebContents::CreateParams(
+ old_contents->profile())));
+ evicted_web_contents_->GetController().CopyStateFrom(
+ old_contents->GetController());
+ SetContents(WebContents::Create(WebContents::CreateParams(
+ old_contents->profile())));
+ delete old_contents;
+ // As soon as the new contents becomes visible, it should reload.
+ // TODO(skuhne): This breaks script connections with other activities.
+ // Even though this is the same technique as used by the TabStripModel,
+ // we might want to address this cleaner since we are more likely to
+ // run into this state. by unloading.
+ }
+
+ void ReloadContent() {
+ CHECK(evicted_web_contents_.get());
+ WebContents* null_contents = GetWebContents();
+ SetContents(evicted_web_contents_.release());
+ delete null_contents;
+ }
+
+ // Check if the content got evicted.
+ bool IsContentEvicted() { return !evicted_web_contents_.get(); }
+
private:
// WebContentsDelegate:
virtual bool PreHandleKeyboardEvent(
@@ -143,6 +182,11 @@ class AthenaWebView : public views::WebView {
scoped_ptr<WebActivityController> controller_;
+ // If the activity got evicted, this is the web content which holds the known
+ // state of the content before eviction.
+ scoped_ptr<content::WebContents> evicted_web_contents_;
+
+
DISALLOW_COPY_AND_ASSIGN(AthenaWebView);
};
@@ -150,19 +194,84 @@ class AthenaWebView : public views::WebView {
WebActivity::WebActivity(content::BrowserContext* browser_context,
const GURL& url)
- : browser_context_(browser_context), url_(url), web_view_(NULL) {
+ : browser_context_(browser_context),
+ url_(url),
+ web_view_(NULL),
+ last_requested_state_(ACTIVITY_UNLOAD) {
}
WebActivity::~WebActivity() {
+ // It is not required to change the activity state to UNLOADED - unless we
+ // would add state observers.
}
ActivityViewModel* WebActivity::GetActivityViewModel() {
return this;
}
+void WebActivity::SetCurrentState(ActivityStateTranstion state) {
+ switch (state) {
+ case ACTIVITY_LOAD:
+ // By clearing the overview mode image we allow the content to be shown.
+ overview_mode_image_ = gfx::ImageSkia();
+ if (web_view_->IsContentEvicted()) {
+ DCHECK_EQ(ACTIVITY_UNLOAD, last_requested_state_);
+ web_view_->ReloadContent();
+ }
+ Observe(web_view_->GetWebContents());
+ break;
+ case ACTIVITY_DEEP_SLEEP_1:
+ DCHECK_EQ(ACTIVITY_LOAD, last_requested_state_);
+ // TODO(skuhne): Do this. As soon as the new resource management is
+ // agreed upon - or remove otherwise.
+ break;
+ case ACTIVITY_DEEP_SLEEP_2:
+ DCHECK_EQ(ACTIVITY_DEEP_SLEEP_1, last_requested_state_);
+ // TODO(skuhne): Do this. As soon as the new resource management is
+ // agreed upon - or remove otherwise.
+ break;
+ case ACTIVITY_UNLOAD:
+ DCHECK_NE(ACTIVITY_UNLOAD, last_requested_state_);
+ Observe(NULL);
+ web_view_->EvictContent();
Jun Mukai 2014/06/26 19:48:01 Can we just discard web_view_ itself instead of im
Mr4D (OOO till 08-26) 2014/06/26 20:25:39 Well... WebView is used by another instance (the o
Jun Mukai 2014/06/26 21:45:26 Okay, doing the same approach as TabModel sounds p
+ break;
+ }
+ // Remember the last requested state.
+ last_requested_state_ = state;
+}
+
+ActivityState WebActivity::GetCurrentState() {
+ if (!web_view_ || web_view_->IsContentEvicted()) {
+ DCHECK_EQ(ACTIVITY_UNLOAD, last_requested_state_);
+ return ACTIVITY_STATE_UNLOADED;
+ }
+
+ switch(last_requested_state_) {
+ case ACTIVITY_LOAD:
+ if (web_view_->IsDrawn())
+ return ACTIVITY_STATE_VISIBLE;
+ /*
+ // TODO(skuhne): AudioStreamMonitor is currently a part of Chrome and
+ // needs to be moved some levels up.
+ WebContents* contents = web_view_->
+ AudioStreamMonitor* const audio_stream_monitor =
+ AudioStreamMonitor::FromWebContents(contents);
+ if (audio_stream_monitor && audio_stream_monitor->WasRecentlyAudible())
+ return ACTIVITY_STATE_ACTIVE;
+ */
+ return ACTIVITY_STATE_HIDDEN;
+ case ACTIVITY_DEEP_SLEEP_1:
+ return ACTIVITY_DEEP_SLEEP_1;
+ case ACTIVITY_DEEP_SLEEP_2:
+ return ACTIVITY_DEEP_SLEEP_2;
+ case ACTIVITY_UNLOAD:
+ return ACTIVITY_STATE_UNLOADED;
+ }
+}
+
void WebActivity::Init() {
DCHECK(web_view_);
- static_cast<AthenaWebView*>(web_view_)->InstallAccelerators();
+ web_view_->InstallAccelerators();
}
SkColor WebActivity::GetRepresentativeColor() {
@@ -178,7 +287,9 @@ views::View* WebActivity::GetContentsView() {
if (!web_view_) {
web_view_ = new AthenaWebView(browser_context_);
web_view_->LoadInitialURL(url_);
- Observe(web_view_->GetWebContents());
+ SetCurrentState(ACTIVITY_LOAD);
+ // Reset the overview mode image.
+ overview_mode_image_ = gfx::ImageSkia();
}
return web_view_;
}
« athena/activity/public/activity.h ('K') | « athena/content/web_activity.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698