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/channel_info.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "components/version_info/version_info.h"
16 // Converts version_info::Channel to string for user-agent string.
17 std::string
ChannelToString(version_info::Channel channel
) {
19 case version_info::Channel::UNKNOWN
:
21 case version_info::Channel::CANARY
:
23 case version_info::Channel::DEV
:
25 case version_info::Channel::BETA
:
27 case version_info::Channel::STABLE
:
37 const char* kSyncServerUrl
= "https://clients4.google.com/chrome-sync";
39 const char* kSyncDevServerUrl
= "https://clients4.google.com/chrome-sync/dev";
40 } // namespace internal
42 GURL
GetSyncServiceURL(const base::CommandLine
& command_line
) {
43 // By default, dev, canary, and unbranded Chromium users will go to the
44 // development servers. Development servers have more features than standard
45 // sync servers. Users with officially-branded Chrome stable and beta builds
46 // will go to the standard sync servers.
47 GURL
result(internal::kSyncDevServerUrl
);
49 version_info::Channel channel
= chrome::GetChannel();
50 if (channel
== version_info::Channel::STABLE
||
51 channel
== version_info::Channel::BETA
) {
52 result
= GURL(internal::kSyncServerUrl
);
55 // Override the sync server URL from the command-line, if sync server
56 // command-line argument exists.
57 if (command_line
.HasSwitch(switches::kSyncServiceURL
)) {
59 command_line
.GetSwitchValueASCII(switches::kSyncServiceURL
));
61 GURL
custom_sync_url(value
);
62 if (custom_sync_url
.is_valid()) {
63 result
= custom_sync_url
;
65 LOG(WARNING
) << "The following sync URL specified at the command-line "
66 << "is invalid: " << value
;
73 std::string
MakeDesktopUserAgentForSync() {
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(system
);
89 std::string
MakeUserAgentForSync(const std::string
& system
) {
90 std::string user_agent
;
91 user_agent
= "Chrome ";
93 user_agent
+= version_info::GetVersionNumber();
94 user_agent
+= " (" + version_info::GetLastChange() + ")";
95 if (!version_info::IsOfficialBuild()) {
96 user_agent
+= "-devel";
98 user_agent
+= " channel(" + ChannelToString(chrome::GetChannel()) + ")";