Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / component_updater / recovery_component_installer.cc
index bcf9aea..4baa366 100644 (file)
@@ -4,6 +4,8 @@
 
 #include "chrome/browser/component_updater/recovery_component_installer.h"
 
+#include <string>
+
 #include "base/base_paths.h"
 #include "base/bind.h"
 #include "base/command_line.h"
@@ -18,6 +20,7 @@
 #include "base/strings/string_util.h"
 #include "base/values.h"
 #include "chrome/browser/component_updater/component_updater_service.h"
+#include "chrome/common/chrome_paths.h"
 #include "chrome/common/chrome_version_info.h"
 #include "chrome/common/pref_names.h"
 #include "content/public/browser/browser_thread.h"
@@ -66,8 +69,7 @@ class RecoveryComponentInstaller : public ComponentInstaller {
   PrefService* prefs_;
 };
 
-void RecoveryRegisterHelper(ComponentUpdateService* cus,
-                            PrefService* prefs) {
+void RecoveryRegisterHelper(ComponentUpdateService* cus, PrefService* prefs) {
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
   Version version(prefs->GetString(prefs::kRecoveryComponentVersion));
   if (!version.IsValid()) {
@@ -90,9 +92,9 @@ void RecoveryUpdateVersionHelper(const Version& version, PrefService* prefs) {
   prefs->SetString(prefs::kRecoveryComponentVersion, version.GetString());
 }
 
-RecoveryComponentInstaller::RecoveryComponentInstaller(
-      const Version& version, PrefService* prefs)
-    : current_version_(version), prefs_(prefs){
+RecoveryComponentInstaller::RecoveryComponentInstaller(const Version& version,
+                                                       PrefService* prefs)
+    : current_version_(version), prefs_(prefs) {
   DCHECK(version.IsValid());
 }
 
@@ -113,11 +115,23 @@ bool RecoveryComponentInstaller::Install(const base::DictionaryValue& manifest,
     return false;
   if (current_version_.CompareTo(version) >= 0)
     return false;
-  base::FilePath main_file = unpack_path.Append(kRecoveryFileName);
+
+  // Passed the basic tests. Copy the installation to a permanent directory.
+  base::FilePath path;
+  if (!PathService::Get(chrome::DIR_RECOVERY_BASE, &path))
+    return false;
+  path = path.AppendASCII(version.GetString());
+  if (base::PathExists(path) && !base::DeleteFile(path, true))
+      return false;
+  if (!base::Move(unpack_path, path)) {
+    DVLOG(1) << "Recovery component move failed.";
+    return false;
+  }
+
+  base::FilePath main_file = path.Append(kRecoveryFileName);
   if (!base::PathExists(main_file))
     return false;
-  // Passed the basic tests. The installation continues with the
-  // recovery component itself running from the temp directory.
+  // Run the recovery component.
   CommandLine cmdline(main_file);
   std::string arguments;
   if (manifest.GetStringASCII("x-recovery-args", &arguments))
@@ -129,14 +143,17 @@ bool RecoveryComponentInstaller::Install(const base::DictionaryValue& manifest,
   }
   current_version_ = version;
   if (prefs_) {
-    BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+    BrowserThread::PostTask(
+        BrowserThread::UI,
+        FROM_HERE,
         base::Bind(&RecoveryUpdateVersionHelper, version, prefs_));
   }
   return base::LaunchProcess(cmdline, base::LaunchOptions(), NULL);
 }
 
 bool RecoveryComponentInstaller::GetInstalledFile(
-    const std::string& file, base::FilePath* installed_file) {
+    const std::string& file,
+    base::FilePath* installed_file) {
   return false;
 }
 
@@ -158,4 +175,3 @@ void RegisterPrefsForRecoveryComponent(PrefRegistrySimple* registry) {
 }
 
 }  // namespace component_updater
-