OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/common/sync_util.h" | 5 #include "components/sync_driver/sync_util.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/common/channel_info.h" | 9 //#include "chrome/common/channel_info.h" |
droger
2015/08/25 11:25:43
Delete this line.
Jitu( very slow this week)
2015/08/25 11:39:57
Done.
| |
10 #include "chrome/common/chrome_switches.h" | 10 #include "components/sync_driver/sync_driver_switches.h" |
11 #include "components/version_info/version_info.h" | |
12 #include "url/gurl.h" | 11 #include "url/gurl.h" |
13 | 12 |
14 namespace { | 13 namespace { |
15 | 14 |
16 // Converts version_info::Channel to string for user-agent string. | 15 // Converts version_info::Channel to string for user-agent string. |
17 std::string ChannelToString(version_info::Channel channel) { | 16 std::string ChannelToString(version_info::Channel channel) { |
droger
2015/08/25 11:25:43
Delete this function and use version_info::GetChan
Jitu( very slow this week)
2015/08/25 11:39:57
Done.
| |
18 switch (channel) { | 17 switch (channel) { |
19 case version_info::Channel::UNKNOWN: | 18 case version_info::Channel::UNKNOWN: |
20 return "unknown"; | 19 return "unknown"; |
21 case version_info::Channel::CANARY: | 20 case version_info::Channel::CANARY: |
22 return "canary"; | 21 return "canary"; |
23 case version_info::Channel::DEV: | 22 case version_info::Channel::DEV: |
24 return "dev"; | 23 return "dev"; |
25 case version_info::Channel::BETA: | 24 case version_info::Channel::BETA: |
26 return "beta"; | 25 return "beta"; |
27 case version_info::Channel::STABLE: | 26 case version_info::Channel::STABLE: |
28 return "stable"; | 27 return "stable"; |
29 default: | 28 default: |
30 NOTREACHED(); | 29 NOTREACHED(); |
31 return "unknown"; | 30 return "unknown"; |
32 } | 31 } |
33 } | 32 } |
34 } // namespace | 33 } // namespace |
35 | 34 |
36 namespace internal { | 35 namespace internal { |
37 const char* kSyncServerUrl = "https://clients4.google.com/chrome-sync"; | 36 const char* kSyncServerUrl = "https://clients4.google.com/chrome-sync"; |
38 | 37 |
39 const char* kSyncDevServerUrl = "https://clients4.google.com/chrome-sync/dev"; | 38 const char* kSyncDevServerUrl = "https://clients4.google.com/chrome-sync/dev"; |
40 } // namespace internal | 39 } // namespace internal |
41 | 40 |
42 GURL GetSyncServiceURL(const base::CommandLine& command_line) { | 41 GURL GetSyncServiceURL(const base::CommandLine& command_line, |
42 version_info::Channel channel) { | |
43 // By default, dev, canary, and unbranded Chromium users will go to the | 43 // By default, dev, canary, and unbranded Chromium users will go to the |
44 // development servers. Development servers have more features than standard | 44 // development servers. Development servers have more features than standard |
45 // sync servers. Users with officially-branded Chrome stable and beta builds | 45 // sync servers. Users with officially-branded Chrome stable and beta builds |
46 // will go to the standard sync servers. | 46 // will go to the standard sync servers. |
47 GURL result(internal::kSyncDevServerUrl); | 47 GURL result(internal::kSyncDevServerUrl); |
48 | 48 |
49 version_info::Channel channel = chrome::GetChannel(); | |
50 if (channel == version_info::Channel::STABLE || | 49 if (channel == version_info::Channel::STABLE || |
51 channel == version_info::Channel::BETA) { | 50 channel == version_info::Channel::BETA) { |
52 result = GURL(internal::kSyncServerUrl); | 51 result = GURL(internal::kSyncServerUrl); |
53 } | 52 } |
54 | 53 |
55 // Override the sync server URL from the command-line, if sync server | 54 // Override the sync server URL from the command-line, if sync server |
56 // command-line argument exists. | 55 // command-line argument exists. |
57 if (command_line.HasSwitch(switches::kSyncServiceURL)) { | 56 if (command_line.HasSwitch(switches::kSyncServiceURL)) { |
58 std::string value( | 57 std::string value( |
59 command_line.GetSwitchValueASCII(switches::kSyncServiceURL)); | 58 command_line.GetSwitchValueASCII(switches::kSyncServiceURL)); |
60 if (!value.empty()) { | 59 if (!value.empty()) { |
61 GURL custom_sync_url(value); | 60 GURL custom_sync_url(value); |
62 if (custom_sync_url.is_valid()) { | 61 if (custom_sync_url.is_valid()) { |
63 result = custom_sync_url; | 62 result = custom_sync_url; |
64 } else { | 63 } else { |
65 LOG(WARNING) << "The following sync URL specified at the command-line " | 64 LOG(WARNING) << "The following sync URL specified at the command-line " |
66 << "is invalid: " << value; | 65 << "is invalid: " << value; |
67 } | 66 } |
68 } | 67 } |
69 } | 68 } |
70 return result; | 69 return result; |
71 } | 70 } |
72 | 71 |
73 std::string MakeDesktopUserAgentForSync() { | 72 std::string MakeDesktopUserAgentForSync(version_info::Channel channel) { |
74 std::string system = ""; | 73 std::string system = ""; |
75 #if defined(OS_WIN) | 74 #if defined(OS_WIN) |
76 system = "WIN "; | 75 system = "WIN "; |
77 #elif defined(OS_LINUX) | 76 #elif defined(OS_LINUX) |
78 system = "LINUX "; | 77 system = "LINUX "; |
79 #elif defined(OS_FREEBSD) | 78 #elif defined(OS_FREEBSD) |
80 system = "FREEBSD "; | 79 system = "FREEBSD "; |
81 #elif defined(OS_OPENBSD) | 80 #elif defined(OS_OPENBSD) |
82 system = "OPENBSD "; | 81 system = "OPENBSD "; |
83 #elif defined(OS_MACOSX) | 82 #elif defined(OS_MACOSX) |
84 system = "MAC "; | 83 system = "MAC "; |
85 #endif | 84 #endif |
86 return MakeUserAgentForSync(system); | 85 return MakeUserAgentForSync(system, channel); |
87 } | 86 } |
88 | 87 |
89 std::string MakeUserAgentForSync(const std::string& system) { | 88 std::string MakeUserAgentForSync(const std::string& system, |
89 version_info::Channel channel) { | |
90 std::string user_agent; | 90 std::string user_agent; |
91 user_agent = "Chrome "; | 91 user_agent = "Chrome "; |
92 user_agent += system; | 92 user_agent += system; |
93 user_agent += version_info::GetVersionNumber(); | 93 user_agent += version_info::GetVersionNumber(); |
94 user_agent += " (" + version_info::GetLastChange() + ")"; | 94 user_agent += " (" + version_info::GetLastChange() + ")"; |
95 if (!version_info::IsOfficialBuild()) { | 95 if (!version_info::IsOfficialBuild()) { |
96 user_agent += "-devel"; | 96 user_agent += "-devel"; |
97 } else { | 97 } else { |
98 user_agent += " channel(" + ChannelToString(chrome::GetChannel()) + ")"; | 98 user_agent += " channel(" + ChannelToString(channel) + ")"; |
99 } | 99 } |
100 return user_agent; | 100 return user_agent; |
101 } | 101 } |
OLD | NEW |