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

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

Issue 2476063002: Service Manager: Rework Service and ServiceContext lifetime (Closed)
Patch Set: . Created 4 years, 1 month 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/catalog_viewer/catalog_viewer.h ('k') | mash/example/views_examples/views_examples.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/catalog_viewer/catalog_viewer.h" 5 #include "mash/catalog_viewer/catalog_viewer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "mojo/public/cpp/bindings/binding.h" 15 #include "mojo/public/cpp/bindings/binding.h"
16 #include "services/catalog/public/interfaces/catalog.mojom.h" 16 #include "services/catalog/public/interfaces/catalog.mojom.h"
17 #include "services/service_manager/public/cpp/connection.h" 17 #include "services/service_manager/public/cpp/connection.h"
18 #include "services/service_manager/public/cpp/connector.h" 18 #include "services/service_manager/public/cpp/connector.h"
19 #include "services/service_manager/public/cpp/interface_registry.h"
20 #include "services/service_manager/public/cpp/service_context.h"
19 #include "ui/base/models/table_model.h" 21 #include "ui/base/models/table_model.h"
20 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/resources/grit/ui_resources.h" 23 #include "ui/resources/grit/ui_resources.h"
22 #include "ui/views/background.h" 24 #include "ui/views/background.h"
23 #include "ui/views/controls/table/table_view.h" 25 #include "ui/views/controls/table/table_view.h"
24 #include "ui/views/controls/table/table_view_observer.h" 26 #include "ui/views/controls/table/table_view_observer.h"
25 #include "ui/views/mus/aura_init.h" 27 #include "ui/views/mus/aura_init.h"
26 #include "ui/views/mus/window_manager_connection.h" 28 #include "ui/views/mus/window_manager_connection.h"
27 #include "ui/views/widget/widget_delegate.h" 29 #include "ui/views/widget/widget_delegate.h"
28 30
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 CatalogViewer::~CatalogViewer() {} 160 CatalogViewer::~CatalogViewer() {}
159 161
160 void CatalogViewer::RemoveWindow(views::Widget* window) { 162 void CatalogViewer::RemoveWindow(views::Widget* window) {
161 auto it = std::find(windows_.begin(), windows_.end(), window); 163 auto it = std::find(windows_.begin(), windows_.end(), window);
162 DCHECK(it != windows_.end()); 164 DCHECK(it != windows_.end());
163 windows_.erase(it); 165 windows_.erase(it);
164 if (windows_.empty()) 166 if (windows_.empty())
165 base::MessageLoop::current()->QuitWhenIdle(); 167 base::MessageLoop::current()->QuitWhenIdle();
166 } 168 }
167 169
168 void CatalogViewer::OnStart(const service_manager::ServiceInfo& info) { 170 void CatalogViewer::OnStart(service_manager::ServiceContext* context) {
169 tracing_.Initialize(connector(), info.identity.name()); 171 context_ = context;
172 tracing_.Initialize(context->connector(), context->identity().name());
170 173
171 aura_init_ = base::MakeUnique<views::AuraInit>(connector(), info.identity, 174 aura_init_ = base::MakeUnique<views::AuraInit>(
172 "views_mus_resources.pak"); 175 context->connector(), context->identity(), "views_mus_resources.pak");
173 window_manager_connection_ = 176 window_manager_connection_ = views::WindowManagerConnection::Create(
174 views::WindowManagerConnection::Create(connector(), info.identity); 177 context->connector(), context->identity());
175 } 178 }
176 179
177 bool CatalogViewer::OnConnect(const service_manager::ServiceInfo& remote_info, 180 bool CatalogViewer::OnConnect(const service_manager::ServiceInfo& remote_info,
178 service_manager::InterfaceRegistry* registry) { 181 service_manager::InterfaceRegistry* registry) {
179 registry->AddInterface<mojom::Launchable>(this); 182 registry->AddInterface<mojom::Launchable>(this);
180 return true; 183 return true;
181 } 184 }
182 185
183 void CatalogViewer::Launch(uint32_t what, mojom::LaunchMode how) { 186 void CatalogViewer::Launch(uint32_t what, mojom::LaunchMode how) {
184 bool reuse = how == mojom::LaunchMode::REUSE || 187 bool reuse = how == mojom::LaunchMode::REUSE ||
185 how == mojom::LaunchMode::DEFAULT; 188 how == mojom::LaunchMode::DEFAULT;
186 if (reuse && !windows_.empty()) { 189 if (reuse && !windows_.empty()) {
187 windows_.back()->Activate(); 190 windows_.back()->Activate();
188 return; 191 return;
189 } 192 }
190 catalog::mojom::CatalogPtr catalog; 193 catalog::mojom::CatalogPtr catalog;
191 connector()->ConnectToInterface("service:catalog", &catalog); 194 context_->connector()->ConnectToInterface("service:catalog", &catalog);
192 195
193 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( 196 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds(
194 new CatalogViewerContents(this, std::move(catalog)), nullptr, 197 new CatalogViewerContents(this, std::move(catalog)), nullptr,
195 gfx::Rect(25, 25, 500, 600)); 198 gfx::Rect(25, 25, 500, 600));
196 window->Show(); 199 window->Show();
197 windows_.push_back(window); 200 windows_.push_back(window);
198 } 201 }
199 202
200 void CatalogViewer::Create(const service_manager::Identity& remote_identity, 203 void CatalogViewer::Create(const service_manager::Identity& remote_identity,
201 mojom::LaunchableRequest request) { 204 mojom::LaunchableRequest request) {
202 bindings_.AddBinding(this, std::move(request)); 205 bindings_.AddBinding(this, std::move(request));
203 } 206 }
204 207
205 } // namespace catalog_viewer 208 } // namespace catalog_viewer
206 } // namespace mash 209 } // namespace mash
OLDNEW
« no previous file with comments | « mash/catalog_viewer/catalog_viewer.h ('k') | mash/example/views_examples/views_examples.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698