ClearSigninProfile refactored and used in <webview>-based enrollment.
[chromium-blink-merge.git] / gin / per_isolate_data.cc
blob99c928cdd8ea1e02b0699c2243c176e537899286
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
3 // found in the LICENSE file.
5 #include "base/logging.h"
6 #include "base/message_loop/message_loop_proxy.h"
7 #include "gin/per_isolate_data.h"
8 #include "gin/public/gin_embedders.h"
10 using v8::ArrayBuffer;
11 using v8::Eternal;
12 using v8::Isolate;
13 using v8::Local;
14 using v8::Object;
15 using v8::FunctionTemplate;
16 using v8::ObjectTemplate;
18 namespace gin {
20 PerIsolateData::PerIsolateData(Isolate* isolate,
21 ArrayBuffer::Allocator* allocator)
22 : isolate_(isolate),
23 allocator_(allocator),
24 message_loop_proxy_(base::MessageLoopProxy::current()) {
25 isolate_->SetData(kEmbedderNativeGin, this);
28 PerIsolateData::~PerIsolateData() {
29 isolate_->SetData(kEmbedderNativeGin, NULL);
32 PerIsolateData* PerIsolateData::From(Isolate* isolate) {
33 return static_cast<PerIsolateData*>(isolate->GetData(kEmbedderNativeGin));
36 void PerIsolateData::SetObjectTemplate(WrapperInfo* info,
37 Local<ObjectTemplate> templ) {
38 object_templates_[info] = Eternal<ObjectTemplate>(isolate_, templ);
41 void PerIsolateData::SetFunctionTemplate(WrapperInfo* info,
42 Local<FunctionTemplate> templ) {
43 function_templates_[info] = Eternal<FunctionTemplate>(isolate_, templ);
46 v8::Local<v8::ObjectTemplate> PerIsolateData::GetObjectTemplate(
47 WrapperInfo* info) {
48 ObjectTemplateMap::iterator it = object_templates_.find(info);
49 if (it == object_templates_.end())
50 return v8::Local<v8::ObjectTemplate>();
51 return it->second.Get(isolate_);
54 v8::Local<v8::FunctionTemplate> PerIsolateData::GetFunctionTemplate(
55 WrapperInfo* info) {
56 FunctionTemplateMap::iterator it = function_templates_.find(info);
57 if (it == function_templates_.end())
58 return v8::Local<v8::FunctionTemplate>();
59 return it->second.Get(isolate_);
62 void PerIsolateData::SetIndexedPropertyInterceptor(
63 WrappableBase* base,
64 IndexedPropertyInterceptor* interceptor) {
65 indexed_interceptors_[base] = interceptor;
68 void PerIsolateData::SetNamedPropertyInterceptor(
69 WrappableBase* base,
70 NamedPropertyInterceptor* interceptor) {
71 named_interceptors_[base] = interceptor;
74 void PerIsolateData::ClearIndexedPropertyInterceptor(
75 WrappableBase* base,
76 IndexedPropertyInterceptor* interceptor) {
77 IndexedPropertyInterceptorMap::iterator it = indexed_interceptors_.find(base);
78 if (it != indexed_interceptors_.end())
79 indexed_interceptors_.erase(it);
80 else
81 NOTREACHED();
84 void PerIsolateData::ClearNamedPropertyInterceptor(
85 WrappableBase* base,
86 NamedPropertyInterceptor* interceptor) {
87 NamedPropertyInterceptorMap::iterator it = named_interceptors_.find(base);
88 if (it != named_interceptors_.end())
89 named_interceptors_.erase(it);
90 else
91 NOTREACHED();
94 IndexedPropertyInterceptor* PerIsolateData::GetIndexedPropertyInterceptor(
95 WrappableBase* base) {
96 IndexedPropertyInterceptorMap::iterator it = indexed_interceptors_.find(base);
97 if (it != indexed_interceptors_.end())
98 return it->second;
99 else
100 return NULL;
103 NamedPropertyInterceptor* PerIsolateData::GetNamedPropertyInterceptor(
104 WrappableBase* base) {
105 NamedPropertyInterceptorMap::iterator it = named_interceptors_.find(base);
106 if (it != named_interceptors_.end())
107 return it->second;
108 else
109 return NULL;
112 } // namespace gin