| 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 "chrome/common/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/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
| 10 #include "chrome/common/chrome_version_info.h" | 10 #include "chrome/common/chrome_version_info.h" |
| 11 #include "url/gurl.h" | 11 #include "url/gurl.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 // Converts VersionInfo::Channel to string for user-agent string. | 15 // Converts version_info::Channel to string for user-agent string. |
| 16 std::string ChannelToString(chrome::VersionInfo::Channel channel) { | 16 std::string ChannelToString(version_info::Channel channel) { |
| 17 switch (channel) { | 17 switch (channel) { |
| 18 case chrome::VersionInfo::CHANNEL_UNKNOWN: | 18 case version_info::CHANNEL_UNKNOWN: |
| 19 return "unknown"; | 19 return "unknown"; |
| 20 case chrome::VersionInfo::CHANNEL_CANARY: | 20 case version_info::CHANNEL_CANARY: |
| 21 return "canary"; | 21 return "canary"; |
| 22 case chrome::VersionInfo::CHANNEL_DEV: | 22 case version_info::CHANNEL_DEV: |
| 23 return "dev"; | 23 return "dev"; |
| 24 case chrome::VersionInfo::CHANNEL_BETA: | 24 case version_info::CHANNEL_BETA: |
| 25 return "beta"; | 25 return "beta"; |
| 26 case chrome::VersionInfo::CHANNEL_STABLE: | 26 case version_info::CHANNEL_STABLE: |
| 27 return "stable"; | 27 return "stable"; |
| 28 default: | 28 default: |
| 29 NOTREACHED(); | 29 NOTREACHED(); |
| 30 return "unknown"; | 30 return "unknown"; |
| 31 } | 31 } |
| 32 } | 32 } |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 namespace internal { | 35 namespace internal { |
| 36 const char* kSyncServerUrl = "https://clients4.google.com/chrome-sync"; | 36 const char* kSyncServerUrl = "https://clients4.google.com/chrome-sync"; |
| 37 | 37 |
| 38 const char* kSyncDevServerUrl = "https://clients4.google.com/chrome-sync/dev"; | 38 const char* kSyncDevServerUrl = "https://clients4.google.com/chrome-sync/dev"; |
| 39 } // namespace internal | 39 } // namespace internal |
| 40 | 40 |
| 41 GURL GetSyncServiceURL(const base::CommandLine& command_line) { | 41 GURL GetSyncServiceURL(const base::CommandLine& command_line) { |
| 42 // By default, dev, canary, and unbranded Chromium users will go to the | 42 // By default, dev, canary, and unbranded Chromium users will go to the |
| 43 // development servers. Development servers have more features than standard | 43 // development servers. Development servers have more features than standard |
| 44 // sync servers. Users with officially-branded Chrome stable and beta builds | 44 // sync servers. Users with officially-branded Chrome stable and beta builds |
| 45 // will go to the standard sync servers. | 45 // will go to the standard sync servers. |
| 46 GURL result(internal::kSyncDevServerUrl); | 46 GURL result(internal::kSyncDevServerUrl); |
| 47 | 47 |
| 48 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 48 version_info::Channel channel = chrome::VersionInfo::GetChannel(); |
| 49 if (channel == chrome::VersionInfo::CHANNEL_STABLE || | 49 if (channel == version_info::CHANNEL_STABLE || |
| 50 channel == chrome::VersionInfo::CHANNEL_BETA) { | 50 channel == version_info::CHANNEL_BETA) { |
| 51 result = GURL(internal::kSyncServerUrl); | 51 result = GURL(internal::kSyncServerUrl); |
| 52 } | 52 } |
| 53 | 53 |
| 54 // 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 |
| 55 // command-line argument exists. | 55 // command-line argument exists. |
| 56 if (command_line.HasSwitch(switches::kSyncServiceURL)) { | 56 if (command_line.HasSwitch(switches::kSyncServiceURL)) { |
| 57 std::string value( | 57 std::string value( |
| 58 command_line.GetSwitchValueASCII(switches::kSyncServiceURL)); | 58 command_line.GetSwitchValueASCII(switches::kSyncServiceURL)); |
| 59 if (!value.empty()) { | 59 if (!value.empty()) { |
| 60 GURL custom_sync_url(value); | 60 GURL custom_sync_url(value); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 user_agent += version_info.Version(); | 94 user_agent += version_info.Version(); |
| 95 user_agent += " (" + version_info.LastChange() + ")"; | 95 user_agent += " (" + version_info.LastChange() + ")"; |
| 96 if (!version_info.IsOfficialBuild()) { | 96 if (!version_info.IsOfficialBuild()) { |
| 97 user_agent += "-devel"; | 97 user_agent += "-devel"; |
| 98 } else { | 98 } else { |
| 99 user_agent += | 99 user_agent += |
| 100 " channel(" + ChannelToString(version_info.GetChannel()) + ")"; | 100 " channel(" + ChannelToString(version_info.GetChannel()) + ")"; |
| 101 } | 101 } |
| 102 return user_agent; | 102 return user_agent; |
| 103 } | 103 } |
| OLD | NEW |