Add --target-dir argument to deploy_chrome.

This allows specifying custom directory on device to deploy chrome into.

BUG=none
TEST=Manual deployment to a custom target dir, deploy_chrome_unittest.

Change-Id: I5bb374e188c18d5780a055052e721d7ef8f13a84
Reviewed-on: https://gerrit.chromium.org/gerrit/44561
Reviewed-by: David James <davidjames@chromium.org>
Reviewed-by: Ryan Cui <rcui@chromium.org>
Tested-by: Pawel Osciak <posciak@chromium.org>
Commit-Queue: Pawel Osciak <posciak@chromium.org>
diff --git a/scripts/deploy_chrome.py b/scripts/deploy_chrome.py
index f162053..147c340 100644
--- a/scripts/deploy_chrome.py
+++ b/scripts/deploy_chrome.py
@@ -46,7 +46,7 @@
 POST_KILL_WAIT = 2
 
 MOUNT_RW_COMMAND = 'mount -o remount,rw /'
-LSOF_COMMAND = 'lsof /opt/google/chrome/chrome'
+LSOF_COMMAND = 'lsof %s/chrome'
 
 _CHROME_DIR = '/opt/google/chrome'
 
@@ -77,7 +77,8 @@
     self._rootfs_is_still_readonly = multiprocessing.Event()
 
   def _ChromeFileInUse(self):
-    result = self.host.RemoteSh(LSOF_COMMAND, error_code_ok=True)
+    result = self.host.RemoteSh(LSOF_COMMAND % (self.options.target_dir,),
+                                error_code_ok=True)
     return result.returncode == 0
 
   def _DisableRootfsVerification(self):
@@ -165,9 +166,10 @@
       self._rootfs_is_still_readonly.set()
 
   def _Deploy(self):
-    logging.info('Copying Chrome to device...')
+    logging.info('Copying Chrome to %s on device...', self.options.target_dir)
     # Show the output (status) for this command.
-    self.host.Rsync('%s/' % os.path.abspath(self.staging_dir), _CHROME_DIR,
+    self.host.Rsync('%s/' % os.path.abspath(self.staging_dir),
+                    self.options.target_dir,
                     inplace=True, debug_level=logging.INFO,
                     verbose=self.options.verbose)
     if self.options.startui:
@@ -239,6 +241,9 @@
                          'from.  Typically of format <chrome_root>/out/Debug. '
                          'When this option is used, the GYP_DEFINES '
                          'environment variable must be set.')
+  parser.add_option('--target-dir', type='path',
+                    help='Target directory on device to deploy Chrome into.',
+                    default=_CHROME_DIR)
   parser.add_option('-g', '--gs-path', type='gs_path',
                     help='GS path that contains the chrome to deploy.')
   parser.add_option('--nostartui', action='store_false', dest='startui',