Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: url/mojo/url_gurl_struct_traits.h

Issue 2253293002: Mojo C++ bindings: change the first template parameter of StructTraits and UnionTraits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@91_extra
Patch Set: rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « url/mojo/origin_struct_traits.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef URL_MOJO_URL_GURL_STRUCT_TRAITS_H_ 5 #ifndef URL_MOJO_URL_GURL_STRUCT_TRAITS_H_
6 #define URL_MOJO_URL_GURL_STRUCT_TRAITS_H_ 6 #define URL_MOJO_URL_GURL_STRUCT_TRAITS_H_
7 7
8 #include "base/strings/string_piece.h" 8 #include "base/strings/string_piece.h"
9 #include "url/gurl.h" 9 #include "url/gurl.h"
10 #include "url/mojo/url.mojom.h" 10 #include "url/mojo/url.mojom.h"
11 #include "url/url_constants.h" 11 #include "url/url_constants.h"
12 12
13 namespace mojo { 13 namespace mojo {
14 14
15 template <> 15 template <>
16 struct StructTraits<url::mojom::Url, GURL> { 16 struct StructTraits<url::mojom::UrlDataView, GURL> {
17 static base::StringPiece url(const GURL& r) { 17 static base::StringPiece url(const GURL& r) {
18 if (r.possibly_invalid_spec().length() > url::kMaxURLChars || 18 if (r.possibly_invalid_spec().length() > url::kMaxURLChars ||
19 !r.is_valid()) { 19 !r.is_valid()) {
20 return base::StringPiece(); 20 return base::StringPiece();
21 } 21 }
22 22
23 return base::StringPiece(r.possibly_invalid_spec().c_str(), 23 return base::StringPiece(r.possibly_invalid_spec().c_str(),
24 r.possibly_invalid_spec().length()); 24 r.possibly_invalid_spec().length());
25 } 25 }
26 static bool Read(url::mojom::UrlDataView data, GURL* out) { 26 static bool Read(url::mojom::UrlDataView data, GURL* out) {
27 base::StringPiece url_string; 27 base::StringPiece url_string;
28 if (!data.ReadUrl(&url_string)) 28 if (!data.ReadUrl(&url_string))
29 return false; 29 return false;
30 30
31 if (url_string.length() > url::kMaxURLChars) 31 if (url_string.length() > url::kMaxURLChars)
32 return false; 32 return false;
33 33
34 *out = GURL(url_string); 34 *out = GURL(url_string);
35 if (!url_string.empty() && !out->is_valid()) 35 if (!url_string.empty() && !out->is_valid())
36 return false; 36 return false;
37 37
38 return true; 38 return true;
39 } 39 }
40 }; 40 };
41 41
42 } 42 }
43 43
44 #endif // URL_MOJO_URL_GURL_STRUCT_TRAITS_H_ 44 #endif // URL_MOJO_URL_GURL_STRUCT_TRAITS_H_
OLDNEW
« no previous file with comments | « url/mojo/origin_struct_traits.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698