Skip to content
This repository was archived by the owner on Oct 18, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ protected static Uri withSyncAndProfile(Uri u) {
public static final Uri DELETED_PASSWORDS_CONTENT_URI = withSyncAndDeletedAndProfile(DeletedPasswords.CONTENT_URI);
public static final Uri FORM_HISTORY_CONTENT_URI = withSyncAndProfile(FormHistory.CONTENT_URI);
public static final Uri DELETED_FORM_HISTORY_CONTENT_URI = withSyncAndProfile(DeletedFormHistory.CONTENT_URI);
public static final Uri TABS_CONTENT_URI = withSyncAndProfile(Tabs.CONTENT_URI);
public static final Uri CLIENTS_CONTENT_URI = withSyncAndProfile(Clients.CONTENT_URI);

public static final String[] PasswordColumns = new String[] {
Passwords.ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ protected void releaseProviders() {

public FennecTabsRepositorySession(Repository repository, Context context) throws NoContentProviderException {
super(repository);
clientsProvider = getContentProvider(context, BrowserContract.Clients.CONTENT_URI);
clientsProvider = getContentProvider(context, BrowserContractHelpers.CLIENTS_CONTENT_URI);
try {
tabsProvider = getContentProvider(context, BrowserContract.Tabs.CONTENT_URI);
tabsProvider = getContentProvider(context, BrowserContractHelpers.TABS_CONTENT_URI);
} catch (NoContentProviderException e) {
clientsProvider.release();
throw e;
Expand All @@ -85,7 +85,7 @@ public FennecTabsRepositorySession(Repository repository, Context context) throw
throw new RuntimeException(e);
}

tabsHelper = new RepoUtils.QueryHelper(context, BrowserContract.Tabs.CONTENT_URI, LOG_TAG);
tabsHelper = new RepoUtils.QueryHelper(context, BrowserContractHelpers.TABS_CONTENT_URI, LOG_TAG);
}

@Override
Expand Down Expand Up @@ -225,7 +225,7 @@ public void run() {
if (tabsRecord.deleted) {
try {
Logger.debug(LOG_TAG, "Clearing entry for client " + tabsRecord.guid);
clientsProvider.delete(BrowserContract.Clients.CONTENT_URI,
clientsProvider.delete(BrowserContractHelpers.CLIENTS_CONTENT_URI,
CLIENT_GUID_IS,
selectionArgs);
delegate.onRecordStoreSucceeded(record.guid);
Expand All @@ -239,20 +239,20 @@ public void run() {
final ContentValues clientsCV = tabsRecord.getClientsContentValues();

Logger.debug(LOG_TAG, "Updating clients provider.");
final int updated = clientsProvider.update(BrowserContract.Clients.CONTENT_URI,
final int updated = clientsProvider.update(BrowserContractHelpers.CLIENTS_CONTENT_URI,
clientsCV,
CLIENT_GUID_IS,
selectionArgs);
if (0 == updated) {
clientsProvider.insert(BrowserContract.Clients.CONTENT_URI, clientsCV);
clientsProvider.insert(BrowserContractHelpers.CLIENTS_CONTENT_URI, clientsCV);
}

// Now insert tabs.
final ContentValues[] tabsArray = tabsRecord.getTabsContentValues();
Logger.debug(LOG_TAG, "Inserting " + tabsArray.length + " tabs for client " + tabsRecord.guid);

tabsProvider.delete(BrowserContract.Tabs.CONTENT_URI, TABS_CLIENT_GUID_IS, selectionArgs);
final int inserted = tabsProvider.bulkInsert(BrowserContract.Tabs.CONTENT_URI, tabsArray);
tabsProvider.delete(BrowserContractHelpers.TABS_CONTENT_URI, TABS_CLIENT_GUID_IS, selectionArgs);
final int inserted = tabsProvider.bulkInsert(BrowserContractHelpers.TABS_CONTENT_URI, tabsArray);
Logger.trace(LOG_TAG, "Inserted: " + inserted);

delegate.onRecordStoreSucceeded(record.guid);
Expand All @@ -269,8 +269,8 @@ public void run() {
@Override
public void wipe(RepositorySessionWipeDelegate delegate) {
try {
tabsProvider.delete(BrowserContract.Tabs.CONTENT_URI, null, null);
clientsProvider.delete(BrowserContract.Clients.CONTENT_URI, null, null);
tabsProvider.delete(BrowserContractHelpers.TABS_CONTENT_URI, null, null);
clientsProvider.delete(BrowserContractHelpers.CLIENTS_CONTENT_URI, null, null);
} catch (RemoteException e) {
Logger.warn(LOG_TAG, "Got RemoteException in wipe.", e);
delegate.onWipeFailed(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.concurrent.Callable;

import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.db.BrowserContract.DeletedFormHistory;
import org.mozilla.gecko.db.BrowserContract.FormHistory;
import org.mozilla.gecko.sync.repositories.InactiveSessionException;
Expand Down Expand Up @@ -75,7 +76,7 @@ public void createSession(RepositorySessionCreationDelegate delegate,
*/
public static ContentProviderClient acquireContentProvider(final Context context)
throws NoContentProviderException {
Uri uri = FormHistory.CONTENT_URI;
Uri uri = BrowserContract.FORM_HISTORY_AUTHORITY_URI;
ContentProviderClient client = context.getContentResolver().acquireContentProviderClient(uri);
if (client == null) {
throw new NoContentProviderException(uri);
Expand Down Expand Up @@ -123,6 +124,7 @@ public void finish(final RepositorySessionFinishDelegate delegate)
@Override
public void guidsSince(final long timestamp, final RepositorySessionGuidsSinceDelegate delegate) {
Runnable command = new Runnable() {
@Override
public void run() {
if (!isActive()) {
delegate.onGuidsSinceFailed(new InactiveSessionException(null));
Expand Down Expand Up @@ -703,6 +705,7 @@ public static void purgeDatabases(ContentProviderClient formsProvider)
@Override
public void wipe(final RepositorySessionWipeDelegate delegate) {
Runnable command = new Runnable() {
@Override
public void run() {
if (!isActive()) {
delegate.onWipeFailed(new InactiveSessionException(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.sync.repositories.NoContentProviderException;
import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers;
import org.mozilla.gecko.sync.repositories.android.FennecTabsRepository;
import org.mozilla.gecko.sync.repositories.android.FennecTabsRepository.FennecTabsRepositorySession;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
Expand All @@ -34,13 +35,14 @@ public class TestFennecTabsRepositorySession extends AndroidSyncTestCase {

protected ContentProviderClient getTabsClient() {
final ContentResolver cr = getApplicationContext().getContentResolver();
return cr.acquireContentProviderClient(BrowserContract.Tabs.CONTENT_URI);
return cr.acquireContentProviderClient(BrowserContractHelpers.TABS_CONTENT_URI);
}

public TestFennecTabsRepositorySession() throws NoContentProviderException {
super();
}

@Override
public void setUp() {
if (tabsClient == null) {
tabsClient = getTabsClient();
Expand All @@ -51,10 +53,11 @@ protected int deleteAllTestTabs(final ContentProviderClient tabsClient) throws R
if (tabsClient == null) {
return -1;
}
return tabsClient.delete(BrowserContract.Tabs.CONTENT_URI,
return tabsClient.delete(BrowserContractHelpers.TABS_CONTENT_URI,
TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION, TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION_ARGS);
}

@Override
protected void tearDown() throws Exception {
if (tabsClient != null) {
deleteAllTestTabs(tabsClient);
Expand Down Expand Up @@ -148,9 +151,9 @@ private void insertSomeTestTabs(ContentProviderClient tabsClient) throws RemoteE
history3.add("http://test.com/test3.html#2");
testTab3 = new Tab("test title 3", "http://test.com/test3.png", history3, 3000);

tabsClient.insert(BrowserContract.Tabs.CONTENT_URI, testTab1.toContentValues(TEST_CLIENT_GUID, 0));
tabsClient.insert(BrowserContract.Tabs.CONTENT_URI, testTab2.toContentValues(TEST_CLIENT_GUID, 1));
tabsClient.insert(BrowserContract.Tabs.CONTENT_URI, testTab3.toContentValues(TEST_CLIENT_GUID, 2));
tabsClient.insert(BrowserContractHelpers.TABS_CONTENT_URI, testTab1.toContentValues(TEST_CLIENT_GUID, 0));
tabsClient.insert(BrowserContractHelpers.TABS_CONTENT_URI, testTab2.toContentValues(TEST_CLIENT_GUID, 1));
tabsClient.insert(BrowserContractHelpers.TABS_CONTENT_URI, testTab3.toContentValues(TEST_CLIENT_GUID, 2));
}

protected TabsRecord insertTestTabsAndExtractTabsRecord() throws RemoteException {
Expand All @@ -159,7 +162,7 @@ protected TabsRecord insertTestTabsAndExtractTabsRecord() throws RemoteException
final String positionAscending = BrowserContract.Tabs.POSITION + " ASC";
Cursor cursor = null;
try {
cursor = tabsClient.query(BrowserContract.Tabs.CONTENT_URI, null,
cursor = tabsClient.query(BrowserContractHelpers.TABS_CONTENT_URI, null,
TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION, TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION_ARGS, positionAscending);
CursorDumper.dumpCursor(cursor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import org.json.simple.JSONArray;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers;

import android.app.Activity;
import android.content.ContentProviderClient;
Expand Down Expand Up @@ -37,21 +38,22 @@ public TestFennecTabsStorage() {

protected ContentProviderClient getClientsClient() {
final ContentResolver cr = getInstrumentation().getTargetContext().getApplicationContext().getContentResolver();
return cr.acquireContentProviderClient(BrowserContract.Clients.CONTENT_URI);
return cr.acquireContentProviderClient(BrowserContractHelpers.CLIENTS_CONTENT_URI);
}

protected ContentProviderClient getTabsClient() {
final ContentResolver cr = getInstrumentation().getTargetContext().getApplicationContext().getContentResolver();
return cr.acquireContentProviderClient(BrowserContract.Tabs.CONTENT_URI);
return cr.acquireContentProviderClient(BrowserContractHelpers.TABS_CONTENT_URI);
}

protected int deleteAllTestTabs(final ContentProviderClient tabsClient) throws RemoteException {
if (tabsClient == null) {
return -1;
}
return tabsClient.delete(BrowserContract.Tabs.CONTENT_URI, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID });
return tabsClient.delete(BrowserContractHelpers.TABS_CONTENT_URI, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID });
}

@Override
protected void tearDown() throws Exception {
deleteAllTestTabs(getTabsClient());
}
Expand All @@ -73,9 +75,9 @@ protected void insertSomeTestTabs(ContentProviderClient tabsClient) throws Remot
history3.add("http://test.com/test3.html#2");
testTab3 = new Tab("test title 3", "http://test.com/test3.png", history3, 3000);

tabsClient.insert(BrowserContract.Tabs.CONTENT_URI, testTab1.toContentValues(TEST_CLIENT_GUID, 0));
tabsClient.insert(BrowserContract.Tabs.CONTENT_URI, testTab2.toContentValues(TEST_CLIENT_GUID, 1));
tabsClient.insert(BrowserContract.Tabs.CONTENT_URI, testTab3.toContentValues(TEST_CLIENT_GUID, 2));
tabsClient.insert(BrowserContractHelpers.TABS_CONTENT_URI, testTab1.toContentValues(TEST_CLIENT_GUID, 0));
tabsClient.insert(BrowserContractHelpers.TABS_CONTENT_URI, testTab2.toContentValues(TEST_CLIENT_GUID, 1));
tabsClient.insert(BrowserContractHelpers.TABS_CONTENT_URI, testTab3.toContentValues(TEST_CLIENT_GUID, 2));
}

// Sanity.
Expand All @@ -90,7 +92,7 @@ public void testObtainCP() {
}

public void testWipeClients() throws RemoteException {
final Uri uri = BrowserContract.Clients.CONTENT_URI;
final Uri uri = BrowserContractHelpers.CLIENTS_CONTENT_URI;
final ContentProviderClient clientsClient = getClientsClient();

// Have to ensure that it's empty…
Expand All @@ -111,7 +113,7 @@ public void testWipeTabs() throws RemoteException {
}

public void testStoreAndRetrieveClients() throws RemoteException {
final Uri uri = BrowserContract.Clients.CONTENT_URI;
final Uri uri = BrowserContractHelpers.CLIENTS_CONTENT_URI;
final ContentProviderClient clientsClient = getClientsClient();

// Have to ensure that it's empty…
Expand Down Expand Up @@ -174,7 +176,7 @@ public void testTabFromCursor() throws Exception {
final String positionAscending = BrowserContract.Tabs.POSITION + " ASC";
Cursor cursor = null;
try {
cursor = tabsClient.query(BrowserContract.Tabs.CONTENT_URI, null, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID }, positionAscending);
cursor = tabsClient.query(BrowserContractHelpers.TABS_CONTENT_URI, null, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID }, positionAscending);
assertEquals(3, cursor.getCount());

cursor.moveToFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.mozilla.gecko.background.db.CursorDumper;
import org.mozilla.gecko.background.db.TestFennecTabsStorage;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers;
import org.mozilla.gecko.sync.repositories.android.FennecTabsRepository;
import org.mozilla.gecko.sync.repositories.domain.TabsRecord;

Expand All @@ -22,7 +23,7 @@ public void testTabsRecordFromCursor() throws Exception {
final String positionAscending = BrowserContract.Tabs.POSITION + " ASC";
Cursor cursor = null;
try {
cursor = tabsClient.query(BrowserContract.Tabs.CONTENT_URI, null, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID }, positionAscending);
cursor = tabsClient.query(BrowserContractHelpers.TABS_CONTENT_URI, null, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID }, positionAscending);
assertEquals(3, cursor.getCount());

cursor.moveToPosition(1);
Expand Down Expand Up @@ -55,7 +56,7 @@ public void testEmptyTabsRecordFromCursor() throws Exception {
final String positionAscending = BrowserContract.Tabs.POSITION + " ASC";
Cursor cursor = null;
try {
cursor = tabsClient.query(BrowserContract.Tabs.CONTENT_URI, null, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID }, positionAscending);
cursor = tabsClient.query(BrowserContractHelpers.TABS_CONTENT_URI, null, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID }, positionAscending);
assertEquals(0, cursor.getCount());

final TabsRecord tabsRecord = FennecTabsRepository.tabsRecordFromCursor(cursor, TEST_CLIENT_GUID, TEST_CLIENT_NAME);
Expand All @@ -81,7 +82,7 @@ public void testLocalTabs() throws Exception {
Cursor cursor = null;
try {
// Keep this in sync with the Fennec schema.
cursor = tabsClient.query(BrowserContract.Tabs.CONTENT_URI, null, BrowserContract.Tabs.CLIENT_GUID + " IS NULL", null, positionAscending);
cursor = tabsClient.query(BrowserContractHelpers.TABS_CONTENT_URI, null, BrowserContract.Tabs.CLIENT_GUID + " IS NULL", null, positionAscending);
CursorDumper.dumpCursor(cursor);

final TabsRecord tabsRecord = FennecTabsRepository.tabsRecordFromCursor(cursor, TEST_CLIENT_GUID, TEST_CLIENT_NAME);
Expand Down