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

Side by Side Diff: chrome_frame/chrome_frame_automation.cc

Issue 6001010: Move platform_thread to base/threading and put in the base namespace. I left ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 11 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
« no previous file with comments | « chrome_frame/chrome_frame_automation.h ('k') | chrome_frame/test/mock_ie_event_sink_actions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_frame/chrome_frame_automation.h" 5 #include "chrome_frame/chrome_frame_automation.h"
6 6
7 #include "app/app_switches.h" 7 #include "app/app_switches.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 DCHECK(!snapshots_); 249 DCHECK(!snapshots_);
250 snapshots_ = snapshots; 250 snapshots_ = snapshots;
251 uma_send_interval_ = send_interval; 251 uma_send_interval_ = send_interval;
252 thread_->message_loop()->PostDelayedTask(FROM_HERE, 252 thread_->message_loop()->PostDelayedTask(FROM_HERE,
253 NewRunnableMethod(this, &AutomationProxyCacheEntry::SendUMAData), 253 NewRunnableMethod(this, &AutomationProxyCacheEntry::SendUMAData),
254 send_interval); 254 send_interval);
255 } 255 }
256 256
257 void AutomationProxyCacheEntry::CreateProxy(ChromeFrameLaunchParams* params, 257 void AutomationProxyCacheEntry::CreateProxy(ChromeFrameLaunchParams* params,
258 LaunchDelegate* delegate) { 258 LaunchDelegate* delegate) {
259 DCHECK(IsSameThread(PlatformThread::CurrentId())); 259 DCHECK(IsSameThread(base::PlatformThread::CurrentId()));
260 DCHECK(delegate); 260 DCHECK(delegate);
261 DCHECK(params); 261 DCHECK(params);
262 DCHECK(proxy_.get() == NULL); 262 DCHECK(proxy_.get() == NULL);
263 263
264 // We *must* create automationproxy in a thread that has message loop, 264 // We *must* create automationproxy in a thread that has message loop,
265 // since SyncChannel::Context construction registers event to be watched 265 // since SyncChannel::Context construction registers event to be watched
266 // through ObjectWatcher which subscribes for the current thread message loop 266 // through ObjectWatcher which subscribes for the current thread message loop
267 // destruction notification. 267 // destruction notification.
268 268
269 // At same time we must destroy/stop the thread from another thread. 269 // At same time we must destroy/stop the thread from another thread.
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 // Finally set the proxy. 371 // Finally set the proxy.
372 proxy_.reset(proxy); 372 proxy_.reset(proxy);
373 launch_delegates_.push_back(delegate); 373 launch_delegates_.push_back(delegate);
374 374
375 delegate->LaunchComplete(proxy_.get(), launch_result_); 375 delegate->LaunchComplete(proxy_.get(), launch_result_);
376 } 376 }
377 377
378 void AutomationProxyCacheEntry::RemoveDelegate(LaunchDelegate* delegate, 378 void AutomationProxyCacheEntry::RemoveDelegate(LaunchDelegate* delegate,
379 base::WaitableEvent* done, 379 base::WaitableEvent* done,
380 bool* was_last_delegate) { 380 bool* was_last_delegate) {
381 DCHECK(IsSameThread(PlatformThread::CurrentId())); 381 DCHECK(IsSameThread(base::PlatformThread::CurrentId()));
382 DCHECK(delegate); 382 DCHECK(delegate);
383 DCHECK(done); 383 DCHECK(done);
384 DCHECK(was_last_delegate); 384 DCHECK(was_last_delegate);
385 385
386 *was_last_delegate = false; 386 *was_last_delegate = false;
387 387
388 LaunchDelegates::iterator it = std::find(launch_delegates_.begin(), 388 LaunchDelegates::iterator it = std::find(launch_delegates_.begin(),
389 launch_delegates_.end(), delegate); 389 launch_delegates_.end(), delegate);
390 if (it == launch_delegates_.end()) { 390 if (it == launch_delegates_.end()) {
391 NOTREACHED(); 391 NOTREACHED();
(...skipping 13 matching lines...) Expand all
405 // Be careful to remove from the list after running pending 405 // Be careful to remove from the list after running pending
406 // tasks. Otherwise the delegate being removed might miss out 406 // tasks. Otherwise the delegate being removed might miss out
407 // on pending notifications such as LaunchComplete. 407 // on pending notifications such as LaunchComplete.
408 launch_delegates_.erase(it); 408 launch_delegates_.erase(it);
409 } 409 }
410 410
411 done->Signal(); 411 done->Signal();
412 } 412 }
413 413
414 void AutomationProxyCacheEntry::AddDelegate(LaunchDelegate* delegate) { 414 void AutomationProxyCacheEntry::AddDelegate(LaunchDelegate* delegate) {
415 DCHECK(IsSameThread(PlatformThread::CurrentId())); 415 DCHECK(IsSameThread(base::PlatformThread::CurrentId()));
416 DCHECK(std::find(launch_delegates_.begin(), 416 DCHECK(std::find(launch_delegates_.begin(),
417 launch_delegates_.end(), 417 launch_delegates_.end(),
418 delegate) == launch_delegates_.end()) 418 delegate) == launch_delegates_.end())
419 << "Same delegate being added twice"; 419 << "Same delegate being added twice";
420 DCHECK(launch_result_ != AUTOMATION_LAUNCH_RESULT_INVALID); 420 DCHECK(launch_result_ != AUTOMATION_LAUNCH_RESULT_INVALID);
421 421
422 launch_delegates_.push_back(delegate); 422 launch_delegates_.push_back(delegate);
423 delegate->LaunchComplete(proxy_.get(), launch_result_); 423 delegate->LaunchComplete(proxy_.get(), launch_result_);
424 } 424 }
425 425
426 void AutomationProxyCacheEntry::OnChannelError() { 426 void AutomationProxyCacheEntry::OnChannelError() {
427 DCHECK(IsSameThread(PlatformThread::CurrentId())); 427 DCHECK(IsSameThread(base::PlatformThread::CurrentId()));
428 launch_result_ = AUTOMATION_SERVER_CRASHED; 428 launch_result_ = AUTOMATION_SERVER_CRASHED;
429 LaunchDelegates::const_iterator it = launch_delegates_.begin(); 429 LaunchDelegates::const_iterator it = launch_delegates_.begin();
430 for (; it != launch_delegates_.end(); ++it) { 430 for (; it != launch_delegates_.end(); ++it) {
431 (*it)->AutomationServerDied(); 431 (*it)->AutomationServerDied();
432 } 432 }
433 } 433 }
434 434
435 void AutomationProxyCacheEntry::SendUMAData() { 435 void AutomationProxyCacheEntry::SendUMAData() {
436 DCHECK(IsSameThread(PlatformThread::CurrentId())); 436 DCHECK(IsSameThread(base::PlatformThread::CurrentId()));
437 DCHECK(snapshots_); 437 DCHECK(snapshots_);
438 // IE uses the chrome frame provided UMA data uploading scheme. NPAPI 438 // IE uses the chrome frame provided UMA data uploading scheme. NPAPI
439 // continues to use Chrome to upload UMA data. 439 // continues to use Chrome to upload UMA data.
440 if (CrashMetricsReporter::GetInstance()->active()) { 440 if (CrashMetricsReporter::GetInstance()->active()) {
441 return; 441 return;
442 } 442 }
443 443
444 if (!proxy_.get()) { 444 if (!proxy_.get()) {
445 DLOG(WARNING) << __FUNCTION__ << " NULL proxy, can't send UMA data"; 445 DLOG(WARNING) << __FUNCTION__ << " NULL proxy, can't send UMA data";
446 } else { 446 } else {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 uma_send_interval_); 502 uma_send_interval_);
503 } 503 }
504 } else if (delegate) { 504 } else if (delegate) {
505 // Notify the new delegate of the launch status from the worker thread 505 // Notify the new delegate of the launch status from the worker thread
506 // and add it to the list of delegates. 506 // and add it to the list of delegates.
507 entry->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(entry.get(), 507 entry->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(entry.get(),
508 &AutomationProxyCacheEntry::AddDelegate, delegate)); 508 &AutomationProxyCacheEntry::AddDelegate, delegate));
509 } 509 }
510 510
511 DCHECK(automation_server_id != NULL); 511 DCHECK(automation_server_id != NULL);
512 DCHECK(!entry->IsSameThread(PlatformThread::CurrentId())); 512 DCHECK(!entry->IsSameThread(base::PlatformThread::CurrentId()));
513 513
514 *automation_server_id = entry; 514 *automation_server_id = entry;
515 } 515 }
516 516
517 bool ProxyFactory::ReleaseAutomationServer(void* server_id, 517 bool ProxyFactory::ReleaseAutomationServer(void* server_id,
518 LaunchDelegate* delegate) { 518 LaunchDelegate* delegate) {
519 if (!server_id) { 519 if (!server_id) {
520 NOTREACHED(); 520 NOTREACHED();
521 return false; 521 return false;
522 } 522 }
523 523
524 AutomationProxyCacheEntry* entry = 524 AutomationProxyCacheEntry* entry =
525 reinterpret_cast<AutomationProxyCacheEntry*>(server_id); 525 reinterpret_cast<AutomationProxyCacheEntry*>(server_id);
526 526
527 #ifndef NDEBUG 527 #ifndef NDEBUG
528 lock_.Acquire(); 528 lock_.Acquire();
529 Vector::ContainerType::iterator it = std::find(proxies_.container().begin(), 529 Vector::ContainerType::iterator it = std::find(proxies_.container().begin(),
530 proxies_.container().end(), 530 proxies_.container().end(),
531 entry); 531 entry);
532 DCHECK(it != proxies_.container().end()); 532 DCHECK(it != proxies_.container().end());
533 DCHECK(!entry->IsSameThread(PlatformThread::CurrentId())); 533 DCHECK(!entry->IsSameThread(base::PlatformThread::CurrentId()));
534 534
535 lock_.Release(); 535 lock_.Release();
536 #endif 536 #endif
537 537
538 // AddRef the entry object as we might need to take it out of the proxy 538 // AddRef the entry object as we might need to take it out of the proxy
539 // stack and then uninitialize the entry. 539 // stack and then uninitialize the entry.
540 entry->AddRef(); 540 entry->AddRef();
541 541
542 bool last_delegate = false; 542 bool last_delegate = false;
543 if (delegate) { 543 if (delegate) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 #ifndef NDEBUG 606 #ifndef NDEBUG
607 if (chrome_launch_params_ && chrome_launch_params_ != chrome_launch_params) { 607 if (chrome_launch_params_ && chrome_launch_params_ != chrome_launch_params) {
608 DCHECK_EQ(chrome_launch_params_->url(), chrome_launch_params->url()); 608 DCHECK_EQ(chrome_launch_params_->url(), chrome_launch_params->url());
609 DCHECK_EQ(chrome_launch_params_->referrer(), 609 DCHECK_EQ(chrome_launch_params_->referrer(),
610 chrome_launch_params->referrer()); 610 chrome_launch_params->referrer());
611 } 611 }
612 #endif 612 #endif
613 613
614 chrome_launch_params_ = chrome_launch_params; 614 chrome_launch_params_ = chrome_launch_params;
615 615
616 ui_thread_id_ = PlatformThread::CurrentId(); 616 ui_thread_id_ = base::PlatformThread::CurrentId();
617 #ifndef NDEBUG 617 #ifndef NDEBUG
618 // In debug mode give more time to work with a debugger. 618 // In debug mode give more time to work with a debugger.
619 if (IsDebuggerPresent()) { 619 if (IsDebuggerPresent()) {
620 // Don't use INFINITE (which is -1) or even MAXINT since we will convert 620 // Don't use INFINITE (which is -1) or even MAXINT since we will convert
621 // from milliseconds to microseconds when stored in a base::TimeDelta, 621 // from milliseconds to microseconds when stored in a base::TimeDelta,
622 // thus * 1000. An hour should be enough. 622 // thus * 1000. An hour should be enough.
623 chrome_launch_params_->set_launch_timeout(60 * 60 * 1000); 623 chrome_launch_params_->set_launch_timeout(60 * 60 * 1000);
624 } else { 624 } else {
625 DCHECK_LT(chrome_launch_params_->launch_timeout(), 625 DCHECK_LT(chrome_launch_params_->launch_timeout(),
626 MAXINT / 2000); 626 MAXINT / 2000);
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 IPC::SyncMessage* msg = new AutomationMsg_InstallExtension(crx_path, NULL); 861 IPC::SyncMessage* msg = new AutomationMsg_InstallExtension(crx_path, NULL);
862 862
863 // The context will delete itself after it is called. 863 // The context will delete itself after it is called.
864 automation_server_->SendAsAsync(msg, ctx, this); 864 automation_server_->SendAsAsync(msg, ctx, this);
865 } 865 }
866 866
867 void ChromeFrameAutomationClient::InstallExtensionComplete( 867 void ChromeFrameAutomationClient::InstallExtensionComplete(
868 const FilePath& crx_path, 868 const FilePath& crx_path,
869 void* user_data, 869 void* user_data,
870 AutomationMsg_ExtensionResponseValues res) { 870 AutomationMsg_ExtensionResponseValues res) {
871 DCHECK_EQ(PlatformThread::CurrentId(), ui_thread_id_); 871 DCHECK_EQ(base::PlatformThread::CurrentId(), ui_thread_id_);
872 872
873 if (chrome_frame_delegate_) { 873 if (chrome_frame_delegate_) {
874 chrome_frame_delegate_->OnExtensionInstalled(crx_path, user_data, res); 874 chrome_frame_delegate_->OnExtensionInstalled(crx_path, user_data, res);
875 } 875 }
876 } 876 }
877 877
878 void ChromeFrameAutomationClient::GetEnabledExtensions(void* user_data) { 878 void ChromeFrameAutomationClient::GetEnabledExtensions(void* user_data) {
879 if (automation_server_ == NULL) { 879 if (automation_server_ == NULL) {
880 GetEnabledExtensionsComplete(user_data, &std::vector<FilePath>()); 880 GetEnabledExtensionsComplete(user_data, &std::vector<FilePath>());
881 return; 881 return;
882 } 882 }
883 883
884 GetEnabledExtensionsContext* ctx = new GetEnabledExtensionsContext( 884 GetEnabledExtensionsContext* ctx = new GetEnabledExtensionsContext(
885 this, user_data); 885 this, user_data);
886 886
887 IPC::SyncMessage* msg = new AutomationMsg_GetEnabledExtensions( 887 IPC::SyncMessage* msg = new AutomationMsg_GetEnabledExtensions(
888 ctx->extension_directories()); 888 ctx->extension_directories());
889 889
890 // The context will delete itself after it is called. 890 // The context will delete itself after it is called.
891 automation_server_->SendAsAsync(msg, ctx, this); 891 automation_server_->SendAsAsync(msg, ctx, this);
892 } 892 }
893 893
894 void ChromeFrameAutomationClient::GetEnabledExtensionsComplete( 894 void ChromeFrameAutomationClient::GetEnabledExtensionsComplete(
895 void* user_data, 895 void* user_data,
896 std::vector<FilePath>* extension_directories) { 896 std::vector<FilePath>* extension_directories) {
897 DCHECK_EQ(PlatformThread::CurrentId(), ui_thread_id_); 897 DCHECK_EQ(base::PlatformThread::CurrentId(), ui_thread_id_);
898 898
899 if (chrome_frame_delegate_) { 899 if (chrome_frame_delegate_) {
900 chrome_frame_delegate_->OnGetEnabledExtensionsComplete( 900 chrome_frame_delegate_->OnGetEnabledExtensionsComplete(
901 user_data, *extension_directories); 901 user_data, *extension_directories);
902 } 902 }
903 903
904 delete extension_directories; 904 delete extension_directories;
905 } 905 }
906 906
907 int ChromeFrameAutomationClient::GetSessionId() const { 907 int ChromeFrameAutomationClient::GetSessionId() const {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 PostTask(FROM_HERE, NewRunnableMethod(this, 1057 PostTask(FROM_HERE, NewRunnableMethod(this,
1058 &ChromeFrameAutomationClient::InitializeComplete, 1058 &ChromeFrameAutomationClient::InitializeComplete,
1059 AUTOMATION_SERVER_CRASHED)); 1059 AUTOMATION_SERVER_CRASHED));
1060 // Then uninitialize. 1060 // Then uninitialize.
1061 PostTask(FROM_HERE, NewRunnableMethod(this, 1061 PostTask(FROM_HERE, NewRunnableMethod(this,
1062 &ChromeFrameAutomationClient::Uninitialize)); 1062 &ChromeFrameAutomationClient::Uninitialize));
1063 } 1063 }
1064 1064
1065 void ChromeFrameAutomationClient::InitializeComplete( 1065 void ChromeFrameAutomationClient::InitializeComplete(
1066 AutomationLaunchResult result) { 1066 AutomationLaunchResult result) {
1067 DCHECK_EQ(PlatformThread::CurrentId(), ui_thread_id_); 1067 DCHECK_EQ(base::PlatformThread::CurrentId(), ui_thread_id_);
1068 if (result != AUTOMATION_SUCCESS) { 1068 if (result != AUTOMATION_SUCCESS) {
1069 DLOG(WARNING) << "InitializeComplete: failure " << result; 1069 DLOG(WARNING) << "InitializeComplete: failure " << result;
1070 ReleaseAutomationServer(); 1070 ReleaseAutomationServer();
1071 } else { 1071 } else {
1072 init_state_ = INITIALIZED; 1072 init_state_ = INITIALIZED;
1073 1073
1074 // If the host already have a window, ask Chrome to re-parent. 1074 // If the host already have a window, ask Chrome to re-parent.
1075 if (parent_window_) 1075 if (parent_window_)
1076 SetParentWindow(parent_window_); 1076 SetParentWindow(parent_window_);
1077 1077
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1190 // Early check to avoid needless marshaling 1190 // Early check to avoid needless marshaling
1191 if (chrome_frame_delegate_ == NULL) 1191 if (chrome_frame_delegate_ == NULL)
1192 return; 1192 return;
1193 1193
1194 PostTask(FROM_HERE, NewRunnableMethod(this, 1194 PostTask(FROM_HERE, NewRunnableMethod(this,
1195 &ChromeFrameAutomationClient::OnChannelErrorUIThread)); 1195 &ChromeFrameAutomationClient::OnChannelErrorUIThread));
1196 } 1196 }
1197 1197
1198 void ChromeFrameAutomationClient::OnMessageReceivedUIThread( 1198 void ChromeFrameAutomationClient::OnMessageReceivedUIThread(
1199 const IPC::Message& msg) { 1199 const IPC::Message& msg) {
1200 DCHECK_EQ(PlatformThread::CurrentId(), ui_thread_id_); 1200 DCHECK_EQ(base::PlatformThread::CurrentId(), ui_thread_id_);
1201 // Forward to the delegate. 1201 // Forward to the delegate.
1202 if (chrome_frame_delegate_) 1202 if (chrome_frame_delegate_)
1203 chrome_frame_delegate_->OnMessageReceived(msg); 1203 chrome_frame_delegate_->OnMessageReceived(msg);
1204 } 1204 }
1205 1205
1206 void ChromeFrameAutomationClient::OnChannelErrorUIThread() { 1206 void ChromeFrameAutomationClient::OnChannelErrorUIThread() {
1207 DCHECK_EQ(PlatformThread::CurrentId(), ui_thread_id_); 1207 DCHECK_EQ(base::PlatformThread::CurrentId(), ui_thread_id_);
1208 1208
1209 // Report a metric that something went wrong unexpectedly. 1209 // Report a metric that something went wrong unexpectedly.
1210 CrashMetricsReporter::GetInstance()->IncrementMetric( 1210 CrashMetricsReporter::GetInstance()->IncrementMetric(
1211 CrashMetricsReporter::CHANNEL_ERROR_COUNT); 1211 CrashMetricsReporter::CHANNEL_ERROR_COUNT);
1212 1212
1213 // Forward to the delegate. 1213 // Forward to the delegate.
1214 if (chrome_frame_delegate_) 1214 if (chrome_frame_delegate_)
1215 chrome_frame_delegate_->OnChannelError(); 1215 chrome_frame_delegate_->OnChannelError();
1216 } 1216 }
1217 1217
1218 void ChromeFrameAutomationClient::ReportNavigationError( 1218 void ChromeFrameAutomationClient::ReportNavigationError(
1219 AutomationMsg_NavigationResponseValues error_code, 1219 AutomationMsg_NavigationResponseValues error_code,
1220 const std::string& url) { 1220 const std::string& url) {
1221 if (!chrome_frame_delegate_) 1221 if (!chrome_frame_delegate_)
1222 return; 1222 return;
1223 1223
1224 if (ui_thread_id_ == PlatformThread::CurrentId()) { 1224 if (ui_thread_id_ == base::PlatformThread::CurrentId()) {
1225 chrome_frame_delegate_->OnLoadFailed(error_code, url); 1225 chrome_frame_delegate_->OnLoadFailed(error_code, url);
1226 } else { 1226 } else {
1227 PostTask(FROM_HERE, NewRunnableMethod(this, 1227 PostTask(FROM_HERE, NewRunnableMethod(this,
1228 &ChromeFrameAutomationClient::ReportNavigationError, 1228 &ChromeFrameAutomationClient::ReportNavigationError,
1229 error_code, url)); 1229 error_code, url));
1230 } 1230 }
1231 } 1231 }
1232 1232
1233 void ChromeFrameAutomationClient::Resize(int width, int height, 1233 void ChromeFrameAutomationClient::Resize(int width, int height,
1234 int flags) { 1234 int flags) {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1457 const URLRequestStatus& status) { 1457 const URLRequestStatus& status) {
1458 automation_server_->Send(new AutomationMsg_RequestEnd( 1458 automation_server_->Send(new AutomationMsg_RequestEnd(
1459 tab_->handle(), request_id, status)); 1459 tab_->handle(), request_id, status));
1460 } 1460 }
1461 1461
1462 void ChromeFrameAutomationClient::OnCookiesRetrieved(bool success, 1462 void ChromeFrameAutomationClient::OnCookiesRetrieved(bool success,
1463 const GURL& url, const std::string& cookie_string, int cookie_id) { 1463 const GURL& url, const std::string& cookie_string, int cookie_id) {
1464 automation_server_->Send(new AutomationMsg_GetCookiesHostResponse( 1464 automation_server_->Send(new AutomationMsg_GetCookiesHostResponse(
1465 tab_->handle(), success, url, cookie_string, cookie_id)); 1465 tab_->handle(), success, url, cookie_string, cookie_id));
1466 } 1466 }
OLDNEW
« no previous file with comments | « chrome_frame/chrome_frame_automation.h ('k') | chrome_frame/test/mock_ie_event_sink_actions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698