OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "webkit/common/database/database_identifier.h" | 5 #include "webkit/common/database/database_identifier.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "googleurl/src/url_canon.h" | 9 #include "googleurl/src/url_canon.h" |
10 | 10 |
11 namespace webkit_database { | 11 namespace webkit_database { |
12 | 12 |
| 13 // static |
| 14 std::string GetIdentifierFromOrigin(const GURL& origin) { |
| 15 return DatabaseIdentifier::CreateFromOrigin(origin).ToString(); |
| 16 } |
| 17 |
| 18 // static |
| 19 GURL GetOriginFromIdentifier(const std::string& identifier) { |
| 20 return DatabaseIdentifier::Parse(identifier).ToOrigin(); |
| 21 } |
| 22 |
13 static bool SchemeIsUnique(const std::string& scheme) { | 23 static bool SchemeIsUnique(const std::string& scheme) { |
14 return scheme == "about" || scheme == "data" || scheme == "javascript"; | 24 return scheme == "about" || scheme == "data" || scheme == "javascript"; |
15 } | 25 } |
16 | 26 |
17 // static | 27 // static |
18 const DatabaseIdentifier DatabaseIdentifier::UniqueFileIdentifier() { | 28 const DatabaseIdentifier DatabaseIdentifier::UniqueFileIdentifier() { |
19 return DatabaseIdentifier("", "", 0, true, true); | 29 return DatabaseIdentifier("", "", 0, true, true); |
20 } | 30 } |
21 | 31 |
22 // static | 32 // static |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 119 |
110 std::string DatabaseIdentifier::ToString() const { | 120 std::string DatabaseIdentifier::ToString() const { |
111 if (is_file_) | 121 if (is_file_) |
112 return "file__0"; | 122 return "file__0"; |
113 if (is_unique_) | 123 if (is_unique_) |
114 return "__0"; | 124 return "__0"; |
115 return scheme_ + "_" + hostname_ + "_" + base::IntToString(port_); | 125 return scheme_ + "_" + hostname_ + "_" + base::IntToString(port_); |
116 } | 126 } |
117 | 127 |
118 GURL DatabaseIdentifier::ToOrigin() const { | 128 GURL DatabaseIdentifier::ToOrigin() const { |
| 129 if (is_file_) |
| 130 return GURL("file:///"); |
119 if (is_unique_) | 131 if (is_unique_) |
120 return GURL(); | 132 return GURL(); |
121 if (port_ == 0) | 133 if (port_ == 0) |
122 return GURL(scheme_ + "://" + hostname_); | 134 return GURL(scheme_ + "://" + hostname_); |
123 return GURL(scheme_ + "://" + hostname_ + ":" + base::IntToString(port_)); | 135 return GURL(scheme_ + "://" + hostname_ + ":" + base::IntToString(port_)); |
124 } | 136 } |
125 | 137 |
126 } // namespace webkit_database | 138 } // namespace webkit_database |
OLD | NEW |