OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/proxy/proxy_resolver_v8.h" | 5 #include "net/proxy/proxy_resolver_v8.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstdio> | 8 #include <cstdio> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 86 |
87 // External string wrapper so V8 can access the UTF16 string wrapped by | 87 // External string wrapper so V8 can access the UTF16 string wrapped by |
88 // ProxyResolverScriptData. | 88 // ProxyResolverScriptData. |
89 class V8ExternalStringFromScriptData | 89 class V8ExternalStringFromScriptData |
90 : public v8::String::ExternalStringResource { | 90 : public v8::String::ExternalStringResource { |
91 public: | 91 public: |
92 explicit V8ExternalStringFromScriptData( | 92 explicit V8ExternalStringFromScriptData( |
93 const scoped_refptr<ProxyResolverScriptData>& script_data) | 93 const scoped_refptr<ProxyResolverScriptData>& script_data) |
94 : script_data_(script_data) {} | 94 : script_data_(script_data) {} |
95 | 95 |
96 virtual const uint16_t* data() const override { | 96 const uint16_t* data() const override { |
97 return reinterpret_cast<const uint16*>(script_data_->utf16().data()); | 97 return reinterpret_cast<const uint16*>(script_data_->utf16().data()); |
98 } | 98 } |
99 | 99 |
100 virtual size_t length() const override { | 100 size_t length() const override { return script_data_->utf16().size(); } |
101 return script_data_->utf16().size(); | |
102 } | |
103 | 101 |
104 private: | 102 private: |
105 const scoped_refptr<ProxyResolverScriptData> script_data_; | 103 const scoped_refptr<ProxyResolverScriptData> script_data_; |
106 DISALLOW_COPY_AND_ASSIGN(V8ExternalStringFromScriptData); | 104 DISALLOW_COPY_AND_ASSIGN(V8ExternalStringFromScriptData); |
107 }; | 105 }; |
108 | 106 |
109 // External string wrapper so V8 can access a string literal. | 107 // External string wrapper so V8 can access a string literal. |
110 class V8ExternalASCIILiteral | 108 class V8ExternalASCIILiteral |
111 : public v8::String::ExternalOneByteStringResource { | 109 : public v8::String::ExternalOneByteStringResource { |
112 public: | 110 public: |
113 // |ascii| must be a NULL-terminated C string, and must remain valid | 111 // |ascii| must be a NULL-terminated C string, and must remain valid |
114 // throughout this object's lifetime. | 112 // throughout this object's lifetime. |
115 V8ExternalASCIILiteral(const char* ascii, size_t length) | 113 V8ExternalASCIILiteral(const char* ascii, size_t length) |
116 : ascii_(ascii), length_(length) { | 114 : ascii_(ascii), length_(length) { |
117 DCHECK(base::IsStringASCII(ascii)); | 115 DCHECK(base::IsStringASCII(ascii)); |
118 } | 116 } |
119 | 117 |
120 virtual const char* data() const override { | 118 const char* data() const override { return ascii_; } |
121 return ascii_; | |
122 } | |
123 | 119 |
124 virtual size_t length() const override { | 120 size_t length() const override { return length_; } |
125 return length_; | |
126 } | |
127 | 121 |
128 private: | 122 private: |
129 const char* ascii_; | 123 const char* ascii_; |
130 size_t length_; | 124 size_t length_; |
131 DISALLOW_COPY_AND_ASSIGN(V8ExternalASCIILiteral); | 125 DISALLOW_COPY_AND_ASSIGN(V8ExternalASCIILiteral); |
132 }; | 126 }; |
133 | 127 |
134 // When creating a v8::String from a C++ string we have two choices: create | 128 // When creating a v8::String from a C++ string we have two choices: create |
135 // a copy, or create a wrapper that shares the same underlying storage. | 129 // a copy, or create a wrapper that shares the same underlying storage. |
136 // For small strings it is better to just make a copy, whereas for large | 130 // For small strings it is better to just make a copy, whereas for large |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 return 0; | 797 return 0; |
804 | 798 |
805 v8::Locker locked(g_proxy_resolver_isolate_->isolate()); | 799 v8::Locker locked(g_proxy_resolver_isolate_->isolate()); |
806 v8::Isolate::Scope isolate_scope(g_proxy_resolver_isolate_->isolate()); | 800 v8::Isolate::Scope isolate_scope(g_proxy_resolver_isolate_->isolate()); |
807 v8::HeapStatistics heap_statistics; | 801 v8::HeapStatistics heap_statistics; |
808 g_proxy_resolver_isolate_->isolate()->GetHeapStatistics(&heap_statistics); | 802 g_proxy_resolver_isolate_->isolate()->GetHeapStatistics(&heap_statistics); |
809 return heap_statistics.used_heap_size(); | 803 return heap_statistics.used_heap_size(); |
810 } | 804 } |
811 | 805 |
812 } // namespace net | 806 } // namespace net |
OLD | NEW |