Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / remoting / test / app_remoting_service_urls.cc
blob87432a60cdee8f030894a9beaf83d5494d4dba46
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
3 // found in the LICENSE file.
5 #include "remoting/test/app_remoting_service_urls.h"
7 #include "base/logging.h"
8 #include "base/strings/stringprintf.h"
10 namespace {
11 // The placeholder is the environment endpoint qualifier. No trailing slash
12 // is added as it will be appended as needed later.
13 const char kAppRemotingTestEndpointBase[] =
14 "https://www-googleapis-test.sandbox.google.com/appremoting/%s";
15 const char kAppRemotingDevEndpointQualifier[] = "v1beta1_dev";
16 const char kAppRemotingTestEndpointQualifier[] = "v1beta1";
17 const char kAppRemotingStagingEndpointQualifier[] = "v1beta1_staging";
19 // Placeholder value is for the Application ID.
20 const char kRunApplicationApi[] = "applications/%s/run";
22 // First placeholder value is for the Application ID. Second placeholder is for
23 // the Host ID to report the issue for.
24 const char kReportIssueApi[] = "applications/%s/hosts/%s/reportIssue";
25 } // namespace
27 namespace remoting {
28 namespace test {
30 bool IsSupportedServiceEnvironment(ServiceEnvironment service_environment) {
31 return (service_environment >= 0 &&
32 service_environment < kUnknownEnvironment);
35 std::string GetBaseUrl(ServiceEnvironment service_environment) {
36 std::string base_service_url;
38 const char* environment_qualifier = nullptr;
39 switch (service_environment) {
40 case kDeveloperEnvironment:
41 environment_qualifier = kAppRemotingDevEndpointQualifier;
42 break;
44 case kTestingEnvironment:
45 environment_qualifier = kAppRemotingTestEndpointQualifier;
46 break;
48 case kStagingEnvironment:
49 environment_qualifier = kAppRemotingStagingEndpointQualifier;
50 break;
52 default:
53 NOTREACHED();
56 if (environment_qualifier) {
57 base_service_url =
58 base::StringPrintf(kAppRemotingTestEndpointBase, environment_qualifier);
61 return base_service_url;
64 std::string GetRunApplicationUrl(const std::string& extension_id,
65 ServiceEnvironment service_environment) {
66 std::string service_url;
67 if (!IsSupportedServiceEnvironment(service_environment)) {
68 return service_url;
71 service_url = GetBaseUrl(service_environment);
72 if (!service_url.empty()) {
73 std::string api_string =
74 base::StringPrintf(kRunApplicationApi, extension_id.c_str());
75 service_url =
76 base::StringPrintf("%s/%s", service_url.c_str(), api_string.c_str());
79 return service_url;
82 std::string GetReportIssueUrl(const std::string& extension_id,
83 const std::string& host_id,
84 ServiceEnvironment service_environment) {
85 std::string service_url;
86 if (!IsSupportedServiceEnvironment(service_environment)) {
87 return service_url;
90 service_url = GetBaseUrl(service_environment);
91 if (!service_url.empty()) {
92 std::string api_string = base::StringPrintf(
93 kReportIssueApi, extension_id.c_str(), host_id.c_str());
94 service_url =
95 base::StringPrintf("%s/%s", service_url.c_str(), api_string.c_str());
98 return service_url;
101 } // namespace test
102 } // namespace remoting