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

Side by Side Diff: device/test/usb_test_gadget_impl.cc

Issue 2031743005: Remove use of deprecated MessageLoop methods in device. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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/serial/serial_io_handler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/files/file.h" 14 #include "base/files/file.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/location.h"
16 #include "base/logging.h" 17 #include "base/logging.h"
17 #include "base/macros.h" 18 #include "base/macros.h"
18 #include "base/memory/ptr_util.h" 19 #include "base/memory/ptr_util.h"
19 #include "base/memory/ref_counted.h" 20 #include "base/memory/ref_counted.h"
20 #include "base/path_service.h" 21 #include "base/path_service.h"
21 #include "base/process/process_handle.h" 22 #include "base/process/process_handle.h"
22 #include "base/run_loop.h" 23 #include "base/run_loop.h"
23 #include "base/scoped_observer.h" 24 #include "base/scoped_observer.h"
25 #include "base/single_thread_task_runner.h"
24 #include "base/strings/stringprintf.h" 26 #include "base/strings/stringprintf.h"
25 #include "base/strings/utf_string_conversions.h" 27 #include "base/strings/utf_string_conversions.h"
26 #include "base/threading/thread_task_runner_handle.h" 28 #include "base/threading/thread_task_runner_handle.h"
27 #include "base/time/time.h" 29 #include "base/time/time.h"
28 #include "device/core/device_client.h" 30 #include "device/core/device_client.h"
29 #include "device/test/usb_test_gadget.h" 31 #include "device/test/usb_test_gadget.h"
30 #include "device/usb/usb_device.h" 32 #include "device/usb/usb_device.h"
31 #include "device/usb/usb_device_handle.h" 33 #include "device/usb/usb_device_handle.h"
32 #include "device/usb/usb_service.h" 34 #include "device/usb/usb_service.h"
33 #include "net/base/escape.h" 35 #include "net/base/escape.h"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 232
231 void OnDevicesEnumerated( 233 void OnDevicesEnumerated(
232 const std::vector<scoped_refptr<UsbDevice>>& devices) { 234 const std::vector<scoped_refptr<UsbDevice>>& devices) {
233 for (const scoped_refptr<UsbDevice>& device : devices) { 235 for (const scoped_refptr<UsbDevice>& device : devices) {
234 OnDeviceAdded(device); 236 OnDeviceAdded(device);
235 } 237 }
236 238
237 if (!device_) { 239 if (!device_) {
238 // TODO(reillyg): This timer could be replaced by a way to use long- 240 // TODO(reillyg): This timer could be replaced by a way to use long-
239 // polling to wait for claimed devices to become unclaimed. 241 // polling to wait for claimed devices to become unclaimed.
240 base::MessageLoop::current()->PostDelayedTask( 242 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
241 FROM_HERE, base::Bind(&UsbGadgetFactory::EnumerateDevices, 243 FROM_HERE, base::Bind(&UsbGadgetFactory::EnumerateDevices,
242 weak_factory_.GetWeakPtr()), 244 weak_factory_.GetWeakPtr()),
243 base::TimeDelta::FromMilliseconds(kReenumeratePeriod)); 245 base::TimeDelta::FromMilliseconds(kReenumeratePeriod));
244 } 246 }
245 } 247 }
246 248
247 void OnDeviceAdded(scoped_refptr<UsbDevice> device) override { 249 void OnDeviceAdded(scoped_refptr<UsbDevice> device) override {
248 if (device_.get()) { 250 if (device_.get()) {
249 // Already trying to claim a device. 251 // Already trying to claim a device.
250 return; 252 return;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 } 372 }
371 } 373 }
372 374
373 void Reset() { 375 void Reset() {
374 device_ = nullptr; 376 device_ = nullptr;
375 serial_number_.clear(); 377 serial_number_.clear();
376 claimed_ = false; 378 claimed_ = false;
377 version_.clear(); 379 version_.clear();
378 380
379 // Wait a bit and then try again to find an available device. 381 // Wait a bit and then try again to find an available device.
380 base::MessageLoop::current()->PostDelayedTask( 382 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
381 FROM_HERE, base::Bind(&UsbGadgetFactory::EnumerateDevices, 383 FROM_HERE, base::Bind(&UsbGadgetFactory::EnumerateDevices,
382 weak_factory_.GetWeakPtr()), 384 weak_factory_.GetWeakPtr()),
383 base::TimeDelta::FromMilliseconds(kReenumeratePeriod)); 385 base::TimeDelta::FromMilliseconds(kReenumeratePeriod));
384 } 386 }
385 387
386 UsbService* usb_service_ = nullptr; 388 UsbService* usb_service_ = nullptr;
387 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 389 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
388 std::string session_id_; 390 std::string session_id_;
389 std::unique_ptr<net::URLFetcher> url_fetcher_; 391 std::unique_ptr<net::URLFetcher> url_fetcher_;
390 scoped_refptr<UsbDevice> device_; 392 scoped_refptr<UsbDevice> device_;
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 return false; 613 return false;
612 } 614 }
613 615
614 DeviceAddListener add_listener(usb_service_, device_address_, -1); 616 DeviceAddListener add_listener(usb_service_, device_address_, -1);
615 device_ = add_listener.WaitForAdd(); 617 device_ = add_listener.WaitForAdd();
616 DCHECK(device_.get()); 618 DCHECK(device_.get());
617 return true; 619 return true;
618 } 620 }
619 621
620 } // namespace device 622 } // namespace device
OLDNEW
« no previous file with comments | « device/serial/serial_io_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698