| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 151 |
| 152 AutomationProvider::AutomationProvider(Profile* profile) | 152 AutomationProvider::AutomationProvider(Profile* profile) |
| 153 : profile_(profile), | 153 : profile_(profile), |
| 154 reply_message_(NULL), | 154 reply_message_(NULL), |
| 155 reinitialize_on_channel_error_( | 155 reinitialize_on_channel_error_( |
| 156 CommandLine::ForCurrentProcess()->HasSwitch( | 156 CommandLine::ForCurrentProcess()->HasSwitch( |
| 157 switches::kAutomationReinitializeOnChannelError)), | 157 switches::kAutomationReinitializeOnChannelError)), |
| 158 use_initial_load_observers_(true), | 158 use_initial_load_observers_(true), |
| 159 is_connected_(false), | 159 is_connected_(false), |
| 160 initial_tab_loads_complete_(false), | 160 initial_tab_loads_complete_(false), |
| 161 network_library_initialized_(true), | |
| 162 login_webui_ready_(true) { | 161 login_webui_ready_(true) { |
| 163 TRACE_EVENT_BEGIN_ETW("AutomationProvider::AutomationProvider", 0, ""); | 162 TRACE_EVENT_BEGIN_ETW("AutomationProvider::AutomationProvider", 0, ""); |
| 164 | 163 |
| 165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 166 | 165 |
| 167 browser_tracker_.reset(new AutomationBrowserTracker(this)); | 166 browser_tracker_.reset(new AutomationBrowserTracker(this)); |
| 168 tab_tracker_.reset(new AutomationTabTracker(this)); | 167 tab_tracker_.reset(new AutomationTabTracker(this)); |
| 169 window_tracker_.reset(new AutomationWindowTracker(this)); | 168 window_tracker_.reset(new AutomationWindowTracker(this)); |
| 170 new_tab_ui_load_observer_.reset(new NewTabUILoadObserver(this, profile)); | 169 new_tab_ui_load_observer_.reset(new NewTabUILoadObserver(this, profile)); |
| 171 metric_event_duration_observer_.reset(new MetricEventDurationObserver()); | 170 metric_event_duration_observer_.reset(new MetricEventDurationObserver()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 #if defined(OS_CHROMEOS) | 214 #if defined(OS_CHROMEOS) |
| 216 if (use_initial_load_observers_) { | 215 if (use_initial_load_observers_) { |
| 217 // Wait for webui login to be ready. | 216 // Wait for webui login to be ready. |
| 218 // Observer will delete itself. | 217 // Observer will delete itself. |
| 219 if (CommandLine::ForCurrentProcess()->HasSwitch( | 218 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 220 chromeos::switches::kLoginManager) && | 219 chromeos::switches::kLoginManager) && |
| 221 !chromeos::LoginState::Get()->IsUserLoggedIn()) { | 220 !chromeos::LoginState::Get()->IsUserLoggedIn()) { |
| 222 login_webui_ready_ = false; | 221 login_webui_ready_ = false; |
| 223 new OOBEWebuiReadyObserver(this); | 222 new OOBEWebuiReadyObserver(this); |
| 224 } | 223 } |
| 225 | |
| 226 // Wait for the network manager to initialize. | |
| 227 // The observer will delete itself when done. | |
| 228 network_library_initialized_ = false; | |
| 229 NetworkManagerInitObserver* observer = new NetworkManagerInitObserver(this); | |
| 230 if (!observer->Init()) | |
| 231 delete observer; | |
| 232 } | 224 } |
| 233 #endif | 225 #endif |
| 234 | 226 |
| 235 TRACE_EVENT_END_ETW("AutomationProvider::InitializeChannel", 0, ""); | 227 TRACE_EVENT_END_ETW("AutomationProvider::InitializeChannel", 0, ""); |
| 236 | 228 |
| 237 return true; | 229 return true; |
| 238 } | 230 } |
| 239 | 231 |
| 240 IPC::Channel::Mode AutomationProvider::GetChannelMode( | 232 IPC::Channel::Mode AutomationProvider::GetChannelMode( |
| 241 bool use_named_interface) { | 233 bool use_named_interface) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 257 else | 249 else |
| 258 initial_load_observer_.reset(new InitialLoadObserver(expected_tabs, this)); | 250 initial_load_observer_.reset(new InitialLoadObserver(expected_tabs, this)); |
| 259 } | 251 } |
| 260 | 252 |
| 261 void AutomationProvider::OnInitialTabLoadsComplete() { | 253 void AutomationProvider::OnInitialTabLoadsComplete() { |
| 262 initial_tab_loads_complete_ = true; | 254 initial_tab_loads_complete_ = true; |
| 263 VLOG(2) << "OnInitialTabLoadsComplete"; | 255 VLOG(2) << "OnInitialTabLoadsComplete"; |
| 264 SendInitialLoadMessage(); | 256 SendInitialLoadMessage(); |
| 265 } | 257 } |
| 266 | 258 |
| 267 void AutomationProvider::OnNetworkLibraryInit() { | |
| 268 network_library_initialized_ = true; | |
| 269 VLOG(2) << "OnNetworkLibraryInit"; | |
| 270 SendInitialLoadMessage(); | |
| 271 } | |
| 272 | |
| 273 void AutomationProvider::OnOOBEWebuiReady() { | 259 void AutomationProvider::OnOOBEWebuiReady() { |
| 274 login_webui_ready_ = true; | 260 login_webui_ready_ = true; |
| 275 VLOG(2) << "OnOOBEWebuiReady"; | 261 VLOG(2) << "OnOOBEWebuiReady"; |
| 276 SendInitialLoadMessage(); | 262 SendInitialLoadMessage(); |
| 277 } | 263 } |
| 278 | 264 |
| 279 void AutomationProvider::SendInitialLoadMessage() { | 265 void AutomationProvider::SendInitialLoadMessage() { |
| 280 if (is_connected_ && initial_tab_loads_complete_ && | 266 if (is_connected_ && initial_tab_loads_complete_ && |
| 281 network_library_initialized_ && login_webui_ready_) { | 267 login_webui_ready_) { |
| 282 VLOG(2) << "Initial loads complete; sending initial loads message."; | 268 VLOG(2) << "Initial loads complete; sending initial loads message."; |
| 283 Send(new AutomationMsg_InitialLoadsComplete()); | 269 Send(new AutomationMsg_InitialLoadsComplete()); |
| 284 } | 270 } |
| 285 } | 271 } |
| 286 | 272 |
| 287 void AutomationProvider::DisableInitialLoadObservers() { | 273 void AutomationProvider::DisableInitialLoadObservers() { |
| 288 use_initial_load_observers_ = false; | 274 use_initial_load_observers_ = false; |
| 289 OnInitialTabLoadsComplete(); | 275 OnInitialTabLoadsComplete(); |
| 290 OnNetworkLibraryInit(); | |
| 291 OnOOBEWebuiReady(); | 276 OnOOBEWebuiReady(); |
| 292 } | 277 } |
| 293 | 278 |
| 294 int AutomationProvider::GetIndexForNavigationController( | 279 int AutomationProvider::GetIndexForNavigationController( |
| 295 const NavigationController* controller, const Browser* parent) const { | 280 const NavigationController* controller, const Browser* parent) const { |
| 296 DCHECK(parent); | 281 DCHECK(parent); |
| 297 return parent->tab_strip_model()->GetIndexOfWebContents( | 282 return parent->tab_strip_model()->GetIndexOfWebContents( |
| 298 controller->GetWebContents()); | 283 controller->GetWebContents()); |
| 299 } | 284 } |
| 300 | 285 |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 | 779 |
| 795 return NULL; | 780 return NULL; |
| 796 } | 781 } |
| 797 | 782 |
| 798 void AutomationProvider::SaveAsAsync(int tab_handle) { | 783 void AutomationProvider::SaveAsAsync(int tab_handle) { |
| 799 NavigationController* tab = NULL; | 784 NavigationController* tab = NULL; |
| 800 WebContents* web_contents = GetWebContentsForHandle(tab_handle, &tab); | 785 WebContents* web_contents = GetWebContentsForHandle(tab_handle, &tab); |
| 801 if (web_contents) | 786 if (web_contents) |
| 802 web_contents->OnSavePage(); | 787 web_contents->OnSavePage(); |
| 803 } | 788 } |
| OLD | NEW |