OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "components/cloud_devices/common/cloud_devices_urls.h" | 5 #include "components/cloud_devices/common/cloud_devices_urls.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "components/cloud_devices/common/cloud_devices_switches.h" | 10 #include "components/cloud_devices/common/cloud_devices_switches.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 const char kCloudPrintURL[] = "https://www.google.com/cloudprint"; | 33 const char kCloudPrintURL[] = "https://www.google.com/cloudprint"; |
34 | 34 |
35 const char kCloudDevicesUrl[] = "https://www.googleapis.com/clouddevices/v1"; | 35 const char kCloudDevicesUrl[] = "https://www.googleapis.com/clouddevices/v1"; |
36 | 36 |
37 } | 37 } |
38 | 38 |
39 // Returns the root service URL for the cloud print service. The default is to | 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 | 40 // point at the Google Cloud Print service. This can be overridden by the |
41 // command line or by the user preferences. | 41 // command line or by the user preferences. |
42 GURL GetCloudPrintURL() { | 42 GURL GetCloudPrintURL() { |
43 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 43 const base::CommandLine* command_line = |
| 44 base::CommandLine::ForCurrentProcess(); |
44 GURL cloud_print_url( | 45 GURL cloud_print_url( |
45 command_line->GetSwitchValueASCII(switches::kCloudPrintURL)); | 46 command_line->GetSwitchValueASCII(switches::kCloudPrintURL)); |
46 if (cloud_print_url.is_empty()) | 47 if (cloud_print_url.is_empty()) |
47 cloud_print_url = GURL(kCloudPrintURL); | 48 cloud_print_url = GURL(kCloudPrintURL); |
48 return cloud_print_url; | 49 return cloud_print_url; |
49 } | 50 } |
50 | 51 |
51 GURL GetCloudPrintRelativeURL(const std::string& relative_path) { | 52 GURL GetCloudPrintRelativeURL(const std::string& relative_path) { |
52 GURL url = GetCloudPrintURL(); | 53 GURL url = GetCloudPrintURL(); |
53 std::string path; | 54 std::string path; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } | 96 } |
96 | 97 |
97 GURL GetCloudPrintManageDeviceURL(const std::string& device_id) { | 98 GURL GetCloudPrintManageDeviceURL(const std::string& device_id) { |
98 std::string ref = "printers/" + device_id; | 99 std::string ref = "printers/" + device_id; |
99 GURL::Replacements replacements; | 100 GURL::Replacements replacements; |
100 replacements.SetRefStr(ref); | 101 replacements.SetRefStr(ref); |
101 return GetCloudPrintURL().ReplaceComponents(replacements); | 102 return GetCloudPrintURL().ReplaceComponents(replacements); |
102 } | 103 } |
103 | 104 |
104 GURL GetCloudDevicesURL() { | 105 GURL GetCloudDevicesURL() { |
105 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 106 const base::CommandLine* command_line = |
| 107 base::CommandLine::ForCurrentProcess(); |
106 GURL cloud_print_url( | 108 GURL cloud_print_url( |
107 command_line->GetSwitchValueASCII(switches::kCloudDevicesURL)); | 109 command_line->GetSwitchValueASCII(switches::kCloudDevicesURL)); |
108 if (cloud_print_url.is_empty()) | 110 if (cloud_print_url.is_empty()) |
109 cloud_print_url = GURL(kCloudDevicesUrl); | 111 cloud_print_url = GURL(kCloudDevicesUrl); |
110 return cloud_print_url; | 112 return cloud_print_url; |
111 } | 113 } |
112 | 114 |
113 GURL GetCloudDevicesRelativeURL(const std::string& relative_path) { | 115 GURL GetCloudDevicesRelativeURL(const std::string& relative_path) { |
114 GURL url = GetCloudDevicesURL(); | 116 GURL url = GetCloudDevicesURL(); |
115 std::string path; | 117 std::string path; |
116 const char kURLPathSeparator[] = "/"; | 118 const char kURLPathSeparator[] = "/"; |
117 base::TrimString(url.path(), kURLPathSeparator, &path); | 119 base::TrimString(url.path(), kURLPathSeparator, &path); |
118 std::string trimmed_path; | 120 std::string trimmed_path; |
119 base::TrimString(relative_path, kURLPathSeparator, &trimmed_path); | 121 base::TrimString(relative_path, kURLPathSeparator, &trimmed_path); |
120 path += kURLPathSeparator; | 122 path += kURLPathSeparator; |
121 path += trimmed_path; | 123 path += trimmed_path; |
122 GURL::Replacements replacements; | 124 GURL::Replacements replacements; |
123 replacements.SetPathStr(path); | 125 replacements.SetPathStr(path); |
124 return url.ReplaceComponents(replacements); | 126 return url.ReplaceComponents(replacements); |
125 } | 127 } |
126 | 128 |
127 } // namespace cloud_devices | 129 } // namespace cloud_devices |
OLD | NEW |