Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / signed_in_devices / signed_in_devices_api.cc
index 9a8f8f2..68d9922 100644 (file)
@@ -8,15 +8,18 @@
 #include "base/memory/scoped_vector.h"
 #include "base/values.h"
 #include "chrome/browser/extensions/api/signed_in_devices/id_mapping_helper.h"
-#include "chrome/browser/extensions/extension_prefs.h"
 #include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/sync/glue/device_info.h"
 #include "chrome/browser/sync/profile_sync_service.h"
 #include "chrome/browser/sync/profile_sync_service_factory.h"
 #include "chrome/common/extensions/api/signed_in_devices.h"
+#include "components/sync_driver/device_info_tracker.h"
+#include "components/sync_driver/local_device_info_provider.h"
+#include "extensions/browser/extension_prefs.h"
 
 using base::DictionaryValue;
-using browser_sync::DeviceInfo;
+using sync_driver::DeviceInfo;
+using sync_driver::DeviceInfoTracker;
+using sync_driver::LocalDeviceInfoProvider;
 
 namespace extensions {
 
@@ -34,7 +37,7 @@ const base::DictionaryValue* GetIdMappingDictionary(
           &out_value) || out_value == NULL) {
     // Looks like this is the first call to get the dictionary. Let us create
     // a dictionary and set it in to |extension_prefs|.
-    scoped_ptr<DictionaryValue> dictionary(new DictionaryValue());
+    scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue());
     out_value = dictionary.get();
     extension_prefs->UpdateExtensionPref(
         extension_id,
@@ -46,21 +49,22 @@ const base::DictionaryValue* GetIdMappingDictionary(
 }
 
 // Helper routine to get all signed in devices. The helper takes in
-// the pointers for |ProfileSyncService| and |Extensionprefs|. This
+// the pointers for |DeviceInfoTracker| and |Extensionprefs|. This
 // makes it easier to test by passing mock values for these pointers.
 ScopedVector<DeviceInfo> GetAllSignedInDevices(
     const std::string& extension_id,
-    ProfileSyncService* pss,
+    DeviceInfoTracker* device_tracker,
     ExtensionPrefs* extension_prefs) {
-  ScopedVector<DeviceInfo> devices = pss->GetAllSignedInDevices();
-  const DictionaryValue* mapping_dictionary = GetIdMappingDictionary(
+  DCHECK(device_tracker);
+  ScopedVector<DeviceInfo> devices = device_tracker->GetAllDeviceInfo();
+  const base::DictionaryValue* mapping_dictionary = GetIdMappingDictionary(
       extension_prefs,
       extension_id);
 
   CHECK(mapping_dictionary);
 
   // |mapping_dictionary| is const. So make an editable copy.
-  scoped_ptr<DictionaryValue> editable_mapping_dictionary(
+  scoped_ptr<base::DictionaryValue> editable_mapping_dictionary(
       mapping_dictionary->DeepCopy());
 
   CreateMappingForUnmappedDevices(&(devices.get()),
@@ -76,14 +80,18 @@ ScopedVector<DeviceInfo> GetAllSignedInDevices(
 ScopedVector<DeviceInfo> GetAllSignedInDevices(
     const std::string& extension_id,
     Profile* profile) {
-  // Get the profile sync service and extension prefs pointers
+  // Get the device tracker and extension prefs pointers
   // and call the helper.
-  ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile(profile);
+  DeviceInfoTracker* device_tracker =
+      ProfileSyncServiceFactory::GetForProfile(profile)->GetDeviceInfoTracker();
+  if (device_tracker == NULL) {
+    // Devices are not sync'ing.
+    return ScopedVector<DeviceInfo>().Pass();
+  }
+
   ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile);
 
-  return GetAllSignedInDevices(extension_id,
-                               pss,
-                               extension_prefs);
+  return GetAllSignedInDevices(extension_id, device_tracker, extension_prefs);
 }
 
 scoped_ptr<DeviceInfo> GetLocalDeviceInfo(const std::string& extension_id,
@@ -92,14 +100,17 @@ scoped_ptr<DeviceInfo> GetLocalDeviceInfo(const std::string& extension_id,
   if (!pss) {
     return scoped_ptr<DeviceInfo>();
   }
-  std::string guid = pss->GetLocalDeviceGUID();
+
+  LocalDeviceInfoProvider* local_device = pss->GetLocalDeviceInfoProvider();
+  DCHECK(local_device);
+  std::string guid = local_device->GetLocalSyncCacheGUID();
   scoped_ptr<DeviceInfo> device = GetDeviceInfoForClientId(guid,
                                                            extension_id,
                                                            profile);
   return device.Pass();
 }
 
-bool SignedInDevicesGetFunction::RunImpl() {
+bool SignedInDevicesGetFunction::RunSync() {
   scoped_ptr<api::signed_in_devices::Get::Params> params(
       api::signed_in_devices::Get::Params::Create(*args_));
   EXTENSION_FUNCTION_VALIDATE(params.get());