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 "storage/common/database/database_identifier.h" | 5 #include "storage/common/database/database_identifier.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "url/url_canon.h" | 12 #include "url/url_canon.h" |
13 | 13 |
14 namespace storage { | 14 namespace storage { |
15 | 15 |
16 // static | 16 // static |
17 std::string GetIdentifierFromOrigin(const GURL& origin) { | 17 std::string GetIdentifierFromOrigin(const GURL& origin) { |
18 return DatabaseIdentifier::CreateFromOrigin(origin).ToString(); | 18 return DatabaseIdentifier::CreateFromOrigin(origin).ToString(); |
19 } | 19 } |
20 | 20 |
21 // static | 21 // static |
22 GURL GetOriginFromIdentifier(const std::string& identifier) { | 22 GURL GetOriginFromIdentifier(const std::string& identifier) { |
23 return DatabaseIdentifier::Parse(identifier).ToOrigin(); | 23 return DatabaseIdentifier::Parse(identifier).ToOrigin(); |
24 } | 24 } |
25 | 25 |
| 26 // static |
| 27 bool IsValidOriginIdentifier(const std::string& identifier) { |
| 28 return GetOriginFromIdentifier(identifier).is_valid(); |
| 29 } |
| 30 |
26 static bool SchemeIsUnique(const std::string& scheme) { | 31 static bool SchemeIsUnique(const std::string& scheme) { |
27 return scheme == "about" || scheme == "data" || scheme == "javascript"; | 32 return scheme == "about" || scheme == "data" || scheme == "javascript"; |
28 } | 33 } |
29 | 34 |
30 // static | 35 // static |
31 const DatabaseIdentifier DatabaseIdentifier::UniqueFileIdentifier() { | 36 const DatabaseIdentifier DatabaseIdentifier::UniqueFileIdentifier() { |
32 return DatabaseIdentifier("", "", 0, true, true); | 37 return DatabaseIdentifier("", "", 0, true, true); |
33 } | 38 } |
34 | 39 |
35 // static | 40 // static |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 if (is_file_) | 144 if (is_file_) |
140 return GURL("file:///"); | 145 return GURL("file:///"); |
141 if (is_unique_) | 146 if (is_unique_) |
142 return GURL(); | 147 return GURL(); |
143 if (port_ == 0) | 148 if (port_ == 0) |
144 return GURL(scheme_ + "://" + hostname_); | 149 return GURL(scheme_ + "://" + hostname_); |
145 return GURL(scheme_ + "://" + hostname_ + ":" + base::IntToString(port_)); | 150 return GURL(scheme_ + "://" + hostname_ + ":" + base::IntToString(port_)); |
146 } | 151 } |
147 | 152 |
148 } // namespace storage | 153 } // namespace storage |
OLD | NEW |