Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: chrome/browser/extensions/api/signed_in_devices/id_mapping_helper.cc

Issue 2310683002: Remove most ScopedVector usage from c/b/extensions. (Closed)
Patch Set: cleaned up Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 7 #include <memory>
8 8
9 #include "base/memory/scoped_vector.h"
10 #include "base/rand_util.h" 9 #include "base/rand_util.h"
11 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
12 #include "base/values.h" 11 #include "base/values.h"
13 #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"
14 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
15 #include "components/crx_file/id_util.h" 14 #include "components/crx_file/id_util.h"
16 #include "components/sync/device_info/device_info.h" 15 #include "components/sync/device_info/device_info.h"
17 16
18 using base::DictionaryValue; 17 using base::DictionaryValue;
19 using base::Value; 18 using base::Value;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 61
63 do { 62 do {
64 string_value = base::IntToString(rand_value); 63 string_value = base::IntToString(rand_value);
65 rand_value++; 64 rand_value++;
66 } while (mapping.Get(string_value, &out_value)); 65 } while (mapping.Get(string_value, &out_value));
67 66
68 return string_value; 67 return string_value;
69 } 68 }
70 69
71 void CreateMappingForUnmappedDevices( 70 void CreateMappingForUnmappedDevices(
72 std::vector<DeviceInfo*>* device_info, 71 const std::vector<std::unique_ptr<DeviceInfo>>& device_info,
73 base::DictionaryValue* value) { 72 base::DictionaryValue* value) {
74 for (unsigned int i = 0; i < device_info->size(); ++i) { 73 for (const std::unique_ptr<DeviceInfo>& device : device_info) {
75 DeviceInfo* device = (*device_info)[i];
76 std::string local_id = GetPublicIdFromGUID(*value, 74 std::string local_id = GetPublicIdFromGUID(*value,
77 device->guid()); 75 device->guid());
78 76
79 // If the device does not have a local id, set one. 77 // If the device does not have a local id, set one.
80 if (local_id.empty()) { 78 if (local_id.empty()) {
81 local_id = GetRandomId(*value, device_info->size()); 79 local_id = GetRandomId(*value, device_info.size());
82 value->SetString(local_id, device->guid()); 80 value->SetString(local_id, device->guid());
83 } 81 }
84 device->set_public_id(local_id); 82 device->set_public_id(local_id);
85 } 83 }
86 } 84 }
87 85
88 std::unique_ptr<DeviceInfo> GetDeviceInfoForClientId( 86 std::unique_ptr<DeviceInfo> GetDeviceInfoForClientId(
89 const std::string& client_id, 87 const std::string& client_id,
90 const std::string& extension_id, 88 const std::string& extension_id,
91 Profile* profile) { 89 Profile* profile) {
92 DCHECK(crx_file::id_util::IdIsValid(extension_id)) << extension_id 90 DCHECK(crx_file::id_util::IdIsValid(extension_id)) << extension_id
93 << " is not valid"; 91 << " is not valid";
94 ScopedVector<DeviceInfo> devices = GetAllSignedInDevices(extension_id, 92 std::vector<std::unique_ptr<DeviceInfo>> devices =
95 profile); 93 GetAllSignedInDevices(extension_id, profile);
96 for (ScopedVector<DeviceInfo>::iterator it = devices.begin(); 94 for (std::vector<std::unique_ptr<DeviceInfo>>::iterator it = devices.begin();
97 it != devices.end(); 95 it != devices.end(); ++it) {
asargent_no_longer_on_chrome 2016/09/06 22:12:40 consider shortening this to: for (auto it : devic
lazyboy 2016/09/06 23:49:38 Done.
98 ++it) {
99 if ((*it)->guid() == client_id) { 96 if ((*it)->guid() == client_id) {
100 std::unique_ptr<DeviceInfo> device(*it); 97 std::unique_ptr<DeviceInfo> device = std::move(*it);
101 devices.weak_erase(it);
102 return device; 98 return device;
103 } 99 }
104 } 100 }
105 return std::unique_ptr<DeviceInfo>(); 101 return std::unique_ptr<DeviceInfo>();
106 } 102 }
107 103
108 } // namespace extensions 104 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698