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

Side by Side Diff: mojo/services/public/cpp/view_manager/lib/view_manager.cc

Issue 311373005: Nesting (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/services/public/cpp/view_manager/view_manager.h" 5 #include "mojo/services/public/cpp/view_manager/view_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "mojo/public/cpp/application/application.h" 9 #include "mojo/public/cpp/application/application.h"
10 #include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h" 10 #include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h"
11 #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h" 11 #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h"
12 #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h" 12 #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h"
13 #include "mojo/services/public/cpp/view_manager/view.h" 13 #include "mojo/services/public/cpp/view_manager/view.h"
14 14
15 namespace mojo { 15 namespace mojo {
16 namespace view_manager { 16 namespace view_manager {
17 namespace {
18
19 void OnViewManagerReady(base::RunLoop* loop,
20 ViewManager* manager,
21 ViewTreeNode* root) {
22 loop->Quit();
23 }
24
25 } // namespace
26 17
27 //////////////////////////////////////////////////////////////////////////////// 18 ////////////////////////////////////////////////////////////////////////////////
28 // ViewManager, public: 19 // ViewManager, public:
29 20
30 ViewManager::~ViewManager() { 21 ViewManager::~ViewManager() {
31 while (!nodes_.empty()) { 22 while (!nodes_.empty()) {
32 IdToNodeMap::iterator it = nodes_.begin(); 23 IdToNodeMap::iterator it = nodes_.begin();
33 if (synchronizer_->OwnsNode(it->second->id())) 24 if (synchronizer_->OwnsNode(it->second->id()))
34 it->second->Destroy(); 25 it->second->Destroy();
35 else 26 else
36 nodes_.erase(it); 27 nodes_.erase(it);
37 } 28 }
38 while (!views_.empty()) { 29 while (!views_.empty()) {
39 IdToViewMap::iterator it = views_.begin(); 30 IdToViewMap::iterator it = views_.begin();
40 if (synchronizer_->OwnsView(it->second->id())) 31 if (synchronizer_->OwnsView(it->second->id()))
41 it->second->Destroy(); 32 it->second->Destroy();
42 else 33 else
43 views_.erase(it); 34 views_.erase(it);
44 } 35 }
45 } 36 }
46 37
47 // static 38 // static
48 ViewManager* ViewManager::CreateBlocking(Application* application) { 39 void ViewManager::Create(Application* application,
49 base::RunLoop init_loop; 40 ViewManagerDelegate* delegate) {
50 ViewManager* manager = new ViewManager( 41 application->AddService<ViewManagerSynchronizer>(delegate);
51 application,
52 base::Bind(&OnViewManagerReady, &init_loop),
53 RootCallback());
54 init_loop.Run();
55 return manager;
56 }
57
58 // static
59 void ViewManager::Create(
60 Application* application,
61 const RootCallback& root_added_callback,
62 const RootCallback& root_removed_callback) {
63 new ViewManager(application, root_added_callback, root_removed_callback);
64 } 42 }
65 43
66 ViewTreeNode* ViewManager::GetNodeById(TransportNodeId id) { 44 ViewTreeNode* ViewManager::GetNodeById(TransportNodeId id) {
67 IdToNodeMap::const_iterator it = nodes_.find(id); 45 IdToNodeMap::const_iterator it = nodes_.find(id);
68 return it != nodes_.end() ? it->second : NULL; 46 return it != nodes_.end() ? it->second : NULL;
69 } 47 }
70 48
71 View* ViewManager::GetViewById(TransportViewId id) { 49 View* ViewManager::GetViewById(TransportViewId id) {
72 IdToViewMap::const_iterator it = views_.find(id); 50 IdToViewMap::const_iterator it = views_.find(id);
73 return it != views_.end() ? it->second : NULL; 51 return it != views_.end() ? it->second : NULL;
74 } 52 }
75 53
76 //////////////////////////////////////////////////////////////////////////////// 54 ////////////////////////////////////////////////////////////////////////////////
77 // ViewManager, private: 55 // ViewManager, private:
78 56
79 ViewManager::ViewManager( 57 ViewManager::ViewManager(ViewManagerSynchronizer* synchronizer,
80 Application* application, 58 ViewManagerDelegate* delegate)
81 const RootCallback& root_added_callback, 59 : delegate_(delegate),
82 const RootCallback& root_removed_callback) 60 synchronizer_(synchronizer) {}
83 : root_added_callback_(root_added_callback),
84 root_removed_callback_(root_removed_callback),
85 synchronizer_(NULL) {
86 application->AddService<ViewManagerSynchronizer>(this);
87 }
88 61
89 } // namespace view_manager 62 } // namespace view_manager
90 } // namespace mojo 63 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/mojo_services.gypi ('k') | mojo/services/public/cpp/view_manager/lib/view_manager_private.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698