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

Unified Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/webapps/WebappManagedActivity.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 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
Index: chrome/android/java_staging/src/org/chromium/chrome/browser/webapps/WebappManagedActivity.java
diff --git a/chrome/android/java_staging/src/org/chromium/chrome/browser/webapps/WebappManagedActivity.java b/chrome/android/java_staging/src/org/chromium/chrome/browser/webapps/WebappManagedActivity.java
new file mode 100644
index 0000000000000000000000000000000000000000..13798645afd2f6e947b93ad1d0c87495ef619cf3
--- /dev/null
+++ b/chrome/android/java_staging/src/org/chromium/chrome/browser/webapps/WebappManagedActivity.java
@@ -0,0 +1,56 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.webapps;
+
+import java.io.File;
+
+/**
+ * Type of WebappActivity that has the ability to swap out the webapp it is currently showing for a
+ * new one. This is necessary on Android versions older than L because the framework had no way of
+ * allowing multiple instances of an Activity to be launched and show up as different tasks.
+ * Anything extending this class must be named WebappActivity0, WebappActivity1, etc.
+ */
+public abstract class WebappManagedActivity extends WebappActivity {
+ private final int mActivityIndex;
+
+ public WebappManagedActivity() {
+ mActivityIndex = getActivityIndex();
+ }
+
+ @Override
+ public void onStartWithNative() {
+ super.onStartWithNative();
+
+ if (!isFinishing()) {
+ markActivityUsed();
+ }
+ }
+
+ @Override
+ protected File getActivityDirectory() {
+ return WebappDirectoryManager.getWebappDirectory(String.valueOf(mActivityIndex));
+ }
+
+ /**
+ * Marks that this WebappActivity is recently used to prevent other webapps from using it.
+ */
+ private void markActivityUsed() {
+ ActivityAssigner.instance(this).markActivityUsed(mActivityIndex, getWebappInfo().id());
+ }
+
+ /**
+ * Pulls out the index of the WebappActivity subclass that is being used.
+ * e.g. WebappActivity0.getActivityIndex() will return 0.
+ * @return The index corresponding to this WebappActivity.
+ */
+ private int getActivityIndex() {
+ // Cull out the activity index from the class name.
+ String baseClassName = WebappActivity.class.getSimpleName();
+ String className = this.getClass().getSimpleName();
+ assert className.matches("^" + baseClassName + "[0-9]+$");
+ String indexString = className.substring(baseClassName.length());
+ return Integer.parseInt(indexString);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698