Skip to content

Commit

Permalink
Move some DocumentTabModel files upstream
Browse files Browse the repository at this point in the history
* Moves the DocumentTabModel interface upstream.

* Moves the DocumentTabModelInfo protobuf that stores basic
  info about a DocumentTabModel upstream.  Formerly called
  DocumentDatabase.

* Temporarily adds findbugs warnings until the DocumentTabModelImpl moves upstream.

BUG=415747
NOTRY=true

Review URL: https://codereview.chromium.org/796633002

Cr-Commit-Position: refs/heads/master@{#307952}
  • Loading branch information
dfalcantara authored and Commit bot committed Dec 11, 2014
1 parent 289d5fc commit 0dd63b3
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 0 deletions.
7 changes: 7 additions & 0 deletions build/android/findbugs_filter/findbugs_known_bugs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ M M LI: Incorrect lazy initialization of static field org.chromium.chrome.browse
M V EI2: org.chromium.content_public.browser.LoadUrlParams.setPostData(byte[]) may expose internal representation by storing an externally mutable object into LoadUrlParams.mPostData At LoadUrlParams.java
M V EI: org.chromium.content_public.browser.LoadUrlParams.getPostData() may expose internal representation by returning LoadUrlParams.mPostData At LoadUrlParams.java
M V EI2: org.chromium.net.ChromiumUrlRequest.setUploadData(String, byte[]) may expose internal representation by storing an externally mutable object into ChromiumUrlRequest.mUploadData At ChromiumUrlRequest.java
M D UrF: Unread public/protected field: org.chromium.chrome.browser.tabmodel.document.DocumentTabModel$Entry.initialUrl At DocumentTabModel.java
M D UrF: Unread public/protected field: org.chromium.chrome.browser.tabmodel.document.DocumentTabModel$Entry.isTabStateReady At DocumentTabModel.java
M D UrF: Unread public/protected field: org.chromium.chrome.browser.tabmodel.document.DocumentTabModel$Entry.tabState At DocumentTabModel.java
M D UuF: Unused public or protected field: org.chromium.chrome.browser.tabmodel.document.DocumentTabModel$Entry.canGoBack In DocumentTabModel.java
M D UuF: Unused public or protected field: org.chromium.chrome.browser.tabmodel.document.DocumentTabModel$Entry.currentUrl In DocumentTabModel.java
M D UuF: Unused public or protected field: org.chromium.chrome.browser.tabmodel.document.DocumentTabModel$Entry.isDirty In DocumentTabModel.java
M D UuF: Unused public or protected field: org.chromium.chrome.browser.tabmodel.document.DocumentTabModel$Entry.placeholderTab In DocumentTabModel.java
9 changes: 9 additions & 0 deletions chrome/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ java_strings_grd("chrome_strings_grd") {
android_library("chrome_java") {
deps = [
":chrome_java_resources",
":document_tab_model_info_proto_java",
"//base:base_java",
"//net/android:net_java",
"//components/bookmarks/common/android:bookmarks_java",
Expand Down Expand Up @@ -145,6 +146,14 @@ java_cpp_template("app_banner_metrics_ids_javagen") {
]
}

# GYP: //chrome/chrome_browser.gypi:document_tab_model_info_proto_java
proto_java_library("document_tab_model_info_proto_java") {
proto_path = "java/src/org/chromium/chrome/browser/tabmodel/document"
sources = [
"$proto_path/document_tab_model_info.proto",
]
}

# GYP: //chrome/chrome_browser.gypi:resource_id_java
java_cpp_template("resource_id_javagen") {
sources = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
// Copyright 2014 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.tabmodel.document;

import android.content.Intent;

import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.Tab;
import org.chromium.chrome.browser.TabState;
import org.chromium.chrome.browser.tabmodel.TabModel;

/**
* Extends the regular TabModel interface so that it can be aware of, and work with, Android's
* Recents menu.
*/
public interface DocumentTabModel extends TabModel {
/** Stores information about a DocumentActivity. */
public static final class Entry {
public final int tabId;
public boolean canGoBack;
public String initialUrl;
public String currentUrl;
public TabState tabState;
public boolean isTabStateReady;
public boolean isDirty;
public Tab placeholderTab;

public Entry(int tabId) {
this.tabId = tabId;
}

public Entry(int tabId, String initialUrl) {
this.tabId = tabId;
this.initialUrl = initialUrl;
}

public Entry(int tabId, TabState tabState) {
this.tabId = tabId;
this.tabState = tabState;
this.isTabStateReady = true;
}
}

/**
* Delays an action until the TabList initialization has reached a certain state.
* Adds itself to the Observer list if the TabList is not ready, and is automatically removed
* once its run condition is satisfied and the action is run.
*/
public abstract static class InitializationObserver {
private final DocumentTabModel mTabModel;

public InitializationObserver(DocumentTabModel tabModel) {
mTabModel = tabModel;
}

/** @return Whether or not the TabList is initialized enough for the observer to run. */
public abstract boolean isSatisfied(int currentState);

/** @return Whether or not the Activity owning the observer has died. */
public abstract boolean isCanceled();

/** Perform whatever action the observer is waiting for. */
protected abstract void runImmediately();

/** Perform the action if the TabList is ready, or observe the TabList until it is. */
public final void runWhenReady() {
ThreadUtils.assertOnUiThread();
if (isSatisfied(mTabModel.getCurrentInitializationStage())) {
runImmediately();
} else {
mTabModel.addInitializationObserver(this);
}
}
}

/**
* Begin setting up the C++-side counterpart to this class.
*/
void initializeNative();

/**
* @return Whether the native-side pointer has been initialized.
*/
boolean isNativeInitialized();

/**
* Returns the initial URL for the Document with the given ID.
* @param tabId The ID for the document to return the url for.
* @return The initial URL for the entry if it was found, null otherwise.
*/
String getInitialUrlForDocument(int tabId);

/**
* Returns the current URL for the Document with the given ID.
* @param tabId The ID for the document to return the url for.
* @return The current URL for the entry if it was found, null otherwise.
*/
String getCurrentUrlForDocument(int tabId);

/**
* Returns whether or not an attempt to restore the TabState for the given tab ID has finished.
* @param tabId The ID for the document.
* @return Whether or not an attempt to restore the tab state has finished, or true if there
* is no Entry with the given ID.
*/
boolean isTabStateReady(int tabId);

/**
* Returns the tab state for the given file, loading it from disk if necessary.
* @param tabId ID of the tab to restore.
* @return TabState if it exists, null otherwise.
*/
TabState getTabStateForDocument(int tabId);

/**
* Checks whether or not there is an Entry for the given Tab.
* @param tabId ID of the tab to check for.
* @return Whether or not the Entry exists.
*/
boolean hasEntryForTabId(int tabId);

/**
* Check if a tab/task may be retargeted by an Intent.
* @param tabId ID of the tab.
* @return Whether or not the given tab ID may be retargeted.
*/
boolean isRetargetable(int tabId);

/**
* Closes the Tab at a particular index.
* @param index Index of the tab to close.
* @return Whether the was successfully closed.
*/
@VisibleForTesting
boolean closeTabAt(int index);

/**
* Compares the current list of documents from the system to the internal entry map and creates
* historical tabs for entries that exist in the internal map and not in the system database.
* Those entries are then removed from the internal list to ensure there will be only one
* recently closed tab per entry.
*/
void updateRecentlyClosed();

/**
* Updates an entry in the TabModel.
* @param intent Intent of the Activity that is modifying the TabModel.
* @param tab Tab being updated.
*/
void updateEntry(Intent intent, Tab tab);

/**
* Adds the given Tab to this TabModel.
* @param tab Tab to add.
*/
void addTab(Tab tab);

/**
* @return The stage of initialization that the DocumentTabModel is currently going through.
*/
int getCurrentInitializationStage();

/**
* Adds an InitializationObserver to the DocumentTabModel.
*/
void addInitializationObserver(InitializationObserver observer);

/**
* Records the ID of the last shown Tab.
* @param id ID of the last shown Tab.
*/
void setLastShownId(int id);

/**
* Called to begin loading tab state from disk. It will load the prioritized tab first
* synchronously and then the rest of the tabs asynchronously in the background.
*/
void startTabStateLoad();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2014 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.
//
// Protocol buffer definition for a database of DocumentActivity state.

syntax = "proto2";

package org.chromium.chrome.browser.tabmodel.document;

option java_outer_classname = "DocumentTabModelInfo";
option java_package = "org.chromium.chrome.browser.tabmodel.document";

message DocumentEntry {
// Next ID to use: 6
optional bool can_go_back = 4;
required int32 tab_id = 5;
}

message DocumentList {
// Next ID to use: 2
repeated DocumentEntry entries = 1;
}
14 changes: 14 additions & 0 deletions chrome/chrome_browser.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -3704,6 +3704,20 @@
},
'includes': [ '../build/android/java_cpp_enum.gypi' ],
},
{
# Protobuf compiler / generator for Android's DocumentTabModel
# protocol buffer.
# GN: //chrome/android: document_tab_model_info_proto_java
'target_name': 'document_tab_model_info_proto_java',
'type': 'none',
'variables': {
'proto_in_dir': 'android/java/src/org/chromium/chrome/browser/tabmodel/document',
},
'sources': [
'<(proto_in_dir)/document_tab_model_info.proto',
],
'includes': ['../build/protoc_java.gypi'],
},
],
},],
['enable_extensions==1', {
Expand Down

0 comments on commit 0dd63b3

Please sign in to comment.