From 0692776020974b506af416ac47683d91dc4644b7 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 25 Apr 2013 15:02:58 +0800 Subject: [PATCH] No more C++ RecordedObject and ObjectsRegistry code. All RPC API will be implemented in pure javascript. --- atom.gyp | 5 --- browser/api/atom_api_event_emitter.cc | 4 +-- browser/api/atom_api_event_emitter.h | 8 +++-- browser/api/atom_api_objects_registry.cc | 19 ----------- browser/api/atom_api_objects_registry.h | 37 --------------------- browser/api/atom_api_recorded_object.cc | 41 ----------------------- browser/api/atom_api_recorded_object.h | 42 ------------------------ browser/atom_browser_context.cc | 4 +-- browser/atom_browser_context.h | 10 ------ 9 files changed, 9 insertions(+), 161 deletions(-) delete mode 100644 browser/api/atom_api_objects_registry.cc delete mode 100644 browser/api/atom_api_objects_registry.h delete mode 100644 browser/api/atom_api_recorded_object.cc delete mode 100644 browser/api/atom_api_recorded_object.h diff --git a/atom.gyp b/atom.gyp index 2b4bb996cbeb..e7fdc63d18ee 100644 --- a/atom.gyp +++ b/atom.gyp @@ -8,7 +8,6 @@ 'coffee_sources': [ 'browser/api/lib/atom.coffee', 'browser/api/lib/ipc.coffee', - 'browser/api/lib/.coffee', 'browser/api/lib/window.coffee', 'browser/atom/atom.coffee', 'browser/atom/objects_registry.coffee', @@ -25,10 +24,6 @@ 'browser/api/atom_api_event.h', 'browser/api/atom_api_event_emitter.cc', 'browser/api/atom_api_event_emitter.h', - 'browser/api/atom_api_objects_registry.cc', - 'browser/api/atom_api_objects_registry.h', - 'browser/api/atom_api_recorded_object.cc', - 'browser/api/atom_api_recorded_object.h', 'browser/api/atom_api_window.cc', 'browser/api/atom_api_window.h', 'browser/api/atom_browser_bindings.cc', diff --git a/browser/api/atom_api_event_emitter.cc b/browser/api/atom_api_event_emitter.cc index 7a88a1eb710b..6fe790b9ecd6 100644 --- a/browser/api/atom_api_event_emitter.cc +++ b/browser/api/atom_api_event_emitter.cc @@ -16,8 +16,8 @@ namespace atom { namespace api { -EventEmitter::EventEmitter(v8::Handle wrapper) - : RecordedObject(wrapper) { +EventEmitter::EventEmitter(v8::Handle wrapper) { + Wrap(wrapper); } EventEmitter::~EventEmitter() { diff --git a/browser/api/atom_api_event_emitter.h b/browser/api/atom_api_event_emitter.h index 021d91c7fe2a..4071355d1b56 100644 --- a/browser/api/atom_api_event_emitter.h +++ b/browser/api/atom_api_event_emitter.h @@ -7,7 +7,8 @@ #include -#include "browser/api/atom_api_recorded_object.h" +#include "base/basictypes.h" +#include "vendor/node/src/node_object_wrap.h" namespace base { class ListValue; @@ -20,13 +21,16 @@ namespace api { // Class interiting EventEmitter should assume it's a javascript object which // interits require('events').EventEmitter, this class provides many helper // methods to do event processing in C++. -class EventEmitter : public RecordedObject { +class EventEmitter : public node::ObjectWrap { public: virtual ~EventEmitter(); // Emit an event and returns whether the handler has called preventDefault(). bool Emit(const std::string& name, base::ListValue* args); + // Small accessor to return handle_, this follows Google C++ Style. + v8::Persistent& handle() { return handle_; } + protected: explicit EventEmitter(v8::Handle wrapper); diff --git a/browser/api/atom_api_objects_registry.cc b/browser/api/atom_api_objects_registry.cc deleted file mode 100644 index 71e7efd815e2..000000000000 --- a/browser/api/atom_api_objects_registry.cc +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2013 GitHub, Inc. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "browser/api/atom_api_objects_registry.h" - -namespace atom { - -namespace api { - -ObjectsRegistry::ObjectsRegistry() { -} - -ObjectsRegistry::~ObjectsRegistry() { -} - -} // namespace api - -} // namespace atom diff --git a/browser/api/atom_api_objects_registry.h b/browser/api/atom_api_objects_registry.h deleted file mode 100644 index a92bb9a54dbb..000000000000 --- a/browser/api/atom_api_objects_registry.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2013 GitHub, Inc. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ATOM_BROWSER_API_ATOM_API_OBJECTS_REGISTRY_H_ -#define ATOM_BROWSER_API_ATOM_API_OBJECTS_REGISTRY_H_ - -#include "base/id_map.h" -#include "base/basictypes.h" - -namespace atom { - -namespace api { - -class RecordedObject; - -class ObjectsRegistry { - public: - ObjectsRegistry(); - virtual ~ObjectsRegistry(); - - int Add(RecordedObject* data) { return id_map_.Add(data); } - void Remove(int id) { id_map_.Remove(id); } - void Clear() { id_map_.Clear(); } - RecordedObject* Lookup(int id) const { return id_map_.Lookup(id); } - - private: - IDMap id_map_; - - DISALLOW_COPY_AND_ASSIGN(ObjectsRegistry); -}; - -} // namespace api - -} // namespace atom - -#endif // ATOM_BROWSER_API_ATOM_API_OBJECTS_REGISTRY_H_ diff --git a/browser/api/atom_api_recorded_object.cc b/browser/api/atom_api_recorded_object.cc deleted file mode 100644 index 142bb50bb066..000000000000 --- a/browser/api/atom_api_recorded_object.cc +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2013 GitHub, Inc. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ATOM_BROWSER_API_ATOM_API_RECORDED_OBJECT_ -#define ATOM_BROWSER_API_ATOM_API_RECORDED_OBJECT_ - -#include "browser/api/atom_api_recorded_object.h" - -#include "base/compiler_specific.h" -#include "browser/api/atom_api_objects_registry.h" -#include "browser/atom_browser_context.h" - -namespace atom { - -namespace api { - -RecordedObject::RecordedObject(v8::Handle wrapper) - : ALLOW_THIS_IN_INITIALIZER_LIST(id_( - AtomBrowserContext::Get()->objects_registry()->Add(this))) { - Wrap(wrapper); - - wrapper->SetAccessor(v8::String::New("id"), IDGetter); -} - -RecordedObject::~RecordedObject() { - AtomBrowserContext::Get()->objects_registry()->Remove(id()); -} - -// static -v8::Handle RecordedObject::IDGetter(v8::Local property, - const v8::AccessorInfo& info) { - RecordedObject* self = RecordedObject::Unwrap(info.This()); - return v8::Integer::New(self->id_); -} - -} // namespace api - -} // namespace atom - -#endif // ATOM_BROWSER_API_ATOM_API_RECORDED_OBJECT_ diff --git a/browser/api/atom_api_recorded_object.h b/browser/api/atom_api_recorded_object.h deleted file mode 100644 index a5806ee8f9a2..000000000000 --- a/browser/api/atom_api_recorded_object.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) 2013 GitHub, Inc. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ATOM_BROWSER_API_ATOM_API_RECORDED_OBJECT_H_ -#define ATOM_BROWSER_API_ATOM_API_RECORDED_OBJECT_H_ - -#include "base/basictypes.h" -#include "vendor/node/src/node_object_wrap.h" - -namespace atom { - -namespace api { - -// Objects of this class will be recorded in C++ and available for RPC from -// renderer. -class RecordedObject : public node::ObjectWrap { - public: - virtual ~RecordedObject(); - - // Small accessor to return handle_, this follows Google C++ Style. - v8::Persistent& handle() { return handle_; } - - int id() const { return id_; } - - protected: - explicit RecordedObject(v8::Handle wrapper); - - private: - static v8::Handle IDGetter(v8::Local property, - const v8::AccessorInfo& info); - - int id_; - - DISALLOW_COPY_AND_ASSIGN(RecordedObject); -}; - -} // namespace api - -} // namespace atom - -#endif // ATOM_BROWSER_API_ATOM_API_RECORDED_OBJECT_H_ diff --git a/browser/atom_browser_context.cc b/browser/atom_browser_context.cc index 78cada008866..59649b216f3b 100644 --- a/browser/atom_browser_context.cc +++ b/browser/atom_browser_context.cc @@ -4,13 +4,11 @@ #include "browser/atom_browser_context.h" -#include "browser/api/atom_api_objects_registry.h" #include "browser/atom_browser_main_parts.h" namespace atom { -AtomBrowserContext::AtomBrowserContext() - : objects_registry_(new api::ObjectsRegistry) { +AtomBrowserContext::AtomBrowserContext() { } AtomBrowserContext::~AtomBrowserContext() { diff --git a/browser/atom_browser_context.h b/browser/atom_browser_context.h index 397bd92c6986..1a97bc3fd455 100644 --- a/browser/atom_browser_context.h +++ b/browser/atom_browser_context.h @@ -10,10 +10,6 @@ namespace atom { -namespace api { -class ObjectsRegistry; -} - class AtomBrowserContext : public brightray::BrowserContext { public: AtomBrowserContext(); @@ -21,13 +17,7 @@ class AtomBrowserContext : public brightray::BrowserContext { static AtomBrowserContext* Get(); - api::ObjectsRegistry* objects_registry() const { - return objects_registry_.get(); - } - private: - scoped_ptr objects_registry_; - DISALLOW_COPY_AND_ASSIGN(AtomBrowserContext); };