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

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

Issue 2179023004: Make Service own ServiceContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 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/browser/browser.h » ('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/app_driver/app_driver.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"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 }; 50 };
51 51
52 void AssertTrue(bool success) { 52 void AssertTrue(bool success) {
53 DCHECK(success); 53 DCHECK(success);
54 } 54 }
55 55
56 void DoNothing() {} 56 void DoNothing() {}
57 57
58 } // namespace 58 } // namespace
59 59
60 AppDriver::AppDriver() 60 AppDriver::AppDriver() : binding_(this), weak_factory_(this) {}
61 : connector_(nullptr), binding_(this), weak_factory_(this) {}
62 61
63 AppDriver::~AppDriver() {} 62 AppDriver::~AppDriver() {}
64 63
65 void AppDriver::OnAvailableCatalogEntries( 64 void AppDriver::OnAvailableCatalogEntries(
66 mojo::Array<catalog::mojom::EntryPtr> entries) { 65 mojo::Array<catalog::mojom::EntryPtr> entries) {
67 if (entries.empty()) { 66 if (entries.empty()) {
68 LOG(ERROR) << "Unable to install accelerators for launching chrome."; 67 LOG(ERROR) << "Unable to install accelerators for launching chrome.";
69 return; 68 return;
70 } 69 }
71 70
72 ui::mojom::AcceleratorRegistrarPtr registrar; 71 ui::mojom::AcceleratorRegistrarPtr registrar;
73 connector_->ConnectToInterface(entries[0]->name, &registrar); 72 connector()->ConnectToInterface(entries[0]->name, &registrar);
74 73
75 if (binding_.is_bound()) 74 if (binding_.is_bound())
76 binding_.Unbind(); 75 binding_.Unbind();
77 registrar->SetHandler(binding_.CreateInterfacePtrAndBind()); 76 registrar->SetHandler(binding_.CreateInterfacePtrAndBind());
78 // If the window manager restarts, the handler pipe will close and we'll need 77 // If the window manager restarts, the handler pipe will close and we'll need
79 // to re-add our accelerators when the window manager comes back up. 78 // to re-add our accelerators when the window manager comes back up.
80 binding_.set_connection_error_handler( 79 binding_.set_connection_error_handler(
81 base::Bind(&AppDriver::AddAccelerators, weak_factory_.GetWeakPtr())); 80 base::Bind(&AppDriver::AddAccelerators, weak_factory_.GetWeakPtr()));
82 81
83 for (const AcceleratorSpec& spec : g_spec) { 82 for (const AcceleratorSpec& spec : g_spec) {
84 registrar->AddAccelerator( 83 registrar->AddAccelerator(
85 static_cast<uint32_t>(spec.id), 84 static_cast<uint32_t>(spec.id),
86 ui::CreateKeyMatcher(spec.keyboard_code, spec.event_flags), 85 ui::CreateKeyMatcher(spec.keyboard_code, spec.event_flags),
87 base::Bind(&AssertTrue)); 86 base::Bind(&AssertTrue));
88 } 87 }
89 } 88 }
90 89
91 void AppDriver::OnStart(shell::Connector* connector, 90 void AppDriver::OnStart(const shell::Identity& identity) {
92 const shell::Identity& identity,
93 uint32_t id) {
94 connector_ = connector;
95 AddAccelerators(); 91 AddAccelerators();
96 } 92 }
97 93
98 bool AppDriver::OnConnect(shell::Connection* connection) { 94 bool AppDriver::OnConnect(shell::Connection* connection) {
99 return true; 95 return true;
100 } 96 }
101 97
102 bool AppDriver::OnStop() { 98 bool AppDriver::OnStop() {
103 // Prevent the code in AddAccelerators() from keeping this app alive. 99 // Prevent the code in AddAccelerators() from keeping this app alive.
104 binding_.set_connection_error_handler(base::Bind(&DoNothing)); 100 binding_.set_connection_error_handler(base::Bind(&DoNothing));
(...skipping 17 matching lines...) Expand all
122 {Accelerator::ShowTaskManager, 118 {Accelerator::ShowTaskManager,
123 {mojom::kWindow, "mojo:task_viewer", LaunchMode::DEFAULT}}, 119 {mojom::kWindow, "mojo:task_viewer", LaunchMode::DEFAULT}},
124 {Accelerator::ToggleTouchHud, 120 {Accelerator::ToggleTouchHud,
125 {mojom::kWindow, "mojo:touch_hud", LaunchMode::DEFAULT}}, 121 {mojom::kWindow, "mojo:touch_hud", LaunchMode::DEFAULT}},
126 }; 122 };
127 123
128 const auto iter = options.find(static_cast<Accelerator>(id)); 124 const auto iter = options.find(static_cast<Accelerator>(id));
129 DCHECK(iter != options.end()); 125 DCHECK(iter != options.end());
130 const LaunchOptions& entry = iter->second; 126 const LaunchOptions& entry = iter->second;
131 LaunchablePtr launchable; 127 LaunchablePtr launchable;
132 connector_->ConnectToInterface(entry.app, &launchable); 128 connector()->ConnectToInterface(entry.app, &launchable);
133 launchable->Launch(entry.option, entry.mode); 129 launchable->Launch(entry.option, entry.mode);
134 } 130 }
135 131
136 void AppDriver::AddAccelerators() { 132 void AppDriver::AddAccelerators() {
137 connector_->ConnectToInterface("mojo:catalog", &catalog_); 133 connector()->ConnectToInterface("mojo:catalog", &catalog_);
138 catalog_->GetEntriesProvidingClass( 134 catalog_->GetEntriesProvidingClass(
139 "mus:window_manager", base::Bind(&AppDriver::OnAvailableCatalogEntries, 135 "mus:window_manager", base::Bind(&AppDriver::OnAvailableCatalogEntries,
140 weak_factory_.GetWeakPtr())); 136 weak_factory_.GetWeakPtr()));
141 } 137 }
142 138
143 } // namespace app_driver 139 } // namespace app_driver
144 } // namespace mash 140 } // namespace mash
OLDNEW
« no previous file with comments | « mash/app_driver/app_driver.h ('k') | mash/browser/browser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698