Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / chrome / common / sync_util.cc
blobcd2f7e26ff76c7ec98b5bb3ba4db4ae33db26dba
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"
12 #include "url/gurl.h"
14 namespace {
16 // Converts version_info::Channel to string for user-agent string.
17 std::string ChannelToString(version_info::Channel channel) {
18 switch (channel) {
19 case version_info::Channel::UNKNOWN:
20 return "unknown";
21 case version_info::Channel::CANARY:
22 return "canary";
23 case version_info::Channel::DEV:
24 return "dev";
25 case version_info::Channel::BETA:
26 return "beta";
27 case version_info::Channel::STABLE:
28 return "stable";
29 default:
30 NOTREACHED();
31 return "unknown";
34 } // namespace
36 namespace internal {
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)) {
58 std::string value(
59 command_line.GetSwitchValueASCII(switches::kSyncServiceURL));
60 if (!value.empty()) {
61 GURL custom_sync_url(value);
62 if (custom_sync_url.is_valid()) {
63 result = custom_sync_url;
64 } else {
65 LOG(WARNING) << "The following sync URL specified at the command-line "
66 << "is invalid: " << value;
70 return result;
73 std::string MakeDesktopUserAgentForSync() {
74 std::string system = "";
75 #if defined(OS_WIN)
76 system = "WIN ";
77 #elif defined(OS_LINUX)
78 system = "LINUX ";
79 #elif defined(OS_FREEBSD)
80 system = "FREEBSD ";
81 #elif defined(OS_OPENBSD)
82 system = "OPENBSD ";
83 #elif defined(OS_MACOSX)
84 system = "MAC ";
85 #endif
86 return MakeUserAgentForSync(system);
89 std::string MakeUserAgentForSync(const std::string& system) {
90 std::string user_agent;
91 user_agent = "Chrome ";
92 user_agent += system;
93 user_agent += version_info::GetVersionNumber();
94 user_agent += " (" + version_info::GetLastChange() + ")";
95 if (!version_info::IsOfficialBuild()) {
96 user_agent += "-devel";
97 } else {
98 user_agent += " channel(" + ChannelToString(chrome::GetChannel()) + ")";
100 return user_agent;