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

Side by Side Diff: chrome/browser/extensions/api/signedin_devices/signedin_devices_api.cc

Issue 22706006: Implementation of the DeviceInfo get API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For try runs Created 7 years, 4 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 | Annotate | Revision Log
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/signedin_devices/signedin_devices_api.h" 5 #include "chrome/browser/extensions/api/signedin_devices/signedin_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/signedin_devices/id_mapping_helper.h" 10 #include "chrome/browser/extensions/api/signedin_devices/id_mapping_helper.h"
11 #include "chrome/browser/extensions/extension_prefs.h" 11 #include "chrome/browser/extensions/extension_prefs.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/sync/glue/device_info.h" 13 #include "chrome/browser/sync/glue/device_info.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/signedin_devices.h"
16 17
17 using base::DictionaryValue; 18 using base::DictionaryValue;
18 using browser_sync::DeviceInfo; 19 using browser_sync::DeviceInfo;
19 20
20 namespace extensions { 21 namespace extensions {
21 22
22 static const char kPrefStringForIdMapping[] = "id_mapping_dictioanry"; 23 static const char kPrefStringForIdMapping[] = "id_mapping_dictioanry";
23 24
24 // Gets the dictionary that stores the id mapping. The dictionary is stored 25 // Gets the dictionary that stores the id mapping. The dictionary is stored
25 // in the |ExtensionPrefs|. 26 // in the |ExtensionPrefs|.
(...skipping 14 matching lines...) Expand all
40 kPrefStringForIdMapping, 41 kPrefStringForIdMapping,
41 dictionary.release()); 42 dictionary.release());
42 } 43 }
43 44
44 return out_value; 45 return out_value;
45 } 46 }
46 47
47 // Helper routine to get all signed in devices. The helper takes in 48 // Helper routine to get all signed in devices. The helper takes in
48 // the pointers for |ProfileSyncService| and |Extensionprefs|. This 49 // the pointers for |ProfileSyncService| and |Extensionprefs|. This
49 // makes it easier to test by passing mock values for these pointers. 50 // makes it easier to test by passing mock values for these pointers.
50 ScopedVector<DeviceInfo> GetAllSignedInDevices( 51 ScopedVector<DeviceInfo> GetAllSignedinDevices(
51 const std::string& extension_id, 52 const std::string& extension_id,
52 ProfileSyncService* pss, 53 ProfileSyncService* pss,
53 ExtensionPrefs* extension_prefs) { 54 ExtensionPrefs* extension_prefs) {
54 ScopedVector<DeviceInfo> devices = pss->GetAllSignedInDevices(); 55 ScopedVector<DeviceInfo> devices = pss->GetAllSignedinDevices();
55 const DictionaryValue* mapping_dictionary = GetIdMappingDictionary( 56 const DictionaryValue* mapping_dictionary = GetIdMappingDictionary(
56 extension_prefs, 57 extension_prefs,
57 extension_id); 58 extension_id);
58 59
59 CHECK(mapping_dictionary); 60 CHECK(mapping_dictionary);
60 61
61 // |mapping_dictionary| is const. So make an editable copy. 62 // |mapping_dictionary| is const. So make an editable copy.
62 scoped_ptr<DictionaryValue> editable_mapping_dictionary( 63 scoped_ptr<DictionaryValue> editable_mapping_dictionary(
63 mapping_dictionary->DeepCopy()); 64 mapping_dictionary->DeepCopy());
64 65
65 CreateMappingForUnmappedDevices(&(devices.get()), 66 CreateMappingForUnmappedDevices(&(devices.get()),
66 editable_mapping_dictionary.get()); 67 editable_mapping_dictionary.get());
67 68
68 // Write into |ExtensionPrefs| which will get persisted in disk. 69 // Write into |ExtensionPrefs| which will get persisted in disk.
69 extension_prefs->UpdateExtensionPref(extension_id, 70 extension_prefs->UpdateExtensionPref(extension_id,
70 kPrefStringForIdMapping, 71 kPrefStringForIdMapping,
71 editable_mapping_dictionary.release()); 72 editable_mapping_dictionary.release());
72 return devices.Pass(); 73 return devices.Pass();
73 } 74 }
74 75
75 ScopedVector<DeviceInfo> GetAllSignedInDevices( 76 ScopedVector<DeviceInfo> GetAllSignedinDevices(
76 const std::string& extension_id, 77 const std::string& extension_id,
77 Profile* profile) { 78 Profile* profile) {
78 // Get the profile sync service and extension prefs pointers 79 // Get the profile sync service and extension prefs pointers
79 // and call the helper. 80 // and call the helper.
80 ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile(profile); 81 ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile(profile);
81 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile); 82 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile);
82 83
83 return GetAllSignedInDevices(extension_id, 84 return GetAllSignedinDevices(extension_id,
84 pss, 85 pss,
85 extension_prefs); 86 extension_prefs);
86 } 87 }
87 88
89 bool SignedinDevicesGetFunction::RunImpl() {
90 scoped_ptr<api::signedin_devices::Get::Params> params(
91 api::signedin_devices::Get::Params::Create(*args_));
92 EXTENSION_FUNCTION_VALIDATE(params.get());
93
94 bool is_local = params->is_local.get() ? *params->is_local : false;
95
96 if (is_local) {
97 // TODO(lipalani): Set the device info for local device.
98 base::ListValue* result = new base::ListValue();
99 SetResult(result);
100 return true;
101 }
102
103 ScopedVector<DeviceInfo> devices = GetAllSignedinDevices(extension_id(),
104 profile());
105
106 scoped_ptr<base::ListValue> result(new base::ListValue());
107
108 for (ScopedVector<DeviceInfo>::const_iterator it = devices.begin();
109 it != devices.end();
110 ++it) {
111 result->Append((*it)->ToValue());
112 }
113
114 SetResult(result.release());
115 return true;
116 }
117
88 } // namespace extensions 118 } // namespace extensions
89 119
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698