OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "components/sync_driver/sync_util.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/logging.h" | |
9 #include "build/build_config.h" | |
10 #include "components/sync_driver/sync_driver_switches.h" | |
11 #include "url/gurl.h" | |
12 | |
13 namespace { | |
14 | |
15 // Returns string that represents system in UserAgent. | |
16 std::string GetSystemString(bool is_tablet) { | |
17 std::string system; | |
18 #if defined(OS_CHROMEOS) | |
19 system = "CROS "; | |
20 #elif defined(OS_ANDROID) | |
21 if (is_tablet) { | |
22 system = "ANDROID-TABLET "; | |
23 } else { | |
24 system = "ANDROID-PHONE "; | |
25 } | |
26 #elif defined(OS_IOS) | |
27 if (is_tablet) { | |
28 system = "IOS-TABLET "; | |
29 } else { | |
30 system = "IOS-PHONE "; | |
31 } | |
32 #elif defined(OS_WIN) | |
33 system = "WIN "; | |
34 #elif defined(OS_LINUX) | |
35 system = "LINUX "; | |
36 #elif defined(OS_FREEBSD) | |
37 system = "FREEBSD "; | |
38 #elif defined(OS_OPENBSD) | |
39 system = "OPENBSD "; | |
40 #elif defined(OS_MACOSX) | |
41 system = "MAC "; | |
42 #endif | |
43 return system; | |
44 } | |
45 | |
46 } // namespace | |
47 | |
48 namespace internal { | |
49 | |
50 const char* kSyncServerUrl = "https://clients4.google.com/chrome-sync"; | |
51 | |
52 const char* kSyncDevServerUrl = "https://clients4.google.com/chrome-sync/dev"; | |
53 | |
54 std::string FormatUserAgentForSync(const std::string& system, | |
55 version_info::Channel channel) { | |
56 std::string user_agent; | |
57 user_agent = "Chrome "; | |
58 user_agent += system; | |
59 user_agent += version_info::GetVersionNumber(); | |
60 user_agent += " (" + version_info::GetLastChange() + ")"; | |
61 if (!version_info::IsOfficialBuild()) { | |
62 user_agent += "-devel"; | |
63 } else { | |
64 user_agent += " channel(" + version_info::GetChannelString(channel) + ")"; | |
65 } | |
66 return user_agent; | |
67 } | |
68 | |
69 } // namespace internal | |
70 | |
71 GURL GetSyncServiceURL(const base::CommandLine& command_line, | |
72 version_info::Channel channel) { | |
73 // By default, dev, canary, and unbranded Chromium users will go to the | |
74 // development servers. Development servers have more features than standard | |
75 // sync servers. Users with officially-branded Chrome stable and beta builds | |
76 // will go to the standard sync servers. | |
77 GURL result(internal::kSyncDevServerUrl); | |
78 | |
79 if (channel == version_info::Channel::STABLE || | |
80 channel == version_info::Channel::BETA) { | |
81 result = GURL(internal::kSyncServerUrl); | |
82 } | |
83 | |
84 // Override the sync server URL from the command-line, if sync server | |
85 // command-line argument exists. | |
86 if (command_line.HasSwitch(switches::kSyncServiceURL)) { | |
87 std::string value( | |
88 command_line.GetSwitchValueASCII(switches::kSyncServiceURL)); | |
89 if (!value.empty()) { | |
90 GURL custom_sync_url(value); | |
91 if (custom_sync_url.is_valid()) { | |
92 result = custom_sync_url; | |
93 } else { | |
94 LOG(WARNING) << "The following sync URL specified at the command-line " | |
95 << "is invalid: " << value; | |
96 } | |
97 } | |
98 } | |
99 return result; | |
100 } | |
101 | |
102 std::string MakeUserAgentForSync(version_info::Channel channel, | |
103 bool is_tablet) { | |
104 std::string system = GetSystemString(is_tablet); | |
105 return internal::FormatUserAgentForSync(system, channel); | |
106 } | |
OLD | NEW |