1 // Copyright 2015 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 "chrome/common/sync_util.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/chrome_version_info.h"
15 // Converts VersionInfo::Channel to string for user-agent string.
16 std::string
ChannelToString(chrome::VersionInfo::Channel channel
) {
18 case chrome::VersionInfo::CHANNEL_UNKNOWN
:
20 case chrome::VersionInfo::CHANNEL_CANARY
:
22 case chrome::VersionInfo::CHANNEL_DEV
:
24 case chrome::VersionInfo::CHANNEL_BETA
:
26 case chrome::VersionInfo::CHANNEL_STABLE
:
36 const char* kSyncServerUrl
= "https://clients4.google.com/chrome-sync";
38 const char* kSyncDevServerUrl
= "https://clients4.google.com/chrome-sync/dev";
39 } // namespace internal
41 GURL
GetSyncServiceURL(const base::CommandLine
& command_line
) {
42 // By default, dev, canary, and unbranded Chromium users will go to the
43 // development servers. Development servers have more features than standard
44 // sync servers. Users with officially-branded Chrome stable and beta builds
45 // will go to the standard sync servers.
46 GURL
result(internal::kSyncDevServerUrl
);
48 chrome::VersionInfo::Channel channel
= chrome::VersionInfo::GetChannel();
49 if (channel
== chrome::VersionInfo::CHANNEL_STABLE
||
50 channel
== chrome::VersionInfo::CHANNEL_BETA
) {
51 result
= GURL(internal::kSyncServerUrl
);
54 // Override the sync server URL from the command-line, if sync server
55 // command-line argument exists.
56 if (command_line
.HasSwitch(switches::kSyncServiceURL
)) {
58 command_line
.GetSwitchValueASCII(switches::kSyncServiceURL
));
60 GURL
custom_sync_url(value
);
61 if (custom_sync_url
.is_valid()) {
62 result
= custom_sync_url
;
64 LOG(WARNING
) << "The following sync URL specified at the command-line "
65 << "is invalid: " << value
;
72 std::string
MakeDesktopUserAgentForSync(
73 const chrome::VersionInfo
& version_info
) {
74 std::string system
= "";
77 #elif defined(OS_LINUX)
79 #elif defined(OS_FREEBSD)
81 #elif defined(OS_OPENBSD)
83 #elif defined(OS_MACOSX)
86 return MakeUserAgentForSync(version_info
, system
);
89 std::string
MakeUserAgentForSync(const chrome::VersionInfo
& version_info
,
90 const std::string
& system
) {
91 std::string user_agent
;
92 user_agent
= "Chrome ";
94 user_agent
+= version_info
.Version();
95 user_agent
+= " (" + version_info
.LastChange() + ")";
96 if (!version_info
.IsOfficialBuild()) {
97 user_agent
+= "-devel";
100 " channel(" + ChannelToString(version_info
.GetChannel()) + ")";