[Sync] Move some extension-sync-related logic to ExtensionService

Add ExtensionSyncData class to hold the data that goes between the
extension service and extension sync.

Add ProcessSyncData() method to ExtensionService (with unit tests!).

Remove now-unneeded extension sync functions.

BUG=77995
TEST=

Review URL: http://codereview.chromium.org/6852029

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81899 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index 2197792a..3ddccd1 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -38,6 +38,7 @@
 #include "chrome/browser/extensions/extension_process_manager.h"
 #include "chrome/browser/extensions/extension_processes_api.h"
 #include "chrome/browser/extensions/extension_special_storage_policy.h"
+#include "chrome/browser/extensions/extension_sync_data.h"
 #include "chrome/browser/extensions/extension_updater.h"
 #include "chrome/browser/extensions/extension_web_ui.h"
 #include "chrome/browser/extensions/extension_webnavigation_api.h"
@@ -1197,6 +1198,63 @@
   }
 }
 
+void ExtensionService::ProcessSyncData(
+    const ExtensionSyncData& extension_sync_data,
+    PendingExtensionInfo::ShouldAllowInstallPredicate should_allow) {
+  const std::string& id = extension_sync_data.id;
+
+  // Handle uninstalls first.
+  if (extension_sync_data.uninstalled) {
+    std::string error;
+    if (!UninstallExtensionHelper(this, id)) {
+      LOG(WARNING) << "Could not uninstall extension " << id
+                   << " for sync";
+    }
+    return;
+  }
+
+  const Extension* extension = GetExtensionByIdInternal(id, true, true);
+  // TODO(akalin): Figure out what to do with terminated extensions.
+
+  // Handle already-installed extensions (just update settings).
+  //
+  // TODO(akalin): Ideally, we should be able to set prefs for an
+  // extension regardless of whether or not it's installed (and have
+  // it automatially apply on install).
+  if (extension) {
+    if (extension_sync_data.enabled) {
+      EnableExtension(id);
+    } else {
+      DisableExtension(id);
+    }
+    SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled);
+    int result = extension->version()->CompareTo(extension_sync_data.version);
+    if (result < 0) {
+      // Extension is outdated.
+      CheckForUpdatesSoon();
+    } else if (result > 0) {
+      // Sync version is outdated.  Do nothing for now, as sync code
+      // in other places will eventually update the sync data.
+      //
+      // TODO(akalin): Move that code here.
+    }
+    return;
+  }
+
+  // Handle not-yet-installed extensions.
+  //
+  // TODO(akalin): Replace silent update with a list of enabled
+  // permissions.
+  pending_extension_manager()->AddFromSync(
+      id,
+      extension_sync_data.update_url,
+      should_allow,
+      true,  // install_silently
+      extension_sync_data.enabled,
+      extension_sync_data.incognito_enabled);
+  CheckForUpdatesSoon();
+}
+
 bool ExtensionService::IsIncognitoEnabled(
     const std::string& extension_id) const {
   // If this is an existing component extension we always allow it to