Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / sync / glue / local_device_info_provider_impl.cc
blobbd6a18f68fb9ce9490508788f3f502ab6976e87b
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
3 // found in the LICENSE file.
5 #include "base/bind.h"
6 #include "chrome/browser/sync/glue/local_device_info_provider_impl.h"
7 #include "chrome/common/chrome_version_info.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "sync/util/get_session_name.h"
10 #include "ui/base/device_form_factor.h"
12 namespace browser_sync {
14 namespace {
16 // Converts VersionInfo::Channel to string for user-agent string.
17 std::string ChannelToString(chrome::VersionInfo::Channel channel) {
18 switch (channel) {
19 case chrome::VersionInfo::CHANNEL_UNKNOWN:
20 return "unknown";
21 case chrome::VersionInfo::CHANNEL_CANARY:
22 return "canary";
23 case chrome::VersionInfo::CHANNEL_DEV:
24 return "dev";
25 case chrome::VersionInfo::CHANNEL_BETA:
26 return "beta";
27 case chrome::VersionInfo::CHANNEL_STABLE:
28 return "stable";
29 default:
30 NOTREACHED();
31 return "unknown";
35 #if defined(OS_ANDROID)
36 bool IsTabletUI() {
37 return ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET;
39 #endif
41 sync_pb::SyncEnums::DeviceType GetLocalDeviceType() {
42 #if defined(OS_CHROMEOS)
43 return sync_pb::SyncEnums_DeviceType_TYPE_CROS;
44 #elif defined(OS_LINUX)
45 return sync_pb::SyncEnums_DeviceType_TYPE_LINUX;
46 #elif defined(OS_MACOSX)
47 return sync_pb::SyncEnums_DeviceType_TYPE_MAC;
48 #elif defined(OS_WIN)
49 return sync_pb::SyncEnums_DeviceType_TYPE_WIN;
50 #elif defined(OS_ANDROID)
51 return IsTabletUI() ? sync_pb::SyncEnums_DeviceType_TYPE_TABLET
52 : sync_pb::SyncEnums_DeviceType_TYPE_PHONE;
53 #else
54 return sync_pb::SyncEnums_DeviceType_TYPE_OTHER;
55 #endif
58 } // namespace
60 LocalDeviceInfoProviderImpl::LocalDeviceInfoProviderImpl()
61 : weak_factory_(this) {
64 LocalDeviceInfoProviderImpl::~LocalDeviceInfoProviderImpl() {
67 // static.
68 std::string LocalDeviceInfoProviderImpl::MakeUserAgentForSyncApi(
69 const chrome::VersionInfo& version_info) {
70 std::string user_agent;
71 user_agent = "Chrome ";
72 #if defined(OS_WIN)
73 user_agent += "WIN ";
74 #elif defined(OS_CHROMEOS)
75 user_agent += "CROS ";
76 #elif defined(OS_ANDROID)
77 if (IsTabletUI())
78 user_agent += "ANDROID-TABLET ";
79 else
80 user_agent += "ANDROID-PHONE ";
81 #elif defined(OS_LINUX)
82 user_agent += "LINUX ";
83 #elif defined(OS_FREEBSD)
84 user_agent += "FREEBSD ";
85 #elif defined(OS_OPENBSD)
86 user_agent += "OPENBSD ";
87 #elif defined(OS_MACOSX)
88 user_agent += "MAC ";
89 #endif
90 user_agent += version_info.Version();
91 user_agent += " (" + version_info.LastChange() + ")";
92 if (!version_info.IsOfficialBuild()) {
93 user_agent += "-devel";
94 } else {
95 user_agent +=
96 " channel(" + ChannelToString(version_info.GetChannel()) + ")";
99 return user_agent;
102 const sync_driver::DeviceInfo*
103 LocalDeviceInfoProviderImpl::GetLocalDeviceInfo() const {
104 return local_device_info_.get();
107 std::string LocalDeviceInfoProviderImpl::GetLocalSyncCacheGUID() const {
108 return cache_guid_;
111 scoped_ptr<sync_driver::LocalDeviceInfoProvider::Subscription>
112 LocalDeviceInfoProviderImpl::RegisterOnInitializedCallback(
113 const base::Closure& callback) {
114 DCHECK(!local_device_info_.get());
115 return callback_list_.Add(callback);
118 void LocalDeviceInfoProviderImpl::Initialize(
119 const std::string& cache_guid, const std::string& signin_scoped_device_id) {
120 DCHECK(!cache_guid.empty());
121 cache_guid_ = cache_guid;
123 syncer::GetSessionName(
124 content::BrowserThread::GetBlockingPool(),
125 base::Bind(&LocalDeviceInfoProviderImpl::InitializeContinuation,
126 weak_factory_.GetWeakPtr(),
127 cache_guid,
128 signin_scoped_device_id));
131 void LocalDeviceInfoProviderImpl::InitializeContinuation(
132 const std::string& guid,
133 const std::string& signin_scoped_device_id,
134 const std::string& session_name) {
135 chrome::VersionInfo version_info;
137 local_device_info_.reset(
138 new sync_driver::DeviceInfo(guid,
139 session_name,
140 version_info.CreateVersionString(),
141 MakeUserAgentForSyncApi(version_info),
142 GetLocalDeviceType(),
143 signin_scoped_device_id));
145 // Notify observers.
146 callback_list_.Notify();
149 } // namespace browser_sync