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

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

Issue 566623003: Refactor syncable DEVICE_INFO type from ChangeProcessor to SyncableService - part 3. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unit test fixes Created 6 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/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 "base/memory/scoped_ptr.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/extensions/api/signed_in_devices/id_mapping_helper.h" 10 #include "chrome/browser/extensions/api/signed_in_devices/id_mapping_helper.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/sync/glue/device_info.h" 12 #include "chrome/browser/sync/glue/device_info_tracker.h"
13 #include "chrome/browser/sync/glue/local_device_info_provider.h" 13 #include "chrome/browser/sync/glue/local_device_info_provider.h"
14 #include "chrome/browser/sync/profile_sync_service.h" 14 #include "chrome/browser/sync/profile_sync_service.h"
15 #include "chrome/browser/sync/profile_sync_service_factory.h" 15 #include "chrome/browser/sync/profile_sync_service_factory.h"
16 #include "chrome/common/extensions/api/signed_in_devices.h" 16 #include "chrome/common/extensions/api/signed_in_devices.h"
17 #include "extensions/browser/extension_prefs.h" 17 #include "extensions/browser/extension_prefs.h"
18 18
19 using base::DictionaryValue; 19 using base::DictionaryValue;
20 using browser_sync::DeviceInfo; 20 using browser_sync::DeviceInfo;
21 using browser_sync::DeviceInfoTracker;
21 using browser_sync::LocalDeviceInfoProvider; 22 using browser_sync::LocalDeviceInfoProvider;
22 23
23 namespace extensions { 24 namespace extensions {
24 25
25 static const char kPrefStringForIdMapping[] = "id_mapping_dictioanry"; 26 static const char kPrefStringForIdMapping[] = "id_mapping_dictioanry";
26 27
27 // Gets the dictionary that stores the id mapping. The dictionary is stored 28 // Gets the dictionary that stores the id mapping. The dictionary is stored
28 // in the |ExtensionPrefs|. 29 // in the |ExtensionPrefs|.
29 const base::DictionaryValue* GetIdMappingDictionary( 30 const base::DictionaryValue* GetIdMappingDictionary(
30 ExtensionPrefs* extension_prefs, 31 ExtensionPrefs* extension_prefs,
(...skipping 10 matching lines...) Expand all
41 extension_prefs->UpdateExtensionPref( 42 extension_prefs->UpdateExtensionPref(
42 extension_id, 43 extension_id,
43 kPrefStringForIdMapping, 44 kPrefStringForIdMapping,
44 dictionary.release()); 45 dictionary.release());
45 } 46 }
46 47
47 return out_value; 48 return out_value;
48 } 49 }
49 50
50 // Helper routine to get all signed in devices. The helper takes in 51 // Helper routine to get all signed in devices. The helper takes in
51 // the pointers for |ProfileSyncService| and |Extensionprefs|. This 52 // the pointers for |DeviceInfoTracker| and |Extensionprefs|. This
52 // makes it easier to test by passing mock values for these pointers. 53 // makes it easier to test by passing mock values for these pointers.
53 ScopedVector<DeviceInfo> GetAllSignedInDevices( 54 ScopedVector<DeviceInfo> GetAllSignedInDevices(
54 const std::string& extension_id, 55 const std::string& extension_id,
55 ProfileSyncService* pss, 56 DeviceInfoTracker* device_tracker,
56 ExtensionPrefs* extension_prefs) { 57 ExtensionPrefs* extension_prefs) {
57 ScopedVector<DeviceInfo> devices = pss->GetAllSignedInDevices(); 58 ScopedVector<DeviceInfo> devices = device_tracker->GetAllDeviceInfo();
58 const base::DictionaryValue* mapping_dictionary = GetIdMappingDictionary( 59 const base::DictionaryValue* mapping_dictionary = GetIdMappingDictionary(
59 extension_prefs, 60 extension_prefs,
60 extension_id); 61 extension_id);
61 62
62 CHECK(mapping_dictionary); 63 CHECK(mapping_dictionary);
63 64
64 // |mapping_dictionary| is const. So make an editable copy. 65 // |mapping_dictionary| is const. So make an editable copy.
65 scoped_ptr<base::DictionaryValue> editable_mapping_dictionary( 66 scoped_ptr<base::DictionaryValue> editable_mapping_dictionary(
66 mapping_dictionary->DeepCopy()); 67 mapping_dictionary->DeepCopy());
67 68
68 CreateMappingForUnmappedDevices(&(devices.get()), 69 CreateMappingForUnmappedDevices(&(devices.get()),
69 editable_mapping_dictionary.get()); 70 editable_mapping_dictionary.get());
70 71
71 // Write into |ExtensionPrefs| which will get persisted in disk. 72 // Write into |ExtensionPrefs| which will get persisted in disk.
72 extension_prefs->UpdateExtensionPref(extension_id, 73 extension_prefs->UpdateExtensionPref(extension_id,
73 kPrefStringForIdMapping, 74 kPrefStringForIdMapping,
74 editable_mapping_dictionary.release()); 75 editable_mapping_dictionary.release());
75 return devices.Pass(); 76 return devices.Pass();
76 } 77 }
77 78
78 ScopedVector<DeviceInfo> GetAllSignedInDevices( 79 ScopedVector<DeviceInfo> GetAllSignedInDevices(
79 const std::string& extension_id, 80 const std::string& extension_id,
80 Profile* profile) { 81 Profile* profile) {
81 // Get the profile sync service and extension prefs pointers 82 // Get the device tracker and extension prefs pointers
82 // and call the helper. 83 // and call the helper.
83 ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile(profile); 84 DeviceInfoTracker* device_tracker =
85 ProfileSyncServiceFactory::GetForProfile(profile)->GetDeviceInfoTracker();
pavely 2014/09/17 23:04:38 What is the condition when GetDeviceInfoTracker()
stanisc 2014/09/18 22:46:53 Good catch! It could only be null if either Sync b
84 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile); 86 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile);
85 87
86 return GetAllSignedInDevices(extension_id, 88 return GetAllSignedInDevices(extension_id, device_tracker, extension_prefs);
87 pss,
88 extension_prefs);
89 } 89 }
90 90
91 scoped_ptr<DeviceInfo> GetLocalDeviceInfo(const std::string& extension_id, 91 scoped_ptr<DeviceInfo> GetLocalDeviceInfo(const std::string& extension_id,
92 Profile* profile) { 92 Profile* profile) {
93 ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile(profile); 93 ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile(profile);
94 if (!pss) { 94 if (!pss) {
95 return scoped_ptr<DeviceInfo>(); 95 return scoped_ptr<DeviceInfo>();
96 } 96 }
97 97
98 LocalDeviceInfoProvider* local_device = pss->GetLocalDeviceInfoProvider(); 98 LocalDeviceInfoProvider* local_device = pss->GetLocalDeviceInfoProvider();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 ++it) { 132 ++it) {
133 result->Append((*it)->ToValue()); 133 result->Append((*it)->ToValue());
134 } 134 }
135 135
136 SetResult(result.release()); 136 SetResult(result.release());
137 return true; 137 return true;
138 } 138 }
139 139
140 } // namespace extensions 140 } // namespace extensions
141 141
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698