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"
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";
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
;
44 case kTestingEnvironment
:
45 environment_qualifier
= kAppRemotingTestEndpointQualifier
;
48 case kStagingEnvironment
:
49 environment_qualifier
= kAppRemotingStagingEndpointQualifier
;
56 if (environment_qualifier
) {
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
)) {
71 service_url
= GetBaseUrl(service_environment
);
72 if (!service_url
.empty()) {
73 std::string api_string
=
74 base::StringPrintf(kRunApplicationApi
, extension_id
.c_str());
76 base::StringPrintf("%s/%s", service_url
.c_str(), api_string
.c_str());
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
)) {
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());
95 base::StringPrintf("%s/%s", service_url
.c_str(), api_string
.c_str());
102 } // namespace remoting