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

Side by Side Diff: chrome/browser/devtools/device/devtools_android_bridge.cc

Issue 278343002: Added device count test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
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 "chrome/browser/devtools/device/devtools_android_bridge.h" 5 #include "chrome/browser/devtools/device/devtools_android_bridge.h"
6 6
7 #include <map> 7 #include <map>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 // Shut down thread on FILE thread to join into IO. 1191 // Shut down thread on FILE thread to join into IO.
1192 BrowserThread::PostTask( 1192 BrowserThread::PostTask(
1193 BrowserThread::FILE, FROM_HERE, 1193 BrowserThread::FILE, FROM_HERE,
1194 base::Bind(&HandlerThread::StopThread, thread_)); 1194 base::Bind(&HandlerThread::StopThread, thread_));
1195 } 1195 }
1196 1196
1197 // DevToolsAndroidBridge ------------------------------------------------------ 1197 // DevToolsAndroidBridge ------------------------------------------------------
1198 1198
1199 DevToolsAndroidBridge::DevToolsAndroidBridge(Profile* profile) 1199 DevToolsAndroidBridge::DevToolsAndroidBridge(Profile* profile)
1200 : profile_(profile), 1200 : profile_(profile),
1201 handler_thread_(HandlerThread::GetInstance()) { 1201 handler_thread_(HandlerThread::GetInstance()),
1202 polling_interval_for_test_(0) {
1202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1203 pref_change_registrar_.Init(profile_->GetPrefs()); 1204 pref_change_registrar_.Init(profile_->GetPrefs());
1204 pref_change_registrar_.Add(prefs::kDevToolsDiscoverUsbDevicesEnabled, 1205 pref_change_registrar_.Add(prefs::kDevToolsDiscoverUsbDevicesEnabled,
1205 base::Bind(&DevToolsAndroidBridge::CreateDeviceProviders, 1206 base::Bind(&DevToolsAndroidBridge::CreateDeviceProviders,
1206 base::Unretained(this))); 1207 base::Unretained(this)));
1207 CreateDeviceProviders(); 1208 CreateDeviceProviders();
1208 base::PostTaskAndReplyWithResult( 1209 base::PostTaskAndReplyWithResult(
1209 device_message_loop()->message_loop_proxy(), 1210 device_message_loop()->message_loop_proxy(),
1210 FROM_HERE, 1211 FROM_HERE,
1211 base::Bind(&AndroidDeviceManager::Create), 1212 base::Bind(&AndroidDeviceManager::Create),
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 return; 1299 return;
1299 1300
1300 DeviceListListeners copy(device_list_listeners_); 1301 DeviceListListeners copy(device_list_listeners_);
1301 for (DeviceListListeners::iterator it = copy.begin(); it != copy.end(); ++it) 1302 for (DeviceListListeners::iterator it = copy.begin(); it != copy.end(); ++it)
1302 (*it)->DeviceListChanged(*devices.get()); 1303 (*it)->DeviceListChanged(*devices.get());
1303 1304
1304 BrowserThread::PostDelayedTask( 1305 BrowserThread::PostDelayedTask(
1305 BrowserThread::UI, 1306 BrowserThread::UI,
1306 FROM_HERE, 1307 FROM_HERE,
1307 base::Bind(&DevToolsAndroidBridge::RequestDeviceList, this), 1308 base::Bind(&DevToolsAndroidBridge::RequestDeviceList, this),
1308 base::TimeDelta::FromMilliseconds(kAdbPollingIntervalMs)); 1309 base::TimeDelta::FromMilliseconds(polling_interval_for_test_
1310 ? polling_interval_for_test_
1311 : kAdbPollingIntervalMs));
1309 } 1312 }
1310 1313
1311 void DevToolsAndroidBridge::RequestDeviceCount() { 1314 void DevToolsAndroidBridge::RequestDeviceCount() {
1312 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1315 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1313 DCHECK(device_manager_); 1316 DCHECK(device_manager_);
1314 1317
1315 if (device_count_listeners_.empty()) 1318 if (device_count_listeners_.empty())
1316 return; 1319 return;
1317 1320
1318 UsbDeviceProvider::CountDevices( 1321 UsbDeviceProvider::CountDevices(
1319 base::Bind(&DevToolsAndroidBridge::ReceivedDeviceCount, this)); 1322 base::Bind(&DevToolsAndroidBridge::ReceivedDeviceCount, this));
1320 } 1323 }
1321 1324
1322 void DevToolsAndroidBridge::ReceivedDeviceCount(int count) { 1325 void DevToolsAndroidBridge::ReceivedDeviceCount(int count) {
1323 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1324 1327
1325 if (device_count_listeners_.empty()) 1328 if (device_count_listeners_.empty())
1326 return; 1329 return;
1327 1330
1328 DeviceCountListeners copy(device_count_listeners_); 1331 DeviceCountListeners copy(device_count_listeners_);
1329 for (DeviceCountListeners::iterator it = copy.begin(); it != copy.end(); ++it) 1332 for (DeviceCountListeners::iterator it = copy.begin(); it != copy.end(); ++it)
1330 (*it)->DeviceCountChanged(count); 1333 (*it)->DeviceCountChanged(count);
1331 1334
1332 BrowserThread::PostDelayedTask( 1335 BrowserThread::PostDelayedTask(
1333 BrowserThread::UI, 1336 BrowserThread::UI,
1334 FROM_HERE, 1337 FROM_HERE,
1335 base::Bind(&DevToolsAndroidBridge::RequestDeviceCount, this), 1338 base::Bind(&DevToolsAndroidBridge::RequestDeviceCount, this),
1336 base::TimeDelta::FromMilliseconds(kAdbPollingIntervalMs)); 1339 base::TimeDelta::FromMilliseconds(polling_interval_for_test_
1340 ? polling_interval_for_test_
1341 : kAdbPollingIntervalMs));
1337 } 1342 }
1338 1343
1339 void DevToolsAndroidBridge::CreateDeviceProviders() { 1344 void DevToolsAndroidBridge::CreateDeviceProviders() {
1340 device_providers_.clear(); 1345 device_providers_.clear();
1341 #if defined(DEBUG_DEVTOOLS) 1346 #if defined(DEBUG_DEVTOOLS)
1342 BrowserListTabContentsProvider::EnableTethering(); 1347 BrowserListTabContentsProvider::EnableTethering();
1343 // We cannot rely on command line switch here as we might want to connect 1348 // We cannot rely on command line switch here as we might want to connect
1344 // to another instance of Chrome. Using hard-coded port number instead. 1349 // to another instance of Chrome. Using hard-coded port number instead.
1345 const int kDefaultDebuggingPort = 9222; 1350 const int kDefaultDebuggingPort = 9222;
1346 device_providers_.push_back(new SelfAsDeviceProvider(kDefaultDebuggingPort)); 1351 device_providers_.push_back(new SelfAsDeviceProvider(kDefaultDebuggingPort));
1347 #endif 1352 #endif
1348 device_providers_.push_back(new AdbDeviceProvider()); 1353 device_providers_.push_back(new AdbDeviceProvider());
1349 1354
1350 PrefService* service = profile_->GetPrefs(); 1355 PrefService* service = profile_->GetPrefs();
1351 const PrefService::Preference* pref = 1356 const PrefService::Preference* pref =
1352 service->FindPreference(prefs::kDevToolsDiscoverUsbDevicesEnabled); 1357 service->FindPreference(prefs::kDevToolsDiscoverUsbDevicesEnabled);
1353 const base::Value* pref_value = pref->GetValue(); 1358 const base::Value* pref_value = pref->GetValue();
1354 1359
1355 bool enabled; 1360 bool enabled;
1356 if (pref_value->GetAsBoolean(&enabled) && enabled) { 1361 if (pref_value->GetAsBoolean(&enabled) && enabled) {
1357 device_providers_.push_back(new UsbDeviceProvider(profile_)); 1362 device_providers_.push_back(new UsbDeviceProvider(profile_));
1358 } 1363 }
1359 } 1364 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698