Make sure webrtc::VideoSource is released when WebRtcVideoTrackAdapter is destroyed.
[chromium-blink-merge.git] / components / cloud_devices / common / cloud_devices_urls.cc
blob9e1090e3093daf503b9cce9cda887b4a7aab6992
1 // Copyright 2014 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.
5 #include "components/cloud_devices/common/cloud_devices_urls.h"
7 #include "base/command_line.h"
8 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h"
10 #include "components/cloud_devices/common/cloud_devices_switches.h"
11 #include "google_apis/gaia/gaia_urls.h"
12 #include "net/base/url_util.h"
14 namespace cloud_devices {
16 const char kCloudPrintAuthScope[] =
17 "https://www.googleapis.com/auth/cloudprint";
19 const char kCloudDevicesAuthScope[] =
20 "https://www.googleapis.com/auth/clouddevices";
22 const char kCloudPrintLearnMoreURL[] =
23 "https://www.google.com/support/cloudprint";
25 const char kCloudPrintTestPageURL[] =
26 "http://www.google.com/landing/cloudprint/enable.html?print=true";
28 namespace {
30 // Url must not be matched by "urls" section of
31 // cloud_print_app/manifest.json. If it's matched, print driver dialog will
32 // open sign-in page in separate window.
33 const char kCloudPrintURL[] = "https://www.google.com/cloudprint";
35 const char kCloudDevicesUrl[] = "https://www.googleapis.com/clouddevices/v1";
39 // Returns the root service URL for the cloud print service. The default is to
40 // point at the Google Cloud Print service. This can be overridden by the
41 // command line or by the user preferences.
42 GURL GetCloudPrintURL() {
43 const CommandLine* command_line = CommandLine::ForCurrentProcess();
44 GURL cloud_print_url(
45 command_line->GetSwitchValueASCII(switches::kCloudPrintURL));
46 if (cloud_print_url.is_empty())
47 cloud_print_url = GURL(kCloudPrintURL);
48 return cloud_print_url;
51 GURL GetCloudPrintRelativeURL(const std::string& relative_path) {
52 GURL url = GetCloudPrintURL();
53 std::string path;
54 static const char kURLPathSeparator[] = "/";
55 base::TrimString(url.path(), kURLPathSeparator, &path);
56 std::string trimmed_path;
57 base::TrimString(relative_path, kURLPathSeparator, &trimmed_path);
58 path += kURLPathSeparator;
59 path += trimmed_path;
60 GURL::Replacements replacements;
61 replacements.SetPathStr(path);
62 return url.ReplaceComponents(replacements);
65 GURL GetCloudPrintSigninURL() {
66 GURL url(GaiaUrls::GetInstance()->service_login_url());
67 url = net::AppendQueryParameter(url, "service", "cloudprint");
68 url = net::AppendQueryParameter(url, "sarp", "1");
69 std::string continue_str = GetCloudPrintURL().spec();
70 url = net::AppendQueryParameter(url, "continue", continue_str);
71 return url;
74 GURL GetCloudPrintAddAccountURL() {
75 GURL url(GaiaUrls::GetInstance()->add_account_url());
76 url = net::AppendQueryParameter(url, "service", "cloudprint");
77 url = net::AppendQueryParameter(url, "sarp", "1");
78 std::string continue_str = GetCloudPrintURL().spec();
79 url = net::AppendQueryParameter(url, "continue", continue_str);
80 return url;
83 GURL GetCloudPrintEnableURL(const std::string& proxy_id) {
84 GURL url = GetCloudPrintRelativeURL("enable_chrome_connector/enable.html");
85 url = net::AppendQueryParameter(url, "proxy", proxy_id);
86 return url;
89 GURL GetCloudPrintEnableWithSigninURL(const std::string& proxy_id) {
90 GURL url(GaiaUrls::GetInstance()->service_login_url());
91 url = net::AppendQueryParameter(url, "service", "cloudprint");
92 url = net::AppendQueryParameter(url, "sarp", "1");
93 std::string continue_str = GetCloudPrintEnableURL(proxy_id).spec();
94 return net::AppendQueryParameter(url, "continue", continue_str);
97 GURL GetCloudPrintManageDeviceURL(const std::string& device_id) {
98 std::string ref = "printers/" + device_id;
99 GURL::Replacements replacements;
100 replacements.SetRefStr(ref);
101 return GetCloudPrintURL().ReplaceComponents(replacements);
104 GURL GetCloudDevicesURL() {
105 const CommandLine* command_line = CommandLine::ForCurrentProcess();
106 GURL cloud_print_url(
107 command_line->GetSwitchValueASCII(switches::kCloudDevicesURL));
108 if (cloud_print_url.is_empty())
109 cloud_print_url = GURL(kCloudDevicesUrl);
110 return cloud_print_url;
113 GURL GetCloudDevicesRelativeURL(const std::string& relative_path) {
114 GURL url = GetCloudDevicesURL();
115 std::string path;
116 const char kURLPathSeparator[] = "/";
117 base::TrimString(url.path(), kURLPathSeparator, &path);
118 std::string trimmed_path;
119 base::TrimString(relative_path, kURLPathSeparator, &trimmed_path);
120 path += kURLPathSeparator;
121 path += trimmed_path;
122 GURL::Replacements replacements;
123 replacements.SetPathStr(path);
124 return url.ReplaceComponents(replacements);
127 } // namespace cloud_devices