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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 package org.chromium.chrome.browser.webapps;
6
7 import java.io.File;
8
9 /**
10 * Type of WebappActivity that has the ability to swap out the webapp it is curr ently showing for a
11 * new one. This is necessary on Android versions older than L because the frame work had no way of
12 * allowing multiple instances of an Activity to be launched and show up as diff erent tasks.
13 * Anything extending this class must be named WebappActivity0, WebappActivity1, etc.
14 */
15 public abstract class WebappManagedActivity extends WebappActivity {
16 private final int mActivityIndex;
17
18 public WebappManagedActivity() {
19 mActivityIndex = getActivityIndex();
20 }
21
22 @Override
23 public void onStartWithNative() {
24 super.onStartWithNative();
25
26 if (!isFinishing()) {
27 markActivityUsed();
28 }
29 }
30
31 @Override
32 protected File getActivityDirectory() {
33 return WebappDirectoryManager.getWebappDirectory(String.valueOf(mActivit yIndex));
34 }
35
36 /**
37 * Marks that this WebappActivity is recently used to prevent other webapps from using it.
38 */
39 private void markActivityUsed() {
40 ActivityAssigner.instance(this).markActivityUsed(mActivityIndex, getWeba ppInfo().id());
41 }
42
43 /**
44 * Pulls out the index of the WebappActivity subclass that is being used.
45 * e.g. WebappActivity0.getActivityIndex() will return 0.
46 * @return The index corresponding to this WebappActivity.
47 */
48 private int getActivityIndex() {
49 // Cull out the activity index from the class name.
50 String baseClassName = WebappActivity.class.getSimpleName();
51 String className = this.getClass().getSimpleName();
52 assert className.matches("^" + baseClassName + "[0-9]+$");
53 String indexString = className.substring(baseClassName.length());
54 return Integer.parseInt(indexString);
55 }
56 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698