Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / sync / glue / device_info.h
blobd94a9bc2b5637156d3206d73259aa6adfc6b29c3
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_H_
6 #define CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/bind.h"
12 #include "sync/protocol/sync.pb.h"
14 namespace base {
15 class DictionaryValue;
18 namespace chrome {
19 class VersionInfo;
22 namespace browser_sync {
24 // A class that holds information regarding the properties of a device.
25 class DeviceInfo {
26 public:
27 DeviceInfo(const std::string& guid,
28 const std::string& client_name,
29 const std::string& chrome_version,
30 const std::string& sync_user_agent,
31 const sync_pb::SyncEnums::DeviceType device_type);
32 ~DeviceInfo();
34 // Sync specific unique identifier for the device. Note if a device
35 // is wiped and sync is set up again this id WILL be different.
36 // The same device might have more than 1 guid if the device has multiple
37 // accounts syncing.
38 const std::string& guid() const;
40 // The host name for the client.
41 const std::string& client_name() const;
43 // Chrome version string.
44 const std::string& chrome_version() const;
46 // The user agent is the combination of OS type, chrome version and which
47 // channel of chrome(stable or beta). For more information see
48 // |DeviceInfo::MakeUserAgentForSyncApi|.
49 const std::string& sync_user_agent() const;
51 // Third party visible id for the device. See |public_id_| for more details.
52 const std::string& public_id() const;
54 // Device Type.
55 sync_pb::SyncEnums::DeviceType device_type() const;
57 // Gets the OS in string form.
58 std::string GetOSString() const;
60 // Gets the device type in string form.
61 std::string GetDeviceTypeString() const;
63 // Compares this object's fields with another's.
64 bool Equals(const DeviceInfo& other) const;
66 // Apps can set ids for a device that is meaningful to them but
67 // not unique enough so the user can be tracked. Exposing |guid|
68 // would lead to a stable unique id for a device which can potentially
69 // be used for tracking.
70 void set_public_id(std::string id);
72 // Converts the |DeviceInfo| values to a JS friendly DictionaryValue,
73 // which extension APIs can expose to third party apps.
74 base::DictionaryValue* ToValue();
76 static sync_pb::SyncEnums::DeviceType GetLocalDeviceType();
78 // Creates a |DeviceInfo| object representing the local device and passes
79 // it as parameter to the callback.
80 static void CreateLocalDeviceInfo(
81 const std::string& guid,
82 base::Callback<void(const DeviceInfo& local_info)> callback);
84 // Gets the local device name and passes it as a parameter to callback.
85 static void GetClientName(
86 base::Callback<void(const std::string& local_info)> callback);
88 // Helper to construct a user agent string (ASCII) suitable for use by
89 // the syncapi for any HTTP communication. This string is used by the sync
90 // backend for classifying client types when calculating statistics.
91 static std::string MakeUserAgentForSyncApi(
92 const chrome::VersionInfo& version_info);
94 private:
95 static void GetClientNameContinuation(
96 base::Callback<void(const std::string& local_info)> callback,
97 const std::string& session_name);
99 static void CreateLocalDeviceInfoContinuation(
100 const std::string& guid,
101 base::Callback<void(const DeviceInfo& local_info)> callback,
102 const std::string& session_name);
104 const std::string guid_;
106 const std::string client_name_;
108 const std::string chrome_version_;
110 const std::string sync_user_agent_;
112 const sync_pb::SyncEnums::DeviceType device_type_;
114 // Exposing |guid| would lead to a stable unique id for a device which
115 // can potentially be used for tracking. Public ids are privacy safe
116 // ids in that the same device will have different id for different apps
117 // and they are also reset when app/extension is uninstalled.
118 std::string public_id_;
120 DISALLOW_COPY_AND_ASSIGN(DeviceInfo);
123 } // namespace browser_sync
125 #endif // CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_H_