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

Side by Side Diff: net/proxy/proxy_resolver_v8.cc

Issue 227233006: Make net use v8 through gin (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « net/proxy/proxy_resolver_v8.h ('k') | net/test/run_all_unittests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/debug/leak_annotations.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/strings/string_tokenizer.h" 14 #include "base/strings/string_tokenizer.h"
14 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
16 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
18 #include "gin/public/isolate_holder.h"
17 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
18 #include "net/base/net_log.h" 20 #include "net/base/net_log.h"
19 #include "net/base/net_util.h" 21 #include "net/base/net_util.h"
20 #include "net/proxy/proxy_info.h" 22 #include "net/proxy/proxy_info.h"
21 #include "net/proxy/proxy_resolver_script.h" 23 #include "net/proxy/proxy_resolver_script.h"
22 #include "url/gurl.h" 24 #include "url/gurl.h"
23 #include "url/url_canon.h" 25 #include "url/url_canon.h"
24 #include "v8/include/v8.h" 26 #include "v8/include/v8.h"
25 27
26 // Notes on the javascript environment: 28 // Notes on the javascript environment:
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 759
758 // Try parsing the PAC script. 760 // Try parsing the PAC script.
759 scoped_ptr<Context> context(new Context(this, GetDefaultIsolate())); 761 scoped_ptr<Context> context(new Context(this, GetDefaultIsolate()));
760 int rv = context->InitV8(script_data); 762 int rv = context->InitV8(script_data);
761 if (rv == OK) 763 if (rv == OK)
762 context_.reset(context.release()); 764 context_.reset(context.release());
763 return rv; 765 return rv;
764 } 766 }
765 767
766 // static 768 // static
767 void ProxyResolverV8::RememberDefaultIsolate() { 769 void ProxyResolverV8::EnsureIsolateCreated() {
768 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 770 if (g_proxy_resolver_isolate_)
769 DCHECK(isolate) 771 return;
770 << "ProxyResolverV8::RememberDefaultIsolate called on wrong thread"; 772 g_proxy_resolver_isolate_ =
771 DCHECK(g_default_isolate_ == NULL || g_default_isolate_ == isolate) 773 new gin::IsolateHolder(gin::IsolateHolder::kNonStrictMode);
772 << "Default Isolate can not be changed"; 774 ANNOTATE_LEAKING_OBJECT_PTR(g_proxy_resolver_isolate_);
773 g_default_isolate_ = isolate;
774 } 775 }
775 776
776 #if defined(OS_WIN)
777 // static
778 void ProxyResolverV8::CreateIsolate() {
779 v8::Isolate* isolate = v8::Isolate::New();
780 DCHECK(isolate);
781 DCHECK(g_default_isolate_ == NULL) << "Default Isolate can not be set twice";
782
783 isolate->Enter();
784 v8::V8::Initialize();
785
786 g_default_isolate_ = isolate;
787 }
788 #endif // defined(OS_WIN)
789
790 // static 777 // static
791 v8::Isolate* ProxyResolverV8::GetDefaultIsolate() { 778 v8::Isolate* ProxyResolverV8::GetDefaultIsolate() {
792 DCHECK(g_default_isolate_) 779 DCHECK(g_proxy_resolver_isolate_)
793 << "Must call ProxyResolverV8::RememberDefaultIsolate() first"; 780 << "Must call ProxyResolverV8::EnsureIsolateCreated() first";
794 return g_default_isolate_; 781 return g_proxy_resolver_isolate_->isolate();
795 } 782 }
796 783
797 v8::Isolate* ProxyResolverV8::g_default_isolate_ = NULL; 784 gin::IsolateHolder* ProxyResolverV8::g_proxy_resolver_isolate_ = NULL;
798 785
799 // static 786 // static
800 size_t ProxyResolverV8::GetTotalHeapSize() { 787 size_t ProxyResolverV8::GetTotalHeapSize() {
801 if (!g_default_isolate_) 788 if (!g_proxy_resolver_isolate_)
802 return 0; 789 return 0;
803 790
804 v8::Locker locked(g_default_isolate_); 791 v8::Locker locked(g_proxy_resolver_isolate_->isolate());
805 v8::Isolate::Scope isolate_scope(g_default_isolate_); 792 v8::Isolate::Scope isolate_scope(g_proxy_resolver_isolate_->isolate());
806 v8::HeapStatistics heap_statistics; 793 v8::HeapStatistics heap_statistics;
807 g_default_isolate_->GetHeapStatistics(&heap_statistics); 794 g_proxy_resolver_isolate_->isolate()->GetHeapStatistics(&heap_statistics);
808 return heap_statistics.total_heap_size(); 795 return heap_statistics.total_heap_size();
809 } 796 }
810 797
811 // static 798 // static
812 size_t ProxyResolverV8::GetUsedHeapSize() { 799 size_t ProxyResolverV8::GetUsedHeapSize() {
813 if (!g_default_isolate_) 800 if (!g_proxy_resolver_isolate_)
814 return 0; 801 return 0;
815 802
816 v8::Locker locked(g_default_isolate_); 803 v8::Locker locked(g_proxy_resolver_isolate_->isolate());
817 v8::Isolate::Scope isolate_scope(g_default_isolate_); 804 v8::Isolate::Scope isolate_scope(g_proxy_resolver_isolate_->isolate());
818 v8::HeapStatistics heap_statistics; 805 v8::HeapStatistics heap_statistics;
819 g_default_isolate_->GetHeapStatistics(&heap_statistics); 806 g_proxy_resolver_isolate_->isolate()->GetHeapStatistics(&heap_statistics);
820 return heap_statistics.used_heap_size(); 807 return heap_statistics.used_heap_size();
821 } 808 }
822 809
823 } // namespace net 810 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_resolver_v8.h ('k') | net/test/run_all_unittests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698