Browse files

Bug 740193 Part 7 - Pass Context and accountGUID to sendURIToClientFo…

…rDisplay() instead of registering a session.
  • Loading branch information...
1 parent 0c291a1 commit afb93173bfdd598c48dfa0f39b2edfb531e426f2 @emtwo emtwo committed Apr 17, 2012
View
23 src/main/java/org/mozilla/gecko/sync/CommandProcessor.java
@@ -27,7 +27,6 @@
public class CommandProcessor {
private static final String LOG_TAG = "Command";
private static AtomicInteger currentId = new AtomicInteger();
- private GlobalSession session;
protected ConcurrentHashMap<String, CommandRunner> commands = new ConcurrentHashMap<String, CommandRunner>();
private final static CommandProcessor processor = new CommandProcessor();
@@ -71,10 +70,6 @@ public void registerCommand(String commandType, CommandRunner command) {
commands.put(commandType, command);
}
- public void registerSession(GlobalSession session) {
- this.session = session;
- }
-
public void processCommand(ExtendedJSONObject unparsedCommand) {
Command command = parseCommand(unparsedCommand);
if (command == null) {
@@ -118,16 +113,16 @@ protected static Command parseCommand(ExtendedJSONObject unparsedCommand) {
}
@SuppressWarnings("unchecked")
- public void sendURIToClientForDisplay(String uri, String clientID, String title) {
+ public void sendURIToClientForDisplay(String uri, String clientID, String title, String sender, Context context) {
Logger.info(LOG_TAG, "Sending URI to client: " + uri + " -> " + clientID + " (" + title + ")");
JSONArray args = new JSONArray();
args.add(uri);
- args.add(session.getClientsDelegate().getAccountGUID());
+ args.add(sender);
args.add(title);
Command displayURICommand = new Command("displayURI", args);
- this.sendCommand(clientID, displayURICommand);
+ this.sendCommand(clientID, displayURICommand, context);
}
/**
@@ -143,7 +138,7 @@ public void sendURIToClientForDisplay(String uri, String clientID, String title)
* @param command
* Command to invoke on remote clients
*/
- public void sendCommand(String clientID, Command command) {
+ public void sendCommand(String clientID, Command command, Context context) {
Logger.debug(LOG_TAG, "In sendCommand.");
CommandRunner commandData = commands.get(command.commandType);
@@ -162,15 +157,15 @@ public void sendCommand(String clientID, Command command) {
}
if (clientID != null) {
- this.sendCommandToClient(clientID, command);
+ this.sendCommandToClient(clientID, command, context);
return;
}
- ClientsDatabaseAccessor db = new ClientsDatabaseAccessor(session.getContext());
+ ClientsDatabaseAccessor db = new ClientsDatabaseAccessor(context);
try {
Map<String, ClientRecord> clientMap = db.fetchAllClients();
for (ClientRecord client : clientMap.values()) {
- this.sendCommandToClient(client.guid, command);
+ this.sendCommandToClient(client.guid, command, context);
}
} catch (NullCursorException e) {
Logger.error(LOG_TAG, "NullCursorException when fetching all GUIDs");
@@ -179,10 +174,10 @@ public void sendCommand(String clientID, Command command) {
}
}
- protected void sendCommandToClient(String clientID, Command command) {
+ protected void sendCommandToClient(String clientID, Command command, Context context) {
Logger.info(LOG_TAG, "Sending " + command.commandType + " to " + clientID);
- ClientsDatabaseAccessor db = new ClientsDatabaseAccessor(session.getContext());
+ ClientsDatabaseAccessor db = new ClientsDatabaseAccessor(context);
try {
db.store(clientID, command);
} catch (NullCursorException e) {
View
1 src/main/java/org/mozilla/gecko/sync/GlobalSession.java
@@ -156,7 +156,6 @@ public GlobalSession(String userAPI,
protected void registerCommands() {
final CommandProcessor processor = CommandProcessor.getProcessor();
- processor.registerSession(this);
processor.registerCommand("resetEngine", new CommandRunner(1) {
@Override
View
20 src/main/java/org/mozilla/gecko/sync/setup/activities/SendTabActivity.java
@@ -23,6 +23,8 @@
public static final String LOG_TAG = "SendTabActivity";
private ListView listview;
private ClientRecordArrayAdapter arrayAdapter;
+ private AccountManager accountManager;
+ private Account localAccount;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -49,11 +51,12 @@ public void onResume() {
}
private void redirectIfNoSyncAccount() {
- AccountManager mAccountManager = AccountManager.get(getApplicationContext());
- Account[] accts = mAccountManager.getAccountsByType(Constants.ACCOUNTTYPE_SYNC);
+ accountManager = AccountManager.get(getApplicationContext());
+ Account[] accts = accountManager.getAccountsByType(Constants.ACCOUNTTYPE_SYNC);
// A Sync account exists.
if (accts.length > 0) {
+ localAccount = accts[0];
return;
}
@@ -63,6 +66,16 @@ private void redirectIfNoSyncAccount() {
finish();
}
+ /**
+ * @return Return null if there is no account set up. Return the account GUID otherwise.
+ */
+ private String getAccountGUID() {
+ if (accountManager == null || localAccount == null) {
+ return null;
+ }
+ return accountManager.getUserData(localAccount, Constants.ACCOUNT_GUID);
+ }
+
public void sendClickHandler(View view) {
Logger.info(LOG_TAG, "Send was clicked.");
Bundle extras = this.getIntent().getExtras();
@@ -77,7 +90,7 @@ public void sendClickHandler(View view) {
@Override
public void run() {
for (int i = 0; i < guids.length; i++) {
- processor.sendURIToClientForDisplay(uri, guids[i], title);
+ processor.sendURIToClientForDisplay(uri, guids[i], title, getAccountGUID(), getApplicationContext());
}
}
}.start();
@@ -99,7 +112,6 @@ public void onClick(View v) {
});
dialog.show();
- //dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, android.R.drawable.ic_menu_send);
}
public void enableSend(boolean shouldEnable) {

0 comments on commit afb9317

Please sign in to comment.