OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 private: | 134 private: |
135 const std::string ascii_; | 135 const std::string ascii_; |
136 DISALLOW_COPY_AND_ASSIGN(V8ExternalASCIIString); | 136 DISALLOW_COPY_AND_ASSIGN(V8ExternalASCIIString); |
137 }; | 137 }; |
138 | 138 |
139 // When creating a v8::String from a C++ string we have two choices: create | 139 // When creating a v8::String from a C++ string we have two choices: create |
140 // a copy, or create a wrapper that shares the same underlying storage. | 140 // a copy, or create a wrapper that shares the same underlying storage. |
141 // For small strings it is better to just make a copy, whereas for large | 141 // For small strings it is better to just make a copy, whereas for large |
142 // strings there are savings by sharing the storage. This number identifies | 142 // strings there are savings by sharing the storage. This number identifies |
143 // the cutoff length for when to start wrapping rather than creating copies. | 143 // the cutoff length for when to start wrapping rather than creating copies. |
144 // TODO(eroman): This is disabled because of crbug.com/48145. | 144 const size_t kMaxStringBytesForCopy = 256; |
145 const size_t kMaxStringBytesForCopy = static_cast<size_t>(-1); | |
146 | 145 |
147 // Converts a V8 String to a UTF16 string16. | 146 // Converts a V8 String to a UTF16 string16. |
148 string16 V8StringToUTF16(v8::Handle<v8::String> s) { | 147 string16 V8StringToUTF16(v8::Handle<v8::String> s) { |
149 int len = s->Length(); | 148 int len = s->Length(); |
150 string16 result; | 149 string16 result; |
151 // Note that the reinterpret cast is because on Windows string16 is an alias | 150 // Note that the reinterpret cast is because on Windows string16 is an alias |
152 // to wstring, and hence has character type wchar_t not uint16_t. | 151 // to wstring, and hence has character type wchar_t not uint16_t. |
153 s->Write(reinterpret_cast<uint16_t*>(WriteInto(&result, len + 1)), 0, len); | 152 s->Write(reinterpret_cast<uint16_t*>(WriteInto(&result, len + 1)), 0, len); |
154 return result; | 153 return result; |
155 } | 154 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 explicit Context(ProxyResolverJSBindings* js_bindings) | 238 explicit Context(ProxyResolverJSBindings* js_bindings) |
240 : js_bindings_(js_bindings) { | 239 : js_bindings_(js_bindings) { |
241 DCHECK(js_bindings != NULL); | 240 DCHECK(js_bindings != NULL); |
242 } | 241 } |
243 | 242 |
244 ~Context() { | 243 ~Context() { |
245 v8::Locker locked; | 244 v8::Locker locked; |
246 | 245 |
247 v8_this_.Dispose(); | 246 v8_this_.Dispose(); |
248 v8_context_.Dispose(); | 247 v8_context_.Dispose(); |
| 248 |
| 249 // Run the V8 garbage collector. We do this to be sure the |
| 250 // ExternalStringResource objects we allocated get properly disposed. |
| 251 // Otherwise when running the unit-tests they may get leaked. |
| 252 // See crbug.com/48145. |
| 253 PurgeMemory(); |
249 } | 254 } |
250 | 255 |
251 int ResolveProxy(const GURL& query_url, ProxyInfo* results) { | 256 int ResolveProxy(const GURL& query_url, ProxyInfo* results) { |
252 v8::Locker locked; | 257 v8::Locker locked; |
253 v8::HandleScope scope; | 258 v8::HandleScope scope; |
254 | 259 |
255 v8::Context::Scope function_scope(v8_context_); | 260 v8::Context::Scope function_scope(v8_context_); |
256 | 261 |
257 v8::Local<v8::Value> function; | 262 v8::Local<v8::Value> function; |
258 if (!GetFindProxyForURL(&function)) { | 263 if (!GetFindProxyForURL(&function)) { |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 | 649 |
645 // Try parsing the PAC script. | 650 // Try parsing the PAC script. |
646 scoped_ptr<Context> context(new Context(js_bindings_.get())); | 651 scoped_ptr<Context> context(new Context(js_bindings_.get())); |
647 int rv = context->InitV8(pac_script); | 652 int rv = context->InitV8(pac_script); |
648 if (rv == OK) | 653 if (rv == OK) |
649 context_.reset(context.release()); | 654 context_.reset(context.release()); |
650 return rv; | 655 return rv; |
651 } | 656 } |
652 | 657 |
653 } // namespace net | 658 } // namespace net |
OLD | NEW |