Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / common / sync_util.cc
blob3cda52192ff32438818010c1139ad58cc292d88c
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"
11 #include "url/gurl.h"
13 namespace {
15 // Converts VersionInfo::Channel to string for user-agent string.
16 std::string ChannelToString(chrome::VersionInfo::Channel channel) {
17 switch (channel) {
18 case chrome::VersionInfo::CHANNEL_UNKNOWN:
19 return "unknown";
20 case chrome::VersionInfo::CHANNEL_CANARY:
21 return "canary";
22 case chrome::VersionInfo::CHANNEL_DEV:
23 return "dev";
24 case chrome::VersionInfo::CHANNEL_BETA:
25 return "beta";
26 case chrome::VersionInfo::CHANNEL_STABLE:
27 return "stable";
28 default:
29 NOTREACHED();
30 return "unknown";
33 } // namespace
35 namespace internal {
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)) {
57 std::string value(
58 command_line.GetSwitchValueASCII(switches::kSyncServiceURL));
59 if (!value.empty()) {
60 GURL custom_sync_url(value);
61 if (custom_sync_url.is_valid()) {
62 result = custom_sync_url;
63 } else {
64 LOG(WARNING) << "The following sync URL specified at the command-line "
65 << "is invalid: " << value;
69 return result;
72 std::string MakeDesktopUserAgentForSync(
73 const chrome::VersionInfo& version_info) {
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(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 ";
93 user_agent += system;
94 user_agent += version_info.Version();
95 user_agent += " (" + version_info.LastChange() + ")";
96 if (!version_info.IsOfficialBuild()) {
97 user_agent += "-devel";
98 } else {
99 user_agent +=
100 " channel(" + ChannelToString(version_info.GetChannel()) + ")";
102 return user_agent;