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

Unified Diff: mojo/services/public/cpp/view_manager/lib/view.cc

Issue 272833002: View synchronization (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: mojo/services/public/cpp/view_manager/lib/view.cc
diff --git a/mojo/services/public/cpp/view_manager/lib/view.cc b/mojo/services/public/cpp/view_manager/lib/view.cc
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..577aca8d01a0884d397cab670b623d3010ec5a4c 100644
--- a/mojo/services/public/cpp/view_manager/lib/view.cc
+++ b/mojo/services/public/cpp/view_manager/lib/view.cc
@@ -0,0 +1,82 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/services/public/cpp/view_manager/view.h"
+
+#include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h"
+#include "mojo/services/public/cpp/view_manager/lib/view_private.h"
+#include "mojo/services/public/cpp/view_manager/view_observer.h"
+
+namespace mojo {
+namespace services {
+namespace view_manager {
+
+namespace {
+class ScopedDestructionNotifier {
+ public:
+ explicit ScopedDestructionNotifier(View* view)
+ : view_(view) {
+ FOR_EACH_OBSERVER(
+ ViewObserver,
+ *ViewPrivate(view_).observers(),
+ OnViewDestroy(view_, ViewObserver::DISPOSITION_CHANGING));
+ }
+ ~ScopedDestructionNotifier() {
+ FOR_EACH_OBSERVER(
+ ViewObserver,
+ *ViewPrivate(view_).observers(),
+ OnViewDestroy(view_, ViewObserver::DISPOSITION_CHANGED));
+ }
+
+ private:
+ View* view_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedDestructionNotifier);
+};
+} // namespace
+
+// static
+View* View::Create(ViewManager* manager) {
+ View* view = new View(manager);
+ ViewManagerPrivate(manager).AddView(view->id(), view);
+ return view;
+}
+
+void View::Destroy() {
+ if (manager_)
+ ViewManagerPrivate(manager_).synchronizer()->DestroyView(id_);
+ LocalDestroy();
+}
+
+void View::AddObserver(ViewObserver* observer) {
+ observers_.AddObserver(observer);
+}
+
+void View::RemoveObserver(ViewObserver* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+View::View(ViewManager* manager)
+ : id_(ViewManagerPrivate(manager).synchronizer()->CreateView()),
+ node_(NULL),
+ manager_(manager) {}
+
+View::View()
+ : id_(-1),
+ node_(NULL),
+ manager_(NULL) {}
+
+View::~View() {
+ ScopedDestructionNotifier notifier(this);
+ if (manager_)
+ ViewManagerPrivate(manager_).RemoveView(id_);
+}
+
+void View::LocalDestroy() {
+ delete this;
+}
+
+} // namespace view_manager
+} // namespace services
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698