Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / components / sync_driver / sync_util.cc
blobe0b0c8dd013a33f4513592b25338d10d76dbd970
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 "components/sync_driver/sync_util.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "components/sync_driver/sync_driver_switches.h"
10 #include "url/gurl.h"
12 namespace internal {
13 const char* kSyncServerUrl = "https://clients4.google.com/chrome-sync";
15 const char* kSyncDevServerUrl = "https://clients4.google.com/chrome-sync/dev";
16 } // namespace internal
18 GURL GetSyncServiceURL(const base::CommandLine& command_line,
19 version_info::Channel channel) {
20 // By default, dev, canary, and unbranded Chromium users will go to the
21 // development servers. Development servers have more features than standard
22 // sync servers. Users with officially-branded Chrome stable and beta builds
23 // will go to the standard sync servers.
24 GURL result(internal::kSyncDevServerUrl);
26 if (channel == version_info::Channel::STABLE ||
27 channel == version_info::Channel::BETA) {
28 result = GURL(internal::kSyncServerUrl);
31 // Override the sync server URL from the command-line, if sync server
32 // command-line argument exists.
33 if (command_line.HasSwitch(switches::kSyncServiceURL)) {
34 std::string value(
35 command_line.GetSwitchValueASCII(switches::kSyncServiceURL));
36 if (!value.empty()) {
37 GURL custom_sync_url(value);
38 if (custom_sync_url.is_valid()) {
39 result = custom_sync_url;
40 } else {
41 LOG(WARNING) << "The following sync URL specified at the command-line "
42 << "is invalid: " << value;
46 return result;
49 std::string MakeDesktopUserAgentForSync(version_info::Channel channel) {
50 std::string system = "";
51 #if defined(OS_WIN)
52 system = "WIN ";
53 #elif defined(OS_LINUX)
54 system = "LINUX ";
55 #elif defined(OS_FREEBSD)
56 system = "FREEBSD ";
57 #elif defined(OS_OPENBSD)
58 system = "OPENBSD ";
59 #elif defined(OS_MACOSX)
60 system = "MAC ";
61 #endif
62 return MakeUserAgentForSync(system, channel);
65 std::string MakeUserAgentForSync(const std::string& system,
66 version_info::Channel channel) {
67 std::string user_agent;
68 user_agent = "Chrome ";
69 user_agent += system;
70 user_agent += version_info::GetVersionNumber();
71 user_agent += " (" + version_info::GetLastChange() + ")";
72 if (!version_info::IsOfficialBuild()) {
73 user_agent += "-devel";
74 } else {
75 user_agent += " channel(" + version_info::GetChannelString(channel) + ")";
77 return user_agent;