| OLD | NEW |
| 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 "base/at_exit.h" |
| 5 #include "base/bind.h" | 6 #include "base/bind.h" |
| 6 #include "mojo/public/cpp/bindings/allocation_scope.h" | 7 #include "base/command_line.h" |
| 7 #include "mojo/public/cpp/bindings/remote_ptr.h" | 8 #include "base/message_loop/message_loop.h" |
| 8 #include "mojo/public/cpp/environment/environment.h" | 9 #include "mojo/public/cpp/environment/environment.h" |
| 9 #include "mojo/public/cpp/shell/application.h" | 10 #include "mojo/public/cpp/shell/application.h" |
| 10 #include "mojo/public/cpp/system/core.h" | 11 #include "mojo/public/cpp/system/core.h" |
| 11 #include "mojo/public/cpp/system/macros.h" | 12 #include "mojo/public/cpp/system/macros.h" |
| 12 #include "mojo/public/cpp/utility/run_loop.h" | 13 #include "mojo/public/cpp/utility/run_loop.h" |
| 13 #include "mojo/public/interfaces/shell/shell.mojom.h" | 14 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
| 14 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" | 15 #include "mojo/services/public/cpp/view_manager/view_tree_node.h" |
| 15 | 16 |
| 16 #if defined(WIN32) | 17 #if defined(WIN32) |
| 17 #if !defined(CDECL) | 18 #if !defined(CDECL) |
| 18 #define CDECL __cdecl | 19 #define CDECL __cdecl |
| 19 #endif | 20 #endif |
| 20 #define SAMPLE_APP_EXPORT __declspec(dllexport) | 21 #define SAMPLE_APP_EXPORT __declspec(dllexport) |
| 21 #else | 22 #else |
| 22 #define CDECL | 23 #define CDECL |
| 23 #define SAMPLE_APP_EXPORT __attribute__((visibility("default"))) | 24 #define SAMPLE_APP_EXPORT __attribute__((visibility("default"))) |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 namespace mojo { | 27 namespace mojo { |
| 27 namespace examples { | 28 namespace examples { |
| 28 | 29 |
| 29 class SampleApp : public Application, | 30 class SampleApp : public Application { |
| 30 public services::view_manager::ViewManagerClient { | |
| 31 public: | 31 public: |
| 32 explicit SampleApp(MojoHandle shell_handle) : Application(shell_handle) { | 32 explicit SampleApp(MojoHandle shell_handle) |
| 33 InterfacePipe<services::view_manager::ViewManager, AnyInterface> | 33 : Application(shell_handle) { |
| 34 view_manager_pipe; | 34 view_manager_.reset(new services::view_manager::ViewManager(shell())); |
| 35 AllocationScope scope; | 35 node_1_.reset( |
| 36 shell()->Connect("mojo:mojo_view_manager", | 36 new services::view_manager::ViewTreeNode(view_manager_.get())); |
| 37 view_manager_pipe.handle_to_peer.Pass()); | 37 node_11_.reset( |
| 38 view_manager_.reset(view_manager_pipe.handle_to_self.Pass(), this); | 38 new services::view_manager::ViewTreeNode(view_manager_.get())); |
| 39 view_manager_->CreateNode(1, base::Bind(&SampleApp::OnCreatedView, | 39 node_1_->AddChild(node_11_.get()); |
| 40 base::Unretained(this))); | |
| 41 } | 40 } |
| 42 | 41 |
| 43 virtual ~SampleApp() { | 42 virtual ~SampleApp() { |
| 44 } | 43 } |
| 45 | 44 |
| 46 // ViewManagerClient:: | 45 private: |
| 47 virtual void OnConnectionEstablished(uint16_t connection_id) OVERRIDE { | 46 // SampleApp creates a ViewManager and a trivial node hierarchy. |
| 48 } | 47 scoped_ptr<services::view_manager::ViewManager> view_manager_; |
| 49 virtual void OnNodeHierarchyChanged(uint32_t node, | 48 scoped_ptr<services::view_manager::ViewTreeNode> node_1_; |
| 50 uint32_t new_parent, | 49 scoped_ptr<services::view_manager::ViewTreeNode> node_11_; |
| 51 uint32_t old_parent, | |
| 52 uint32_t change_id) OVERRIDE { | |
| 53 } | |
| 54 virtual void OnNodeViewReplaced(uint32_t node, | |
| 55 uint32_t old_view_id, | |
| 56 uint32_t new_view_id, | |
| 57 uint32_t change_id) OVERRIDE { | |
| 58 } | |
| 59 | 50 |
| 60 private: | 51 DISALLOW_COPY_AND_ASSIGN(SampleApp); |
| 61 void OnCreatedView(bool success) { | |
| 62 DCHECK(success); | |
| 63 } | |
| 64 | |
| 65 RemotePtr<services::view_manager::ViewManager> view_manager_; | |
| 66 }; | 52 }; |
| 67 | 53 |
| 68 } // namespace examples | 54 } // namespace examples |
| 69 } // namespace mojo | 55 } // namespace mojo |
| 70 | 56 |
| 71 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain( | 57 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain( |
| 72 MojoHandle shell_handle) { | 58 MojoHandle shell_handle) { |
| 73 mojo::Environment env; | 59 base::MessageLoop loop; |
| 74 mojo::RunLoop loop; | |
| 75 | 60 |
| 76 mojo::examples::SampleApp app(shell_handle); | 61 mojo::examples::SampleApp app(shell_handle); |
| 77 loop.Run(); | 62 loop.Run(); |
| 78 return MOJO_RESULT_OK; | 63 return MOJO_RESULT_OK; |
| 79 } | 64 } |
| OLD | NEW |