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

Side by Side Diff: device/devices_app/devices_app.cc

Issue 1674903003: Extract shell methods from ApplicationImpl into a base class, and pass this to Initialize() instead. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojom
Patch Set: . Created 4 years, 10 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 | « device/devices_app/devices_app.h ('k') | device/devices_app/devices_apptest.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 "device/devices_app/devices_app.h" 5 #include "device/devices_app/devices_app.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/sequenced_task_runner.h" 13 #include "base/sequenced_task_runner.h"
14 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
15 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "device/core/device_client.h" 17 #include "device/core/device_client.h"
18 #include "device/devices_app/usb/device_manager_impl.h" 18 #include "device/devices_app/usb/device_manager_impl.h"
19 #include "device/usb/usb_service.h" 19 #include "device/usb/usb_service.h"
20 #include "mojo/public/cpp/bindings/interface_request.h" 20 #include "mojo/public/cpp/bindings/interface_request.h"
21 #include "mojo/shell/public/cpp/application_connection.h" 21 #include "mojo/shell/public/cpp/application_connection.h"
22 #include "mojo/shell/public/cpp/application_impl.h" 22 #include "mojo/shell/public/cpp/shell.h"
23 #include "url/gurl.h" 23 #include "url/gurl.h"
24 24
25 namespace device { 25 namespace device {
26 26
27 namespace { 27 namespace {
28 28
29 // The number of seconds to wait without any bound DeviceManagers before 29 // The number of seconds to wait without any bound DeviceManagers before
30 // exiting the app. 30 // exiting the app.
31 const int64_t kIdleTimeoutInSeconds = 10; 31 const int64_t kIdleTimeoutInSeconds = 10;
32 32
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 ~USBServiceInitializer() {} 69 ~USBServiceInitializer() {}
70 70
71 private: 71 private:
72 scoped_ptr<AppDeviceClient> app_device_client_; 72 scoped_ptr<AppDeviceClient> app_device_client_;
73 base::Thread blocking_thread_; 73 base::Thread blocking_thread_;
74 74
75 DISALLOW_COPY_AND_ASSIGN(USBServiceInitializer); 75 DISALLOW_COPY_AND_ASSIGN(USBServiceInitializer);
76 }; 76 };
77 77
78 DevicesApp::DevicesApp() 78 DevicesApp::DevicesApp() : shell_(nullptr), active_device_manager_count_(0) {}
79 : app_impl_(nullptr), active_device_manager_count_(0) {}
80 79
81 DevicesApp::~DevicesApp() { 80 DevicesApp::~DevicesApp() {
82 } 81 }
83 82
84 void DevicesApp::Initialize(mojo::ApplicationImpl* app) { 83 void DevicesApp::Initialize(mojo::Shell* shell,
85 app_impl_ = app; 84 const std::string& url,
85 uint32_t id) {
86 shell_ = shell;
86 service_initializer_.reset(new USBServiceInitializer); 87 service_initializer_.reset(new USBServiceInitializer);
87 StartIdleTimer(); 88 StartIdleTimer();
88 } 89 }
89 90
90 bool DevicesApp::AcceptConnection(mojo::ApplicationConnection* connection) { 91 bool DevicesApp::AcceptConnection(mojo::ApplicationConnection* connection) {
91 connection->AddService<usb::DeviceManager>(this); 92 connection->AddService<usb::DeviceManager>(this);
92 return true; 93 return true;
93 } 94 }
94 95
95 void DevicesApp::Quit() { 96 void DevicesApp::Quit() {
96 service_initializer_.reset(); 97 service_initializer_.reset();
97 app_impl_ = nullptr; 98 shell_ = nullptr;
98 } 99 }
99 100
100 void DevicesApp::Create(mojo::ApplicationConnection* connection, 101 void DevicesApp::Create(mojo::ApplicationConnection* connection,
101 mojo::InterfaceRequest<usb::DeviceManager> request) { 102 mojo::InterfaceRequest<usb::DeviceManager> request) {
102 // Bind the new device manager to the connecting application's permission 103 // Bind the new device manager to the connecting application's permission
103 // provider. 104 // provider.
104 usb::PermissionProviderPtr permission_provider; 105 usb::PermissionProviderPtr permission_provider;
105 connection->ConnectToService(&permission_provider); 106 connection->ConnectToService(&permission_provider);
106 107
107 // Owned by its message pipe. 108 // Owned by its message pipe.
(...skipping 10 matching lines...) Expand all
118 DCHECK_GE(active_device_manager_count_, 0u); 119 DCHECK_GE(active_device_manager_count_, 0u);
119 active_device_manager_count_--; 120 active_device_manager_count_--;
120 if (active_device_manager_count_ == 0) { 121 if (active_device_manager_count_ == 0) {
121 // If the last DeviceManager connection has been dropped, kick off an idle 122 // If the last DeviceManager connection has been dropped, kick off an idle
122 // timeout to shut ourselves down. 123 // timeout to shut ourselves down.
123 StartIdleTimer(); 124 StartIdleTimer();
124 } 125 }
125 } 126 }
126 127
127 void DevicesApp::StartIdleTimer() { 128 void DevicesApp::StartIdleTimer() {
128 // Passing unretained |app_impl_| is safe here because |app_impl_| is 129 // Passing unretained |shell_| is safe here because |shell_| is
129 // guaranteed to outlive |this|, and the callback is canceled if |this| is 130 // guaranteed to outlive |this|, and the callback is canceled if |this| is
130 // destroyed. 131 // destroyed.
131 idle_timeout_callback_.Reset(base::Bind(&mojo::ApplicationImpl::Quit, 132 idle_timeout_callback_.Reset(
132 base::Unretained(app_impl_))); 133 base::Bind(&mojo::Shell::Quit, base::Unretained(shell_)));
133 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 134 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
134 FROM_HERE, idle_timeout_callback_.callback(), 135 FROM_HERE, idle_timeout_callback_.callback(),
135 base::TimeDelta::FromSeconds(kIdleTimeoutInSeconds)); 136 base::TimeDelta::FromSeconds(kIdleTimeoutInSeconds));
136 } 137 }
137 138
138 } // namespace device 139 } // namespace device
OLDNEW
« no previous file with comments | « device/devices_app/devices_app.h ('k') | device/devices_app/devices_apptest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698