| Index: chrome/browser/devtools/devtools_ui_bindings.cc
|
| diff --git a/chrome/browser/devtools/devtools_ui_bindings.cc b/chrome/browser/devtools/devtools_ui_bindings.cc
|
| index 1517d2147d0737306c852070e451b93b9eef51bb..5148556e4d410fc110b896544ca6d87db022ac15 100644
|
| --- a/chrome/browser/devtools/devtools_ui_bindings.cc
|
| +++ b/chrome/browser/devtools/devtools_ui_bindings.cc
|
| @@ -63,9 +63,6 @@ static const char kFrontendHostMethod[] = "method";
|
| static const char kFrontendHostParams[] = "params";
|
| static const char kTitleFormat[] = "Developer Tools - %s";
|
|
|
| -static const char kDevicesChanged[] = "DevicesChanged";
|
| -static const char kDeviceCountChanged[] = "DeviceCountChanged";
|
| -
|
| std::string SkColorToRGBAString(SkColor color) {
|
| // We avoid StringPrintf because it will use locale specific formatters for
|
| // the double (e.g. ',' instead of '.' in German).
|
| @@ -307,7 +304,8 @@ DevToolsUIBindings::DevToolsUIBindings(content::WebContents* web_contents,
|
| : profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())),
|
| web_contents_(web_contents),
|
| delegate_(new DefaultBindingsDelegate(web_contents_)),
|
| - device_listener_enabled_(false),
|
| + device_count_updates_enabled_(false),
|
| + devices_updates_enabled_(false),
|
| url_(url),
|
| weak_factory_(this) {
|
| frontend_contents_observer_.reset(new FrontendWebContentsObserver(this));
|
| @@ -349,9 +347,8 @@ DevToolsUIBindings::~DevToolsUIBindings() {
|
| jobs_it->second->Stop();
|
| }
|
| indexing_jobs_.clear();
|
| -
|
| - while (!subscribers_.empty())
|
| - Unsubscribe(*subscribers_.begin());
|
| + SetDeviceCountUpdatesEnabled(false);
|
| + SetDevicesUpdatesEnabled(false);
|
| }
|
|
|
| void DevToolsUIBindings::InspectedContentsClosing() {
|
| @@ -571,65 +568,46 @@ void DevToolsUIBindings::OpenUrlOnRemoteDeviceAndInspect(
|
| }
|
| }
|
|
|
| -void DevToolsUIBindings::Subscribe(const std::string& event_type) {
|
| - if (subscribers_.find(event_type) != subscribers_.end()) {
|
| - LOG(ERROR) << "Already subscribed for [" << event_type << "].";
|
| - return;
|
| - }
|
| -
|
| - subscribers_.insert(event_type);
|
| -
|
| - if (event_type == kDevicesChanged) {
|
| - remote_targets_handler_ = DevToolsTargetsUIHandler::CreateForAdb(
|
| - base::Bind(&DevToolsUIBindings::PopulateRemoteDevices,
|
| - base::Unretained(this)),
|
| - profile_);
|
| - } else if (event_type == kDeviceCountChanged) {
|
| - EnableRemoteDeviceCounter(true);
|
| - } else {
|
| - LOG(ERROR) << "Attempt to start unknown event listener " << event_type;
|
| - }
|
| -}
|
| -
|
| -void DevToolsUIBindings::Unsubscribe(const std::string& event_type) {
|
| - if (subscribers_.find(event_type) == subscribers_.end()) {
|
| - LOG(ERROR) << "Not yet subscribed for [" << event_type << "]";
|
| +void DevToolsUIBindings::SetDeviceCountUpdatesEnabled(bool enabled) {
|
| + if (device_count_updates_enabled_ == enabled)
|
| return;
|
| - }
|
| -
|
| - if (event_type == kDevicesChanged) {
|
| - remote_targets_handler_.reset();
|
| - } else if (event_type == kDeviceCountChanged) {
|
| - EnableRemoteDeviceCounter(false);
|
| - } else {
|
| - LOG(ERROR) << "Attempt to stop unknown event listener " << event_type;
|
| - }
|
| -
|
| - subscribers_.erase(event_type);
|
| -}
|
| -
|
| -void DevToolsUIBindings::EnableRemoteDeviceCounter(bool enable) {
|
| DevToolsAndroidBridge* adb_bridge =
|
| DevToolsAndroidBridge::Factory::GetForProfile(profile_);
|
| if (!adb_bridge)
|
| return;
|
|
|
| - DCHECK(device_listener_enabled_ != enable);
|
| - device_listener_enabled_ = enable;
|
| - if (enable)
|
| + device_count_updates_enabled_ = enabled;
|
| + if (enabled)
|
| adb_bridge->AddDeviceCountListener(this);
|
| else
|
| adb_bridge->RemoveDeviceCountListener(this);
|
| }
|
|
|
| +void DevToolsUIBindings::SetDevicesUpdatesEnabled(bool enabled) {
|
| + if (devices_updates_enabled_ == enabled)
|
| + return;
|
| + devices_updates_enabled_ = enabled;
|
| + if (enabled) {
|
| + remote_targets_handler_ = DevToolsTargetsUIHandler::CreateForAdb(
|
| + base::Bind(&DevToolsUIBindings::DevicesUpdated,
|
| + base::Unretained(this)),
|
| + profile_);
|
| + } else {
|
| + remote_targets_handler_.reset();
|
| + }
|
| +}
|
| +
|
| void DevToolsUIBindings::DeviceCountChanged(int count) {
|
| - DispatchEventOnFrontend(kDeviceCountChanged, base::FundamentalValue(count));
|
| + base::FundamentalValue value(count);
|
| + CallClientFunction("InspectorFrontendAPI.deviceCountUpdated", &value, NULL,
|
| + NULL);
|
| }
|
|
|
| -void DevToolsUIBindings::PopulateRemoteDevices(
|
| +void DevToolsUIBindings::DevicesUpdated(
|
| const std::string& source,
|
| const base::ListValue& targets) {
|
| - DispatchEventOnFrontend(kDevicesChanged, targets);
|
| + CallClientFunction("InspectorFrontendAPI.devicesUpdated", &targets, NULL,
|
| + NULL);
|
| }
|
|
|
| void DevToolsUIBindings::FileSavedAs(const std::string& url) {
|
| @@ -793,18 +771,6 @@ void DevToolsUIBindings::CallClientFunction(const std::string& function_name,
|
| web_contents_->GetMainFrame()->ExecuteJavaScript(javascript);
|
| }
|
|
|
| -void DevToolsUIBindings::DispatchEventOnFrontend(
|
| - const std::string& event_type,
|
| - const base::Value& event_data) {
|
| - if (subscribers_.find(event_type) == subscribers_.end())
|
| - return;
|
| - base::StringValue event_type_value(event_type);
|
| - CallClientFunction("InspectorFrontendAPI.dispatchEventToListeners",
|
| - &event_type_value,
|
| - &event_data,
|
| - NULL);
|
| -}
|
| -
|
| void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() {
|
| // Call delegate first - it seeds importants bit of information.
|
| delegate_->OnLoadCompleted();
|
|
|