| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "mash/shell/shell_application_delegate.h" | 5 #include "mash/shell/shell_application_delegate.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "mash/screenlock/public/interfaces/screenlock.mojom.h" |
| 8 #include "mojo/shell/public/cpp/application_connection.h" | 9 #include "mojo/shell/public/cpp/application_connection.h" |
| 9 #include "mojo/shell/public/cpp/application_impl.h" | 10 #include "mojo/shell/public/cpp/application_impl.h" |
| 10 | 11 |
| 11 namespace mash { | 12 namespace mash { |
| 12 namespace shell { | 13 namespace shell { |
| 13 | 14 |
| 14 ShellApplicationDelegate::ShellApplicationDelegate() : app_(nullptr) {} | 15 ShellApplicationDelegate::ShellApplicationDelegate() : app_(nullptr) {} |
| 15 | 16 |
| 16 ShellApplicationDelegate::~ShellApplicationDelegate() {} | 17 ShellApplicationDelegate::~ShellApplicationDelegate() {} |
| 17 | 18 |
| 18 void ShellApplicationDelegate::Initialize(mojo::ApplicationImpl* app) { | 19 void ShellApplicationDelegate::Initialize(mojo::ApplicationImpl* app) { |
| 19 app_ = app; | 20 app_ = app; |
| 20 StartBrowserDriver(); | 21 StartBrowserDriver(); |
| 21 StartWindowManager(); | 22 StartWindowManager(); |
| 22 StartWallpaper(); | 23 StartWallpaper(); |
| 23 StartShelf(); | 24 StartShelf(); |
| 24 StartQuickLaunch(); | 25 StartQuickLaunch(); |
| 25 } | 26 } |
| 26 | 27 |
| 27 bool ShellApplicationDelegate::ConfigureIncomingConnection( | 28 bool ShellApplicationDelegate::ConfigureIncomingConnection( |
| 28 mojo::ApplicationConnection* connection) { | 29 mojo::ApplicationConnection* connection) { |
| 29 return false; | 30 connection->AddService<mash::shell::mojom::Shell>(this); |
| 31 return true; |
| 32 } |
| 33 |
| 34 void ShellApplicationDelegate::LockScreen() { |
| 35 StartScreenlock(); |
| 36 } |
| 37 void ShellApplicationDelegate::UnlockScreen() { |
| 38 StopScreenlock(); |
| 39 } |
| 40 |
| 41 void ShellApplicationDelegate::Create( |
| 42 mojo::ApplicationConnection* connection, |
| 43 mojo::InterfaceRequest<mash::shell::mojom::Shell> r) { |
| 44 bindings_.AddBinding(this, std::move(r)); |
| 30 } | 45 } |
| 31 | 46 |
| 32 void ShellApplicationDelegate::StartWindowManager() { | 47 void ShellApplicationDelegate::StartWindowManager() { |
| 33 StartRestartableService( | 48 StartRestartableService( |
| 34 "mojo:desktop_wm", | 49 "mojo:desktop_wm", |
| 35 base::Bind(&ShellApplicationDelegate::StartWindowManager, | 50 base::Bind(&ShellApplicationDelegate::StartWindowManager, |
| 36 base::Unretained(this))); | 51 base::Unretained(this))); |
| 37 } | 52 } |
| 38 | 53 |
| 39 void ShellApplicationDelegate::StartWallpaper() { | 54 void ShellApplicationDelegate::StartWallpaper() { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 55 base::Unretained(this))); | 70 base::Unretained(this))); |
| 56 } | 71 } |
| 57 | 72 |
| 58 void ShellApplicationDelegate::StartQuickLaunch() { | 73 void ShellApplicationDelegate::StartQuickLaunch() { |
| 59 StartRestartableService( | 74 StartRestartableService( |
| 60 "mojo:quick_launch", | 75 "mojo:quick_launch", |
| 61 base::Bind(&ShellApplicationDelegate::StartQuickLaunch, | 76 base::Bind(&ShellApplicationDelegate::StartQuickLaunch, |
| 62 base::Unretained(this))); | 77 base::Unretained(this))); |
| 63 } | 78 } |
| 64 | 79 |
| 80 void ShellApplicationDelegate::StartScreenlock() { |
| 81 StartRestartableService( |
| 82 "mojo:screenlock", |
| 83 base::Bind(&ShellApplicationDelegate::StartScreenlock, |
| 84 base::Unretained(this))); |
| 85 } |
| 86 |
| 87 void ShellApplicationDelegate::StopScreenlock() { |
| 88 auto connection = connections_.find("mojo:screenlock"); |
| 89 DCHECK(connections_.end() != connection); |
| 90 mash::screenlock::mojom::ScreenlockPtr screenlock; |
| 91 connection->second->ConnectToService(&screenlock); |
| 92 screenlock->Quit(); |
| 93 connections_.erase(connection); |
| 94 } |
| 95 |
| 65 void ShellApplicationDelegate::StartRestartableService( | 96 void ShellApplicationDelegate::StartRestartableService( |
| 66 const std::string& url, | 97 const std::string& url, |
| 67 const base::Closure& restart_callback) { | 98 const base::Closure& restart_callback) { |
| 68 // TODO(beng): This would be the place to insert logic that counted restarts | 99 // TODO(beng): This would be the place to insert logic that counted restarts |
| 69 // to avoid infinite crash-restart loops. | 100 // to avoid infinite crash-restart loops. |
| 70 scoped_ptr<mojo::ApplicationConnection> connection = | 101 scoped_ptr<mojo::ApplicationConnection> connection = |
| 71 app_->ConnectToApplication(url); | 102 app_->ConnectToApplication(url); |
| 72 connection->SetRemoteServiceProviderConnectionErrorHandler(restart_callback); | 103 connection->SetRemoteServiceProviderConnectionErrorHandler(restart_callback); |
| 73 connections_[url] = std::move(connection); | 104 connections_[url] = std::move(connection); |
| 74 } | 105 } |
| 75 | 106 |
| 76 } // namespace shell | 107 } // namespace shell |
| 77 } // namespace main | 108 } // namespace main |
| OLD | NEW |