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

Side by Side Diff: chrome/browser/devtools/devtools_ui_bindings.cc

Issue 1504763004: [DevTools] Fix frontend host race and assert. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
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/devtools_ui_bindings.h" 5 #include "chrome/browser/devtools/devtools_ui_bindings.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/prefs/scoped_user_pref_update.h" 10 #include "base/prefs/scoped_user_pref_update.h"
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 return NULL; 477 return NULL;
478 } 478 }
479 479
480 DevToolsUIBindings::DevToolsUIBindings(content::WebContents* web_contents) 480 DevToolsUIBindings::DevToolsUIBindings(content::WebContents* web_contents)
481 : profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), 481 : profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())),
482 android_bridge_(DevToolsAndroidBridge::Factory::GetForProfile(profile_)), 482 android_bridge_(DevToolsAndroidBridge::Factory::GetForProfile(profile_)),
483 web_contents_(web_contents), 483 web_contents_(web_contents),
484 delegate_(new DefaultBindingsDelegate(web_contents_)), 484 delegate_(new DefaultBindingsDelegate(web_contents_)),
485 devices_updates_enabled_(false), 485 devices_updates_enabled_(false),
486 frontend_loaded_(false), 486 frontend_loaded_(false),
487 frontend_reattaching_(false),
487 weak_factory_(this) { 488 weak_factory_(this) {
488 g_instances.Get().push_back(this); 489 g_instances.Get().push_back(this);
489 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); 490 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this));
490 web_contents_->GetMutableRendererPrefs()->can_accept_load_drops = false; 491 web_contents_->GetMutableRendererPrefs()->can_accept_load_drops = false;
491 492
492 file_helper_.reset(new DevToolsFileHelper(web_contents_, profile_, this)); 493 file_helper_.reset(new DevToolsFileHelper(web_contents_, profile_, this));
493 file_system_indexer_ = new DevToolsFileSystemIndexer(); 494 file_system_indexer_ = new DevToolsFileSystemIndexer();
494 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( 495 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
495 web_contents_); 496 web_contents_);
496 497
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 } 887 }
887 888
888 void DevToolsUIBindings::ClearPreferences() { 889 void DevToolsUIBindings::ClearPreferences() {
889 DictionaryPrefUpdate update(profile_->GetPrefs(), 890 DictionaryPrefUpdate update(profile_->GetPrefs(),
890 prefs::kDevToolsPreferences); 891 prefs::kDevToolsPreferences);
891 update.Get()->Clear(); 892 update.Get()->Clear();
892 } 893 }
893 894
894 void DevToolsUIBindings::DispatchProtocolMessageFromDevToolsFrontend( 895 void DevToolsUIBindings::DispatchProtocolMessageFromDevToolsFrontend(
895 const std::string& message) { 896 const std::string& message) {
896 if (agent_host_.get()) 897 if (agent_host_.get() && !frontend_reattaching_)
pfeldman 2015/12/07 21:38:42 When does this happen and why should it be ignored
dgozman 2015/12/07 21:46:40 Happens in Reattach. First paragraph of the patch
pfeldman 2015/12/07 21:48:36 But how can it be dispatched twice?
dgozman 2015/12/07 22:03:53 Sorry, it wasn't clear. It's not the same message
897 agent_host_->DispatchProtocolMessage(message); 898 agent_host_->DispatchProtocolMessage(message);
898 } 899 }
899 900
900 void DevToolsUIBindings::RecordEnumeratedHistogram(const std::string& name, 901 void DevToolsUIBindings::RecordEnumeratedHistogram(const std::string& name,
901 int sample, 902 int sample,
902 int boundary_value) { 903 int boundary_value) {
903 if (!(boundary_value >= 0 && boundary_value <= 100 && sample >= 0 && 904 if (!(boundary_value >= 0 && boundary_value <= 100 && sample >= 0 &&
904 sample < boundary_value)) { 905 sample < boundary_value)) {
905 // TODO(nick): Replace with chrome::bad_message::ReceivedBadMessage(). 906 // TODO(nick): Replace with chrome::bad_message::ReceivedBadMessage().
906 frontend_host_->BadMessageRecieved(); 907 frontend_host_->BadMessageRecieved();
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 1120
1120 void DevToolsUIBindings::AttachTo( 1121 void DevToolsUIBindings::AttachTo(
1121 const scoped_refptr<content::DevToolsAgentHost>& agent_host) { 1122 const scoped_refptr<content::DevToolsAgentHost>& agent_host) {
1122 if (agent_host_.get()) 1123 if (agent_host_.get())
1123 Detach(); 1124 Detach();
1124 agent_host_ = agent_host; 1125 agent_host_ = agent_host;
1125 agent_host_->AttachClient(this); 1126 agent_host_->AttachClient(this);
1126 } 1127 }
1127 1128
1128 void DevToolsUIBindings::Reattach() { 1129 void DevToolsUIBindings::Reattach() {
1130 frontend_reattaching_ = true;
1129 DCHECK(agent_host_.get()); 1131 DCHECK(agent_host_.get());
1130 agent_host_->DetachClient(); 1132 agent_host_->DetachClient();
1131 agent_host_->AttachClient(this); 1133 agent_host_->AttachClient(this);
1132 } 1134 }
1133 1135
1134 void DevToolsUIBindings::Detach() { 1136 void DevToolsUIBindings::Detach() {
1135 if (agent_host_.get()) 1137 if (agent_host_.get())
1136 agent_host_->DetachClient(); 1138 agent_host_->DetachClient();
1137 agent_host_ = NULL; 1139 agent_host_ = NULL;
1138 } 1140 }
(...skipping 29 matching lines...) Expand all
1168 javascript.append(", ").append(json); 1170 javascript.append(", ").append(json);
1169 } 1171 }
1170 } 1172 }
1171 } 1173 }
1172 javascript.append(");"); 1174 javascript.append(");");
1173 web_contents_->GetMainFrame()->ExecuteJavaScript( 1175 web_contents_->GetMainFrame()->ExecuteJavaScript(
1174 base::UTF8ToUTF16(javascript)); 1176 base::UTF8ToUTF16(javascript));
1175 } 1177 }
1176 1178
1177 void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() { 1179 void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() {
1180 frontend_reattaching_ = false;
1178 // In the DEBUG_DEVTOOLS mode, the DocumentOnLoadCompletedInMainFrame event 1181 // In the DEBUG_DEVTOOLS mode, the DocumentOnLoadCompletedInMainFrame event
1179 // arrives before the LoadCompleted event, thus it should not trigger the 1182 // arrives before the LoadCompleted event, thus it should not trigger the
1180 // frontend load handling. 1183 // frontend load handling.
1181 #if !defined(DEBUG_DEVTOOLS) 1184 #if !defined(DEBUG_DEVTOOLS)
1182 FrontendLoaded(); 1185 FrontendLoaded();
1183 #endif 1186 #endif
1184 } 1187 }
1185 1188
1186 void DevToolsUIBindings::DidNavigateMainFrame() { 1189 void DevToolsUIBindings::DidNavigateMainFrame() {
1187 frontend_loaded_ = false; 1190 frontend_loaded_ = false;
1188 } 1191 }
1189 1192
1190 void DevToolsUIBindings::FrontendLoaded() { 1193 void DevToolsUIBindings::FrontendLoaded() {
1191 if (frontend_loaded_) 1194 if (frontend_loaded_)
1192 return; 1195 return;
1193 frontend_loaded_ = true; 1196 frontend_loaded_ = true;
1194 1197
1195 // Call delegate first - it seeds importants bit of information. 1198 // Call delegate first - it seeds importants bit of information.
1196 delegate_->OnLoadCompleted(); 1199 delegate_->OnLoadCompleted();
1197 1200
1198 AddDevToolsExtensionsToClient(); 1201 AddDevToolsExtensionsToClient();
1199 if (g_web_socket_api_channel) 1202 if (g_web_socket_api_channel)
1200 g_web_socket_api_channel->AttachedToBindings(this); 1203 g_web_socket_api_channel->AttachedToBindings(this);
1201 } 1204 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698