id_mapping_helper.h revision f2477e01787aa58f445919b809d89e252beef54f
1f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// found in the LICENSE file.
4f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
5f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#ifndef CHROME_BROWSER_EXTENSIONS_API_SIGNED_IN_DEVICES_ID_MAPPING_HELPER_H__
6f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#define CHROME_BROWSER_EXTENSIONS_API_SIGNED_IN_DEVICES_ID_MAPPING_HELPER_H__
7f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
8f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include <string>
9f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include <vector>
10f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
11f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/memory/scoped_ptr.h"
12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
13f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace base {
14f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class DictionaryValue;
15f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}  // namespace base
16f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace browser_sync {
18f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class DeviceInfo;
19f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}  // namespace browser_sync
20f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
21f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class Profile;
22f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
23f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace extensions {
24f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// In order to not expose unique GUIDs for devices to third pary apps,
26f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// the unique GUIDs are mapped to local ids and local ids are exposed to apps.
27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// The functions in this file are helper routines to do the mapping.
28f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
29f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Gets public id from GUID, given a dictionary that has the mapping.
30f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// If it cannot find the GUID the public id returned will be empty.
31f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)std::string GetPublicIdFromGUID(
32f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const base::DictionaryValue& id_mapping,
33f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const std::string& guid);
34f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
35f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Gets the GUID from public id given a dictionary that has the mapping.
36f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// If it cannot find the public id, the GUID returned will be empty.
37f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)std::string GetGUIDFromPublicId(
38f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const base::DictionaryValue& id_mapping,
39f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const std::string& id);
40f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
41f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Creates public id for devices that don't have a public id. To create mappings
42f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// from scratch an empty dictionary must be passed. The dictionary will be
43f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// updated with the mappings. The |device_info| objects will also be updated
44f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// with the public ids.
45f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// The dictionary would have the public id as the key and the
46f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// device guid as the value.
47f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void CreateMappingForUnmappedDevices(
48f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    std::vector<browser_sync::DeviceInfo*>* device_info,
49f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    base::DictionaryValue* value);
50f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
51f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Gets the device info for a given client id. If the device is not found
52f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// the returned pointer would be null.
53f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)scoped_ptr<browser_sync::DeviceInfo> GetDeviceInfoForClientId(
54f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const std::string& client_id,
55f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const std::string& extension_id,
56f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    Profile* profile);
57f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
58f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}  // namespace extensions
59f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
60f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif  // CHROME_BROWSER_EXTENSIONS_API_SIGNED_IN_DEVICES_ID_MAPPING_HELPER_H__
61