OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/automation/automation_provider.h" | 5 #include "chrome/browser/automation/automation_provider.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 | 103 |
104 #if defined(OS_WIN) | 104 #if defined(OS_WIN) |
105 #include "chrome/browser/external_tab_container_win.h" | 105 #include "chrome/browser/external_tab_container_win.h" |
106 #endif // defined(OS_WIN) | 106 #endif // defined(OS_WIN) |
107 | 107 |
108 using base::Time; | 108 using base::Time; |
109 | 109 |
110 AutomationProvider::AutomationProvider(Profile* profile) | 110 AutomationProvider::AutomationProvider(Profile* profile) |
111 : profile_(profile), | 111 : profile_(profile), |
112 reply_message_(NULL), | 112 reply_message_(NULL), |
113 reconnect_on_channel_error_(false), | |
113 is_connected_(false), | 114 is_connected_(false), |
114 initial_loads_complete_(false) { | 115 initial_loads_complete_(false) { |
115 TRACE_EVENT_BEGIN("AutomationProvider::AutomationProvider", 0, ""); | 116 TRACE_EVENT_BEGIN("AutomationProvider::AutomationProvider", 0, ""); |
116 | 117 |
117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
118 | 119 |
119 browser_tracker_.reset(new AutomationBrowserTracker(this)); | 120 browser_tracker_.reset(new AutomationBrowserTracker(this)); |
120 extension_tracker_.reset(new AutomationExtensionTracker(this)); | 121 extension_tracker_.reset(new AutomationExtensionTracker(this)); |
121 tab_tracker_.reset(new AutomationTabTracker(this)); | 122 tab_tracker_.reset(new AutomationTabTracker(this)); |
122 window_tracker_.reset(new AutomationWindowTracker(this)); | 123 window_tracker_.reset(new AutomationWindowTracker(this)); |
(...skipping 16 matching lines...) Expand all Loading... | |
139 | 140 |
140 if (channel_.get()) | 141 if (channel_.get()) |
141 channel_->Close(); | 142 channel_->Close(); |
142 | 143 |
143 g_browser_process->ReleaseModule(); | 144 g_browser_process->ReleaseModule(); |
144 } | 145 } |
145 | 146 |
146 bool AutomationProvider::InitializeChannel(const std::string& channel_id) { | 147 bool AutomationProvider::InitializeChannel(const std::string& channel_id) { |
147 TRACE_EVENT_BEGIN("AutomationProvider::InitializeChannel", 0, ""); | 148 TRACE_EVENT_BEGIN("AutomationProvider::InitializeChannel", 0, ""); |
148 | 149 |
150 channel_id_ = channel_id; | |
149 std::string effective_channel_id = channel_id; | 151 std::string effective_channel_id = channel_id; |
150 | 152 |
151 // If the channel_id starts with kNamedInterfacePrefix, create a named IPC | 153 // If the channel_id starts with kNamedInterfacePrefix, create a named IPC |
152 // server and listen on it, else connect as client to an existing IPC server | 154 // server and listen on it, else connect as client to an existing IPC server |
153 bool use_named_interface = | 155 bool use_named_interface = |
154 channel_id.find(automation::kNamedInterfacePrefix) == 0; | 156 channel_id.find(automation::kNamedInterfacePrefix) == 0; |
155 if (use_named_interface) { | 157 if (use_named_interface) { |
156 effective_channel_id = channel_id.substr( | 158 effective_channel_id = channel_id.substr( |
157 strlen(automation::kNamedInterfacePrefix)); | 159 strlen(automation::kNamedInterfacePrefix)); |
158 if (effective_channel_id.length() <= 0) | 160 if (effective_channel_id.length() <= 0) |
159 return false; | 161 return false; |
162 | |
163 reconnect_on_channel_error_ = true; | |
160 } | 164 } |
161 | 165 |
162 if (!automation_resource_message_filter_.get()) { | 166 if (!automation_resource_message_filter_.get()) { |
163 automation_resource_message_filter_ = new AutomationResourceMessageFilter; | 167 automation_resource_message_filter_ = new AutomationResourceMessageFilter; |
164 } | 168 } |
165 | 169 |
166 channel_.reset(new IPC::SyncChannel( | 170 channel_.reset(new IPC::SyncChannel( |
167 effective_channel_id, | 171 effective_channel_id, |
168 use_named_interface ? IPC::Channel::MODE_NAMED_SERVER | 172 use_named_interface ? IPC::Channel::MODE_NAMED_SERVER |
169 : IPC::Channel::MODE_CLIENT, | 173 : IPC::Channel::MODE_CLIENT, |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
425 | 429 |
426 DISALLOW_COPY_AND_ASSIGN(InvokeTaskLaterTask); | 430 DISALLOW_COPY_AND_ASSIGN(InvokeTaskLaterTask); |
427 }; | 431 }; |
428 | 432 |
429 void AutomationProvider::HandleUnused(const IPC::Message& message, int handle) { | 433 void AutomationProvider::HandleUnused(const IPC::Message& message, int handle) { |
430 if (window_tracker_->ContainsHandle(handle)) { | 434 if (window_tracker_->ContainsHandle(handle)) { |
431 window_tracker_->Remove(window_tracker_->GetResource(handle)); | 435 window_tracker_->Remove(window_tracker_->GetResource(handle)); |
432 } | 436 } |
433 } | 437 } |
434 | 438 |
439 bool AutomationProvider::ReinitializeChannel() { | |
440 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
441 | |
442 // Make sure any old channels are cleaned up before starting up a new one. | |
443 channel_.reset(); | |
444 return InitializeChannel(channel_id_); | |
445 } | |
446 | |
435 void AutomationProvider::OnChannelError() { | 447 void AutomationProvider::OnChannelError() { |
436 VLOG(1) << "AutomationProxy went away, shutting down app."; | 448 if (reconnect_on_channel_error_) { |
437 AutomationProviderList::GetInstance()->RemoveProvider(this); | 449 VLOG(1) << "AutomationProxy disconnected, resetting AutomationProvider."; |
450 if (!ReinitializeChannel()) { | |
451 VLOG(1) << "Error reinitializing AutomationProvider channel."; | |
452 AutomationProviderList::GetInstance()->RemoveProvider(this); | |
453 } | |
454 } else { | |
455 VLOG(1) << "AutomationProxy went away, shutting down app."; | |
456 AutomationProviderList::GetInstance()->RemoveProvider(this); | |
Nirnimesh
2011/02/17 00:55:12
You won't need to repeat this RemoveProvider() cal
dtu
2011/02/17 02:14:25
Done.
| |
457 } | |
438 } | 458 } |
439 | 459 |
440 bool AutomationProvider::Send(IPC::Message* msg) { | 460 bool AutomationProvider::Send(IPC::Message* msg) { |
441 DCHECK(channel_.get()); | 461 DCHECK(channel_.get()); |
442 return channel_->Send(msg); | 462 return channel_->Send(msg); |
443 } | 463 } |
444 | 464 |
445 Browser* AutomationProvider::FindAndActivateTab( | 465 Browser* AutomationProvider::FindAndActivateTab( |
446 NavigationController* controller) { | 466 NavigationController* controller) { |
447 int tab_index; | 467 int tab_index; |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
992 } | 1012 } |
993 } | 1013 } |
994 } | 1014 } |
995 | 1015 |
996 void AutomationProvider::SaveAsAsync(int tab_handle) { | 1016 void AutomationProvider::SaveAsAsync(int tab_handle) { |
997 NavigationController* tab = NULL; | 1017 NavigationController* tab = NULL; |
998 TabContents* tab_contents = GetTabContentsForHandle(tab_handle, &tab); | 1018 TabContents* tab_contents = GetTabContentsForHandle(tab_handle, &tab); |
999 if (tab_contents) | 1019 if (tab_contents) |
1000 tab_contents->OnSavePage(); | 1020 tab_contents->OnSavePage(); |
1001 } | 1021 } |
OLD | NEW |