Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / components / window_manager / main.cc
blob5f500264b8d63409bb7f7f621434083d1dac6f3f
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
3 // found in the LICENSE file.
5 #include "base/memory/scoped_ptr.h"
6 #include "components/view_manager/public/cpp/view_manager.h"
7 #include "components/view_manager/public/cpp/view_manager_delegate.h"
8 #include "components/window_manager/window_manager_app.h"
9 #include "components/window_manager/window_manager_delegate.h"
10 #include "mojo/application/application_runner_chromium.h"
11 #include "mojo/common/tracing_impl.h"
12 #include "third_party/mojo/src/mojo/public/c/system/main.h"
13 #include "third_party/mojo/src/mojo/public/cpp/application/application_delegate.h"
14 #include "third_party/mojo/src/mojo/public/cpp/application/service_provider_impl.h"
16 // ApplicationDelegate implementation file for WindowManager users (e.g.
17 // core window manager tests) that do not want to provide their own
18 // ApplicationDelegate::Create().
20 using mojo::View;
21 using mojo::ViewManager;
23 namespace window_manager {
25 class DefaultWindowManager : public mojo::ApplicationDelegate,
26 public mojo::ViewManagerDelegate,
27 public WindowManagerDelegate {
28 public:
29 DefaultWindowManager()
30 : window_manager_app_(new WindowManagerApp(this, this)),
31 root_(nullptr),
32 window_offset_(10) {
34 ~DefaultWindowManager() override {}
36 private:
37 // Overridden from mojo::ApplicationDelegate:
38 void Initialize(mojo::ApplicationImpl* impl) override {
39 window_manager_app_->Initialize(impl);
40 tracing_.Initialize(impl);
42 bool ConfigureIncomingConnection(
43 mojo::ApplicationConnection* connection) override {
44 window_manager_app_->ConfigureIncomingConnection(connection);
45 return true;
48 // Overridden from ViewManagerDelegate:
49 void OnEmbed(View* root,
50 mojo::InterfaceRequest<mojo::ServiceProvider> services,
51 mojo::ServiceProviderPtr exposed_services) override {
52 root_ = root;
54 void OnViewManagerDisconnected(ViewManager* view_manager) override {}
56 // Overridden from WindowManagerDelegate:
57 void Embed(const mojo::String& url,
58 mojo::InterfaceRequest<mojo::ServiceProvider> services,
59 mojo::ServiceProviderPtr exposed_services) override {
60 DCHECK(root_);
61 View* view = root_->view_manager()->CreateView();
62 root_->AddChild(view);
64 mojo::Rect rect;
65 rect.x = rect.y = window_offset_;
66 rect.width = rect.height = 100;
67 view->SetBounds(rect);
68 window_offset_ += 10;
70 view->SetVisible(true);
71 view->Embed(url, services.Pass(), exposed_services.Pass());
74 scoped_ptr<WindowManagerApp> window_manager_app_;
76 View* root_;
77 int window_offset_;
78 mojo::TracingImpl tracing_;
80 MOJO_DISALLOW_COPY_AND_ASSIGN(DefaultWindowManager);
83 } // namespace window_manager
85 MojoResult MojoMain(MojoHandle shell_handle) {
86 mojo::ApplicationRunnerChromium runner(
87 new window_manager::DefaultWindowManager);
88 return runner.Run(shell_handle);