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

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

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header Created 4 years, 8 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/signed_in_devices_api. h" 5 #include "chrome/browser/extensions/api/signed_in_devices/signed_in_devices_api. h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include <memory>
8
8 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
9 #include "base/values.h" 10 #include "base/values.h"
10 #include "chrome/browser/extensions/api/signed_in_devices/id_mapping_helper.h" 11 #include "chrome/browser/extensions/api/signed_in_devices/id_mapping_helper.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/sync/profile_sync_service_factory.h" 13 #include "chrome/browser/sync/profile_sync_service_factory.h"
13 #include "chrome/common/extensions/api/signed_in_devices.h" 14 #include "chrome/common/extensions/api/signed_in_devices.h"
14 #include "components/browser_sync/browser/profile_sync_service.h" 15 #include "components/browser_sync/browser/profile_sync_service.h"
15 #include "components/sync_driver/device_info_tracker.h" 16 #include "components/sync_driver/device_info_tracker.h"
16 #include "components/sync_driver/local_device_info_provider.h" 17 #include "components/sync_driver/local_device_info_provider.h"
17 #include "extensions/browser/extension_prefs.h" 18 #include "extensions/browser/extension_prefs.h"
(...skipping 12 matching lines...) Expand all
30 const base::DictionaryValue* GetIdMappingDictionary( 31 const base::DictionaryValue* GetIdMappingDictionary(
31 ExtensionPrefs* extension_prefs, 32 ExtensionPrefs* extension_prefs,
32 const std::string& extension_id) { 33 const std::string& extension_id) {
33 const base::DictionaryValue* out_value = NULL; 34 const base::DictionaryValue* out_value = NULL;
34 if (!extension_prefs->ReadPrefAsDictionary( 35 if (!extension_prefs->ReadPrefAsDictionary(
35 extension_id, 36 extension_id,
36 kPrefStringForIdMapping, 37 kPrefStringForIdMapping,
37 &out_value) || out_value == NULL) { 38 &out_value) || out_value == NULL) {
38 // Looks like this is the first call to get the dictionary. Let us create 39 // Looks like this is the first call to get the dictionary. Let us create
39 // a dictionary and set it in to |extension_prefs|. 40 // a dictionary and set it in to |extension_prefs|.
40 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue()); 41 std::unique_ptr<base::DictionaryValue> dictionary(
42 new base::DictionaryValue());
41 out_value = dictionary.get(); 43 out_value = dictionary.get();
42 extension_prefs->UpdateExtensionPref( 44 extension_prefs->UpdateExtensionPref(
43 extension_id, 45 extension_id,
44 kPrefStringForIdMapping, 46 kPrefStringForIdMapping,
45 dictionary.release()); 47 dictionary.release());
46 } 48 }
47 49
48 return out_value; 50 return out_value;
49 } 51 }
50 52
51 // Helper routine to get all signed in devices. The helper takes in 53 // Helper routine to get all signed in devices. The helper takes in
52 // the pointers for |DeviceInfoTracker| and |Extensionprefs|. This 54 // the pointers for |DeviceInfoTracker| and |Extensionprefs|. This
53 // makes it easier to test by passing mock values for these pointers. 55 // makes it easier to test by passing mock values for these pointers.
54 ScopedVector<DeviceInfo> GetAllSignedInDevices( 56 ScopedVector<DeviceInfo> GetAllSignedInDevices(
55 const std::string& extension_id, 57 const std::string& extension_id,
56 DeviceInfoTracker* device_tracker, 58 DeviceInfoTracker* device_tracker,
57 ExtensionPrefs* extension_prefs) { 59 ExtensionPrefs* extension_prefs) {
58 DCHECK(device_tracker); 60 DCHECK(device_tracker);
59 ScopedVector<DeviceInfo> devices = device_tracker->GetAllDeviceInfo(); 61 ScopedVector<DeviceInfo> devices = device_tracker->GetAllDeviceInfo();
60 const base::DictionaryValue* mapping_dictionary = GetIdMappingDictionary( 62 const base::DictionaryValue* mapping_dictionary = GetIdMappingDictionary(
61 extension_prefs, 63 extension_prefs,
62 extension_id); 64 extension_id);
63 65
64 CHECK(mapping_dictionary); 66 CHECK(mapping_dictionary);
65 67
66 // |mapping_dictionary| is const. So make an editable copy. 68 // |mapping_dictionary| is const. So make an editable copy.
67 scoped_ptr<base::DictionaryValue> editable_mapping_dictionary( 69 std::unique_ptr<base::DictionaryValue> editable_mapping_dictionary(
68 mapping_dictionary->DeepCopy()); 70 mapping_dictionary->DeepCopy());
69 71
70 CreateMappingForUnmappedDevices(&(devices.get()), 72 CreateMappingForUnmappedDevices(&(devices.get()),
71 editable_mapping_dictionary.get()); 73 editable_mapping_dictionary.get());
72 74
73 // Write into |ExtensionPrefs| which will get persisted in disk. 75 // Write into |ExtensionPrefs| which will get persisted in disk.
74 extension_prefs->UpdateExtensionPref(extension_id, 76 extension_prefs->UpdateExtensionPref(extension_id,
75 kPrefStringForIdMapping, 77 kPrefStringForIdMapping,
76 editable_mapping_dictionary.release()); 78 editable_mapping_dictionary.release());
77 return devices; 79 return devices;
(...skipping 10 matching lines...) Expand all
88 if (!device_tracker->IsSyncing()) { 90 if (!device_tracker->IsSyncing()) {
89 // Devices are not sync'ing. 91 // Devices are not sync'ing.
90 return ScopedVector<DeviceInfo>(); 92 return ScopedVector<DeviceInfo>();
91 } 93 }
92 94
93 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile); 95 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile);
94 96
95 return GetAllSignedInDevices(extension_id, device_tracker, extension_prefs); 97 return GetAllSignedInDevices(extension_id, device_tracker, extension_prefs);
96 } 98 }
97 99
98 scoped_ptr<DeviceInfo> GetLocalDeviceInfo(const std::string& extension_id, 100 std::unique_ptr<DeviceInfo> GetLocalDeviceInfo(const std::string& extension_id,
99 Profile* profile) { 101 Profile* profile) {
100 ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile(profile); 102 ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile(profile);
101 if (!pss) { 103 if (!pss) {
102 return scoped_ptr<DeviceInfo>(); 104 return std::unique_ptr<DeviceInfo>();
103 } 105 }
104 106
105 LocalDeviceInfoProvider* local_device = pss->GetLocalDeviceInfoProvider(); 107 LocalDeviceInfoProvider* local_device = pss->GetLocalDeviceInfoProvider();
106 DCHECK(local_device); 108 DCHECK(local_device);
107 std::string guid = local_device->GetLocalSyncCacheGUID(); 109 std::string guid = local_device->GetLocalSyncCacheGUID();
108 scoped_ptr<DeviceInfo> device = GetDeviceInfoForClientId(guid, 110 std::unique_ptr<DeviceInfo> device =
109 extension_id, 111 GetDeviceInfoForClientId(guid, extension_id, profile);
110 profile);
111 return device; 112 return device;
112 } 113 }
113 114
114 bool SignedInDevicesGetFunction::RunSync() { 115 bool SignedInDevicesGetFunction::RunSync() {
115 scoped_ptr<api::signed_in_devices::Get::Params> params( 116 std::unique_ptr<api::signed_in_devices::Get::Params> params(
116 api::signed_in_devices::Get::Params::Create(*args_)); 117 api::signed_in_devices::Get::Params::Create(*args_));
117 EXTENSION_FUNCTION_VALIDATE(params.get()); 118 EXTENSION_FUNCTION_VALIDATE(params.get());
118 119
119 bool is_local = params->is_local.get() ? *params->is_local : false; 120 bool is_local = params->is_local.get() ? *params->is_local : false;
120 121
121 if (is_local) { 122 if (is_local) {
122 scoped_ptr<DeviceInfo> device = 123 std::unique_ptr<DeviceInfo> device =
123 GetLocalDeviceInfo(extension_id(), GetProfile()); 124 GetLocalDeviceInfo(extension_id(), GetProfile());
124 base::ListValue* result = new base::ListValue(); 125 base::ListValue* result = new base::ListValue();
125 if (device.get()) { 126 if (device.get()) {
126 result->Append(device->ToValue()); 127 result->Append(device->ToValue());
127 } 128 }
128 SetResult(result); 129 SetResult(result);
129 return true; 130 return true;
130 } 131 }
131 132
132 ScopedVector<DeviceInfo> devices = 133 ScopedVector<DeviceInfo> devices =
133 GetAllSignedInDevices(extension_id(), GetProfile()); 134 GetAllSignedInDevices(extension_id(), GetProfile());
134 135
135 scoped_ptr<base::ListValue> result(new base::ListValue()); 136 std::unique_ptr<base::ListValue> result(new base::ListValue());
136 137
137 for (ScopedVector<DeviceInfo>::const_iterator it = devices.begin(); 138 for (ScopedVector<DeviceInfo>::const_iterator it = devices.begin();
138 it != devices.end(); 139 it != devices.end();
139 ++it) { 140 ++it) {
140 result->Append((*it)->ToValue()); 141 result->Append((*it)->ToValue());
141 } 142 }
142 143
143 SetResult(result.release()); 144 SetResult(result.release());
144 return true; 145 return true;
145 } 146 }
146 147
147 } // namespace extensions 148 } // namespace extensions
148 149
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698