| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/signed_in_devices/id_mapping_helper.h" | 5 #include "chrome/browser/extensions/api/signed_in_devices/id_mapping_helper.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
| 9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/extensions/api/signed_in_devices/signed_in_devices_api.
h" | 12 #include "chrome/browser/extensions/api/signed_in_devices/signed_in_devices_api.
h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/sync/glue/device_info.h" | |
| 15 #include "components/crx_file/id_util.h" | 14 #include "components/crx_file/id_util.h" |
| 15 #include "components/sync_driver/device_info.h" |
| 16 | 16 |
| 17 using base::DictionaryValue; | 17 using base::DictionaryValue; |
| 18 using base::Value; | 18 using base::Value; |
| 19 using browser_sync::DeviceInfo; | 19 using sync_driver::DeviceInfo; |
| 20 | 20 |
| 21 namespace extensions { | 21 namespace extensions { |
| 22 | 22 |
| 23 std::string GetPublicIdFromGUID( | 23 std::string GetPublicIdFromGUID( |
| 24 const base::DictionaryValue& id_mapping, | 24 const base::DictionaryValue& id_mapping, |
| 25 const std::string& guid) { | 25 const std::string& guid) { |
| 26 for (base::DictionaryValue::Iterator it(id_mapping); | 26 for (base::DictionaryValue::Iterator it(id_mapping); |
| 27 !it.IsAtEnd(); | 27 !it.IsAtEnd(); |
| 28 it.Advance()) { | 28 it.Advance()) { |
| 29 const base::Value& value = it.value(); | 29 const base::Value& value = it.value(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 do { | 62 do { |
| 63 string_value = base::IntToString(rand_value); | 63 string_value = base::IntToString(rand_value); |
| 64 rand_value++; | 64 rand_value++; |
| 65 } while (mapping.Get(string_value, &out_value)); | 65 } while (mapping.Get(string_value, &out_value)); |
| 66 | 66 |
| 67 return string_value; | 67 return string_value; |
| 68 } | 68 } |
| 69 | 69 |
| 70 void CreateMappingForUnmappedDevices( | 70 void CreateMappingForUnmappedDevices( |
| 71 std::vector<browser_sync::DeviceInfo*>* device_info, | 71 std::vector<DeviceInfo*>* device_info, |
| 72 base::DictionaryValue* value) { | 72 base::DictionaryValue* value) { |
| 73 for (unsigned int i = 0; i < device_info->size(); ++i) { | 73 for (unsigned int i = 0; i < device_info->size(); ++i) { |
| 74 DeviceInfo* device = (*device_info)[i]; | 74 DeviceInfo* device = (*device_info)[i]; |
| 75 std::string local_id = GetPublicIdFromGUID(*value, | 75 std::string local_id = GetPublicIdFromGUID(*value, |
| 76 device->guid()); | 76 device->guid()); |
| 77 | 77 |
| 78 // If the device does not have a local id, set one. | 78 // If the device does not have a local id, set one. |
| 79 if (local_id.empty()) { | 79 if (local_id.empty()) { |
| 80 local_id = GetRandomId(*value, device_info->size()); | 80 local_id = GetRandomId(*value, device_info->size()); |
| 81 value->SetString(local_id, device->guid()); | 81 value->SetString(local_id, device->guid()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 98 if ((*it)->guid() == client_id) { | 98 if ((*it)->guid() == client_id) { |
| 99 scoped_ptr<DeviceInfo> device(*it); | 99 scoped_ptr<DeviceInfo> device(*it); |
| 100 devices.weak_erase(it); | 100 devices.weak_erase(it); |
| 101 return device.Pass(); | 101 return device.Pass(); |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 return scoped_ptr<DeviceInfo>(); | 104 return scoped_ptr<DeviceInfo>(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 } // namespace extensions | 107 } // namespace extensions |
| OLD | NEW |