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

Side by Side Diff: mash/app_driver/app_driver.cc

Issue 1989333003: mash: Rename browser_driver to app_driver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 7 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
« no previous file with comments | « mash/app_driver/app_driver.h ('k') | mash/app_driver/main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/browser_driver/browser_driver_application_delegate.h" 5 #include "mash/app_driver/app_driver.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "components/mus/common/event_matcher_util.h" 11 #include "components/mus/common/event_matcher_util.h"
12 #include "mash/public/interfaces/launchable.mojom.h" 12 #include "mash/public/interfaces/launchable.mojom.h"
13 #include "services/shell/public/cpp/connection.h" 13 #include "services/shell/public/cpp/connection.h"
14 #include "services/shell/public/cpp/connector.h" 14 #include "services/shell/public/cpp/connector.h"
15 15
16 using mash::mojom::LaunchablePtr; 16 using mash::mojom::LaunchablePtr;
17 using mash::mojom::LaunchMode; 17 using mash::mojom::LaunchMode;
18 18
19 namespace mash { 19 namespace mash {
20 namespace browser_driver { 20 namespace app_driver {
21 namespace { 21 namespace {
22 22
23 enum class Accelerator : uint32_t { 23 enum class Accelerator : uint32_t {
24 NewWindow, 24 NewWindow,
25 NewTab, 25 NewTab,
26 NewIncognitoWindow, 26 NewIncognitoWindow,
27 }; 27 };
28 28
29 struct AcceleratorSpec { 29 struct AcceleratorSpec {
30 Accelerator id; 30 Accelerator id;
(...skipping 13 matching lines...) Expand all
44 }; 44 };
45 45
46 void AssertTrue(bool success) { 46 void AssertTrue(bool success) {
47 DCHECK(success); 47 DCHECK(success);
48 } 48 }
49 49
50 void DoNothing() {} 50 void DoNothing() {}
51 51
52 } // namespace 52 } // namespace
53 53
54 BrowserDriverApplicationDelegate::BrowserDriverApplicationDelegate() 54 AppDriver::AppDriver()
55 : connector_(nullptr), 55 : connector_(nullptr), binding_(this), weak_factory_(this) {}
56 binding_(this),
57 weak_factory_(this) {}
58 56
59 BrowserDriverApplicationDelegate::~BrowserDriverApplicationDelegate() {} 57 AppDriver::~AppDriver() {}
60 58
61 void BrowserDriverApplicationDelegate::OnAvailableCatalogEntries( 59 void AppDriver::OnAvailableCatalogEntries(
62 const mojo::Array<catalog::mojom::EntryPtr>& entries) { 60 const mojo::Array<catalog::mojom::EntryPtr>& entries) {
63 if (entries.empty()) { 61 if (entries.empty()) {
64 LOG(ERROR) << "Unable to install accelerators for launching chrome."; 62 LOG(ERROR) << "Unable to install accelerators for launching chrome.";
65 return; 63 return;
66 } 64 }
67 65
68 mus::mojom::AcceleratorRegistrarPtr registrar; 66 mus::mojom::AcceleratorRegistrarPtr registrar;
69 connector_->ConnectToInterface(entries[0]->name, &registrar); 67 connector_->ConnectToInterface(entries[0]->name, &registrar);
70 68
71 if (binding_.is_bound()) 69 if (binding_.is_bound())
72 binding_.Unbind(); 70 binding_.Unbind();
73 registrar->SetHandler(binding_.CreateInterfacePtrAndBind()); 71 registrar->SetHandler(binding_.CreateInterfacePtrAndBind());
74 // If the window manager restarts, the handler pipe will close and we'll need 72 // If the window manager restarts, the handler pipe will close and we'll need
75 // to re-add our accelerators when the window manager comes back up. 73 // to re-add our accelerators when the window manager comes back up.
76 binding_.set_connection_error_handler( 74 binding_.set_connection_error_handler(
77 base::Bind(&BrowserDriverApplicationDelegate::AddAccelerators, 75 base::Bind(&AppDriver::AddAccelerators, weak_factory_.GetWeakPtr()));
78 weak_factory_.GetWeakPtr()));
79 76
80 for (const AcceleratorSpec& spec : g_spec) { 77 for (const AcceleratorSpec& spec : g_spec) {
81 registrar->AddAccelerator( 78 registrar->AddAccelerator(
82 static_cast<uint32_t>(spec.id), 79 static_cast<uint32_t>(spec.id),
83 mus::CreateKeyMatcher(spec.keyboard_code, spec.event_flags), 80 mus::CreateKeyMatcher(spec.keyboard_code, spec.event_flags),
84 base::Bind(&AssertTrue)); 81 base::Bind(&AssertTrue));
85 } 82 }
86 } 83 }
87 84
88 void BrowserDriverApplicationDelegate::Initialize( 85 void AppDriver::Initialize(shell::Connector* connector,
89 shell::Connector* connector, 86 const shell::Identity& identity,
90 const shell::Identity& identity, 87 uint32_t id) {
91 uint32_t id) {
92 connector_ = connector; 88 connector_ = connector;
93 AddAccelerators(); 89 AddAccelerators();
94 } 90 }
95 91
96 bool BrowserDriverApplicationDelegate::AcceptConnection( 92 bool AppDriver::AcceptConnection(shell::Connection* connection) {
97 shell::Connection* connection) {
98 return true; 93 return true;
99 } 94 }
100 95
101 bool BrowserDriverApplicationDelegate::ShellConnectionLost() { 96 bool AppDriver::ShellConnectionLost() {
102 // Prevent the code in AddAccelerators() from keeping this app alive. 97 // Prevent the code in AddAccelerators() from keeping this app alive.
103 binding_.set_connection_error_handler(base::Bind(&DoNothing)); 98 binding_.set_connection_error_handler(base::Bind(&DoNothing));
104 return true; 99 return true;
105 } 100 }
106 101
107 void BrowserDriverApplicationDelegate::OnAccelerator( 102 void AppDriver::OnAccelerator(uint32_t id, mus::mojom::EventPtr event) {
108 uint32_t id, mus::mojom::EventPtr event) {
109 uint32_t option = mojom::kWindow; 103 uint32_t option = mojom::kWindow;
110 switch (static_cast<Accelerator>(id)) { 104 switch (static_cast<Accelerator>(id)) {
111 case Accelerator::NewWindow: 105 case Accelerator::NewWindow:
112 option = mojom::kWindow; 106 option = mojom::kWindow;
113 break; 107 break;
114 case Accelerator::NewTab: 108 case Accelerator::NewTab:
115 option = mojom::kDocument; 109 option = mojom::kDocument;
116 break; 110 break;
117 case Accelerator::NewIncognitoWindow: 111 case Accelerator::NewIncognitoWindow:
118 option = mojom::kIncognitoWindow; 112 option = mojom::kIncognitoWindow;
119 break; 113 break;
120 default: 114 default:
121 NOTREACHED(); 115 NOTREACHED();
122 break; 116 break;
123 } 117 }
124 LaunchablePtr launchable; 118 LaunchablePtr launchable;
125 connector_->ConnectToInterface("exe:chrome", &launchable); 119 connector_->ConnectToInterface("exe:chrome", &launchable);
126 launchable->Launch(option, LaunchMode::MAKE_NEW); 120 launchable->Launch(option, LaunchMode::MAKE_NEW);
127 } 121 }
128 122
129 void BrowserDriverApplicationDelegate::AddAccelerators() { 123 void AppDriver::AddAccelerators() {
130 connector_->ConnectToInterface("mojo:catalog", &catalog_); 124 connector_->ConnectToInterface("mojo:catalog", &catalog_);
131 catalog_->GetEntriesProvidingClass( 125 catalog_->GetEntriesProvidingClass(
132 "mus:window_manager", 126 "mus:window_manager", base::Bind(&AppDriver::OnAvailableCatalogEntries,
133 base::Bind(&BrowserDriverApplicationDelegate::OnAvailableCatalogEntries, 127 weak_factory_.GetWeakPtr()));
134 weak_factory_.GetWeakPtr()));
135 } 128 }
136 129
137 } // namespace browser_driver 130 } // namespace app_driver
138 } // namespace mash 131 } // namespace mash
OLDNEW
« no previous file with comments | « mash/app_driver/app_driver.h ('k') | mash/app_driver/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698