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

Side by Side Diff: chrome/browser/sync/glue/local_device_info_provider_impl.cc

Issue 594643003: Device info datatype should be moved to components/sync_driver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed CR feedback Created 6 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/bind.h"
5 #include "chrome/browser/sync/glue/local_device_info_provider_impl.h" 6 #include "chrome/browser/sync/glue/local_device_info_provider_impl.h"
7 #include "chrome/common/chrome_version_info.h"
8 #include "ui/base/device_form_factor.h"
6 9
7 namespace browser_sync { 10 namespace browser_sync {
8 11
12 namespace {
13
14 // Converts VersionInfo::Channel to string for user-agent string.
15 std::string ChannelToString(chrome::VersionInfo::Channel channel) {
16 switch (channel) {
17 case chrome::VersionInfo::CHANNEL_UNKNOWN:
18 return "unknown";
19 case chrome::VersionInfo::CHANNEL_CANARY:
20 return "canary";
21 case chrome::VersionInfo::CHANNEL_DEV:
22 return "dev";
23 case chrome::VersionInfo::CHANNEL_BETA:
24 return "beta";
25 case chrome::VersionInfo::CHANNEL_STABLE:
26 return "stable";
27 default:
28 NOTREACHED();
29 return "unknown";
30 }
31 }
32
33 #if defined(OS_ANDROID)
34 bool IsTabletUI() {
35 return ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET;
36 }
37 #endif
38
39 sync_pb::SyncEnums::DeviceType GetLocalDeviceType() {
40 #if defined(OS_CHROMEOS)
41 return sync_pb::SyncEnums_DeviceType_TYPE_CROS;
42 #elif defined(OS_LINUX)
43 return sync_pb::SyncEnums_DeviceType_TYPE_LINUX;
44 #elif defined(OS_MACOSX)
45 return sync_pb::SyncEnums_DeviceType_TYPE_MAC;
46 #elif defined(OS_WIN)
47 return sync_pb::SyncEnums_DeviceType_TYPE_WIN;
48 #elif defined(OS_ANDROID)
49 return IsTabletUI() ? sync_pb::SyncEnums_DeviceType_TYPE_TABLET
50 : sync_pb::SyncEnums_DeviceType_TYPE_PHONE;
51 #else
52 return sync_pb::SyncEnums_DeviceType_TYPE_OTHER;
53 #endif
54 }
55
56 } // namespace
57
9 LocalDeviceInfoProviderImpl::LocalDeviceInfoProviderImpl() 58 LocalDeviceInfoProviderImpl::LocalDeviceInfoProviderImpl()
10 : weak_factory_(this) { 59 : weak_factory_(this) {
11 } 60 }
12 61
13 LocalDeviceInfoProviderImpl::~LocalDeviceInfoProviderImpl() { 62 LocalDeviceInfoProviderImpl::~LocalDeviceInfoProviderImpl() {
14 } 63 }
15 64
65 // static.
66 std::string LocalDeviceInfoProviderImpl::MakeUserAgentForSyncApi(
67 const chrome::VersionInfo& version_info) {
68 std::string user_agent;
69 user_agent = "Chrome ";
70 #if defined(OS_WIN)
71 user_agent += "WIN ";
72 #elif defined(OS_CHROMEOS)
73 user_agent += "CROS ";
74 #elif defined(OS_ANDROID)
75 if (IsTabletUI())
76 user_agent += "ANDROID-TABLET ";
77 else
78 user_agent += "ANDROID-PHONE ";
79 #elif defined(OS_LINUX)
80 user_agent += "LINUX ";
81 #elif defined(OS_FREEBSD)
82 user_agent += "FREEBSD ";
83 #elif defined(OS_OPENBSD)
84 user_agent += "OPENBSD ";
85 #elif defined(OS_MACOSX)
86 user_agent += "MAC ";
87 #endif
88 if (!version_info.is_valid()) {
89 DLOG(ERROR) << "Unable to create chrome::VersionInfo object";
90 return user_agent;
91 }
92
93 user_agent += version_info.Version();
94 user_agent += " (" + version_info.LastChange() + ")";
95 if (!version_info.IsOfficialBuild()) {
96 user_agent += "-devel";
97 } else {
98 user_agent +=
99 " channel(" + ChannelToString(version_info.GetChannel()) + ")";
100 }
101
102 return user_agent;
103 }
104
16 const DeviceInfo* 105 const DeviceInfo*
17 LocalDeviceInfoProviderImpl::GetLocalDeviceInfo() const { 106 LocalDeviceInfoProviderImpl::GetLocalDeviceInfo() const {
18 return local_device_info_.get(); 107 return local_device_info_.get();
19 } 108 }
20 109
21 std::string LocalDeviceInfoProviderImpl::GetLocalSyncCacheGUID() const { 110 std::string LocalDeviceInfoProviderImpl::GetLocalSyncCacheGUID() const {
22 return cache_guid_; 111 return cache_guid_;
23 } 112 }
24 113
25 scoped_ptr<LocalDeviceInfoProvider::Subscription> 114 scoped_ptr<LocalDeviceInfoProvider::Subscription>
26 LocalDeviceInfoProviderImpl::RegisterOnInitializedCallback( 115 LocalDeviceInfoProviderImpl::RegisterOnInitializedCallback(
27 const base::Closure& callback) { 116 const base::Closure& callback) {
28 DCHECK(!local_device_info_.get()); 117 DCHECK(!local_device_info_.get());
29 return callback_list_.Add(callback); 118 return callback_list_.Add(callback);
30 } 119 }
31 120
32 void LocalDeviceInfoProviderImpl::Initialize( 121 void LocalDeviceInfoProviderImpl::Initialize(
33 const std::string& cache_guid, const std::string& signin_scoped_device_id) { 122 const std::string& cache_guid, const std::string& signin_scoped_device_id) {
34 DCHECK(!cache_guid.empty()); 123 DCHECK(!cache_guid.empty());
35 cache_guid_ = cache_guid; 124 cache_guid_ = cache_guid;
36 DeviceInfo::CreateLocalDeviceInfo( 125
37 cache_guid_, 126 DeviceInfo::GetClientName(
38 signin_scoped_device_id,
39 base::Bind(&LocalDeviceInfoProviderImpl::InitializeContinuation, 127 base::Bind(&LocalDeviceInfoProviderImpl::InitializeContinuation,
40 weak_factory_.GetWeakPtr())); 128 weak_factory_.GetWeakPtr(),
129 cache_guid,
130 signin_scoped_device_id));
41 } 131 }
42 132
43 void LocalDeviceInfoProviderImpl::InitializeContinuation( 133 void LocalDeviceInfoProviderImpl::InitializeContinuation(
44 const DeviceInfo& local_info) { 134 const std::string& guid,
45 // Copy constructor is disallowed in DeviceInfo, construct a new one from 135 const std::string& signin_scoped_device_id,
46 // the fields passed in local_info. 136 const std::string& session_name) {
47 local_device_info_.reset( 137 chrome::VersionInfo version_info;
48 new DeviceInfo( 138
49 local_info.guid(), 139 local_device_info_.reset(new DeviceInfo(guid,
50 local_info.client_name(), 140 session_name,
51 local_info.chrome_version(), 141 version_info.CreateVersionString(),
52 local_info.sync_user_agent(), 142 MakeUserAgentForSyncApi(version_info),
53 local_info.device_type(), 143 GetLocalDeviceType(),
54 local_info.signin_scoped_device_id())); 144 signin_scoped_device_id));
55 145
56 // Notify observers. 146 // Notify observers.
57 callback_list_.Notify(); 147 callback_list_.Notify();
58 } 148 }
59 149
60 } // namespace browser_sync 150 } // namespace browser_sync
61 151
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698