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

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

Issue 317433004: Get view manager client lib unit test harness to run again. Does not get any individual tests worki… (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/message_loop/message_loop.h" 7 #include "base/bind.h"
8 #include "base/run_loop.h"
8 #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"
9 #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"
10 #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"
11 #include "mojo/services/public/cpp/view_manager/view.h" 13 #include "mojo/services/public/cpp/view_manager/view.h"
12 14
13 namespace mojo { 15 namespace mojo {
14 namespace view_manager { 16 namespace view_manager {
17 namespace {
15 18
16 ViewManager::ViewManager(Application* application) 19 void OnViewManagerReady(base::RunLoop* loop, ViewManager* manager) {
17 : synchronizer_(NULL), 20 loop->Quit();
18 tree_(NULL) {
19 application->AddService<ViewManagerSynchronizer>(this);
20 // Block in a nested message loop until the ViewManagerSynchronizer is set up.
21 base::MessageLoop::current()->Run();
22 } 21 }
23 22
23 } // namespace
24
25 ////////////////////////////////////////////////////////////////////////////////
26 // ViewManager, public:
27
24 ViewManager::~ViewManager() { 28 ViewManager::~ViewManager() {
25 while (!nodes_.empty()) { 29 while (!nodes_.empty()) {
26 IdToNodeMap::iterator it = nodes_.begin(); 30 IdToNodeMap::iterator it = nodes_.begin();
27 if (synchronizer_->OwnsNode(it->second->id())) 31 if (synchronizer_->OwnsNode(it->second->id()))
28 it->second->Destroy(); 32 it->second->Destroy();
29 else 33 else
30 nodes_.erase(it); 34 nodes_.erase(it);
31 } 35 }
32 while (!views_.empty()) { 36 while (!views_.empty()) {
33 IdToViewMap::iterator it = views_.begin(); 37 IdToViewMap::iterator it = views_.begin();
34 if (synchronizer_->OwnsView(it->second->id())) 38 if (synchronizer_->OwnsView(it->second->id()))
35 it->second->Destroy(); 39 it->second->Destroy();
36 else 40 else
37 views_.erase(it); 41 views_.erase(it);
38 } 42 }
39 } 43 }
40 44
45 // static
46 ViewManager* ViewManager::CreateBlocking(Application* application) {
47 base::RunLoop init_loop;
48 ViewManager* manager = new ViewManager(
49 application,
50 base::Bind(&OnViewManagerReady, &init_loop));
51 init_loop.Run();
52 return manager;
53 }
54
55 // static
56 void ViewManager::Create(
57 Application* application,
58 const base::Callback<void(ViewManager*)> ready_callback) {
59 new ViewManager(application, ready_callback);
60 }
61
62
sky 2014/06/03 20:15:26 nit: only one newline.
41 ViewTreeNode* ViewManager::GetNodeById(TransportNodeId id) { 63 ViewTreeNode* ViewManager::GetNodeById(TransportNodeId id) {
42 IdToNodeMap::const_iterator it = nodes_.find(id); 64 IdToNodeMap::const_iterator it = nodes_.find(id);
43 return it != nodes_.end() ? it->second : NULL; 65 return it != nodes_.end() ? it->second : NULL;
44 } 66 }
45 67
46 View* ViewManager::GetViewById(TransportViewId id) { 68 View* ViewManager::GetViewById(TransportViewId id) {
47 IdToViewMap::const_iterator it = views_.find(id); 69 IdToViewMap::const_iterator it = views_.find(id);
48 return it != views_.end() ? it->second : NULL; 70 return it != views_.end() ? it->second : NULL;
49 } 71 }
50 72
51 void ViewManager::Embed(const String& url, ViewTreeNode* node) { 73 void ViewManager::Embed(const String& url, ViewTreeNode* node) {
52 synchronizer_->Embed(url, node->id()); 74 synchronizer_->Embed(url, node->id());
53 } 75 }
54 76
77 ////////////////////////////////////////////////////////////////////////////////
78 // ViewManager, private:
79
80 ViewManager::ViewManager(
81 Application* application,
82 const base::Callback<void(ViewManager*)> ready_callback)
83 : ready_callback_(ready_callback),
84 synchronizer_(NULL),
85 tree_(NULL) {
86 application->AddService<ViewManagerSynchronizer>(this);
87 }
88
55 } // namespace view_manager 89 } // namespace view_manager
56 } // namespace mojo 90 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698