File: sync_util.cc

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (109 lines) | stat: -rw-r--r-- 3,207 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/sync/driver/sync_util.h"

#include "base/command_line.h"
#include "base/logging.h"
#include "build/build_config.h"
#include "components/sync/driver/sync_driver_switches.h"
#include "url/gurl.h"

namespace {

// Returns string that represents system in UserAgent.
std::string GetSystemString(bool is_tablet) {
  std::string system;
#if defined(OS_CHROMEOS)
  system = "CROS ";
#elif defined(OS_ANDROID)
  if (is_tablet) {
    system = "ANDROID-TABLET ";
  } else {
    system = "ANDROID-PHONE ";
  }
#elif defined(OS_IOS)
  if (is_tablet) {
    system = "IOS-TABLET ";
  } else {
    system = "IOS-PHONE ";
  }
#elif defined(OS_WIN)
  system = "WIN ";
#elif defined(OS_LINUX)
  system = "LINUX ";
#elif defined(OS_FREEBSD)
  system = "FREEBSD ";
#elif defined(OS_OPENBSD)
  system = "OPENBSD ";
#elif defined(OS_MACOSX)
  system = "MAC ";
#endif
  return system;
}

}  // namespace

namespace syncer {
namespace internal {

const char* kSyncServerUrl = "https://clients4.google.com/chrome-sync";

const char* kSyncDevServerUrl = "https://clients4.google.com/chrome-sync/dev";

std::string FormatUserAgentForSync(const std::string& system,
                                   version_info::Channel channel) {
  std::string user_agent;
  user_agent = "Chrome ";
  user_agent += system;
  user_agent += version_info::GetVersionNumber();
  user_agent += " (" + version_info::GetLastChange() + ")";
  if (!version_info::IsOfficialBuild()) {
    user_agent += "-devel";
  } else {
    user_agent += " channel(" + version_info::GetChannelString(channel) + ")";
  }
  return user_agent;
}

}  // namespace internal

GURL GetSyncServiceURL(const base::CommandLine& command_line,
                       version_info::Channel channel) {
  // By default, dev, canary, and unbranded Chromium users will go to the
  // development servers. Development servers have more features than standard
  // sync servers. Users with officially-branded Chrome stable and beta builds
  // will go to the standard sync servers.
  GURL result(internal::kSyncDevServerUrl);

  if (channel == version_info::Channel::STABLE ||
      channel == version_info::Channel::BETA) {
    result = GURL(internal::kSyncServerUrl);
  }

  // Override the sync server URL from the command-line, if sync server
  // command-line argument exists.
  if (command_line.HasSwitch(switches::kSyncServiceURL)) {
    std::string value(
        command_line.GetSwitchValueASCII(switches::kSyncServiceURL));
    if (!value.empty()) {
      GURL custom_sync_url(value);
      if (custom_sync_url.is_valid()) {
        result = custom_sync_url;
      } else {
        LOG(WARNING) << "The following sync URL specified at the command-line "
                     << "is invalid: " << value;
      }
    }
  }
  return result;
}

std::string MakeUserAgentForSync(version_info::Channel channel,
                                 bool is_tablet) {
  std::string system = GetSystemString(is_tablet);
  return internal::FormatUserAgentForSync(system, channel);
}

}  // namespace syncer