Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(530)

Side by Side Diff: components/sync_driver/sync_util.cc

Issue 1308313003: Componentize chrome/common/sync_util (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/sync_driver/sync_util.h ('k') | components/sync_driver/sync_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "components/sync_driver/sync_driver_switches.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "components/version_info/version_info.h"
12 #include "url/gurl.h" 10 #include "url/gurl.h"
13 11
14 namespace {
15
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";
32 }
33 }
34 } // namespace
35
36 namespace internal { 12 namespace internal {
37 const char* kSyncServerUrl = "https://clients4.google.com/chrome-sync"; 13 const char* kSyncServerUrl = "https://clients4.google.com/chrome-sync";
38 14
39 const char* kSyncDevServerUrl = "https://clients4.google.com/chrome-sync/dev"; 15 const char* kSyncDevServerUrl = "https://clients4.google.com/chrome-sync/dev";
40 } // namespace internal 16 } // namespace internal
41 17
42 GURL GetSyncServiceURL(const base::CommandLine& command_line) { 18 GURL GetSyncServiceURL(const base::CommandLine& command_line,
19 version_info::Channel channel) {
43 // By default, dev, canary, and unbranded Chromium users will go to the 20 // By default, dev, canary, and unbranded Chromium users will go to the
44 // development servers. Development servers have more features than standard 21 // development servers. Development servers have more features than standard
45 // sync servers. Users with officially-branded Chrome stable and beta builds 22 // sync servers. Users with officially-branded Chrome stable and beta builds
46 // will go to the standard sync servers. 23 // will go to the standard sync servers.
47 GURL result(internal::kSyncDevServerUrl); 24 GURL result(internal::kSyncDevServerUrl);
48 25
49 version_info::Channel channel = chrome::GetChannel();
50 if (channel == version_info::Channel::STABLE || 26 if (channel == version_info::Channel::STABLE ||
51 channel == version_info::Channel::BETA) { 27 channel == version_info::Channel::BETA) {
52 result = GURL(internal::kSyncServerUrl); 28 result = GURL(internal::kSyncServerUrl);
53 } 29 }
54 30
55 // Override the sync server URL from the command-line, if sync server 31 // Override the sync server URL from the command-line, if sync server
56 // command-line argument exists. 32 // command-line argument exists.
57 if (command_line.HasSwitch(switches::kSyncServiceURL)) { 33 if (command_line.HasSwitch(switches::kSyncServiceURL)) {
58 std::string value( 34 std::string value(
59 command_line.GetSwitchValueASCII(switches::kSyncServiceURL)); 35 command_line.GetSwitchValueASCII(switches::kSyncServiceURL));
60 if (!value.empty()) { 36 if (!value.empty()) {
61 GURL custom_sync_url(value); 37 GURL custom_sync_url(value);
62 if (custom_sync_url.is_valid()) { 38 if (custom_sync_url.is_valid()) {
63 result = custom_sync_url; 39 result = custom_sync_url;
64 } else { 40 } else {
65 LOG(WARNING) << "The following sync URL specified at the command-line " 41 LOG(WARNING) << "The following sync URL specified at the command-line "
66 << "is invalid: " << value; 42 << "is invalid: " << value;
67 } 43 }
68 } 44 }
69 } 45 }
70 return result; 46 return result;
71 } 47 }
72 48
73 std::string MakeDesktopUserAgentForSync() { 49 std::string MakeDesktopUserAgentForSync(version_info::Channel channel) {
74 std::string system = ""; 50 std::string system = "";
75 #if defined(OS_WIN) 51 #if defined(OS_WIN)
76 system = "WIN "; 52 system = "WIN ";
77 #elif defined(OS_LINUX) 53 #elif defined(OS_LINUX)
78 system = "LINUX "; 54 system = "LINUX ";
79 #elif defined(OS_FREEBSD) 55 #elif defined(OS_FREEBSD)
80 system = "FREEBSD "; 56 system = "FREEBSD ";
81 #elif defined(OS_OPENBSD) 57 #elif defined(OS_OPENBSD)
82 system = "OPENBSD "; 58 system = "OPENBSD ";
83 #elif defined(OS_MACOSX) 59 #elif defined(OS_MACOSX)
84 system = "MAC "; 60 system = "MAC ";
85 #endif 61 #endif
86 return MakeUserAgentForSync(system); 62 return MakeUserAgentForSync(system, channel);
87 } 63 }
88 64
89 std::string MakeUserAgentForSync(const std::string& system) { 65 std::string MakeUserAgentForSync(const std::string& system,
66 version_info::Channel channel) {
90 std::string user_agent; 67 std::string user_agent;
91 user_agent = "Chrome "; 68 user_agent = "Chrome ";
92 user_agent += system; 69 user_agent += system;
93 user_agent += version_info::GetVersionNumber(); 70 user_agent += version_info::GetVersionNumber();
94 user_agent += " (" + version_info::GetLastChange() + ")"; 71 user_agent += " (" + version_info::GetLastChange() + ")";
95 if (!version_info::IsOfficialBuild()) { 72 if (!version_info::IsOfficialBuild()) {
96 user_agent += "-devel"; 73 user_agent += "-devel";
97 } else { 74 } else {
98 user_agent += " channel(" + ChannelToString(chrome::GetChannel()) + ")"; 75 user_agent += " channel(" + version_info::GetChannelString(channel) + ")";
99 } 76 }
100 return user_agent; 77 return user_agent;
101 } 78 }
OLDNEW
« no previous file with comments | « components/sync_driver/sync_util.h ('k') | components/sync_driver/sync_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698