diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-03 20:52:37 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-03 20:52:37 +0000 |
commit | 09eab25bfee3e04dc07f3d5dfc15edf99951e1a2 (patch) | |
tree | 55ee39490c2ab196fadef70c4241f3419dea8052 | |
parent | 8d8277a6c58ba7ec96fc5af416453c5957f3c3dd (diff) | |
download | chromium_src-09eab25bfee3e04dc07f3d5dfc15edf99951e1a2.zip chromium_src-09eab25bfee3e04dc07f3d5dfc15edf99951e1a2.tar.gz chromium_src-09eab25bfee3e04dc07f3d5dfc15edf99951e1a2.tar.bz2 |
Convert WebRtcLoggingHandlerHost to use the blocking thread pool.
Also call base::GetLinuxDistro() on the blocking pool and not on the IO thread
because it may block.
Review URL: https://codereview.chromium.org/299903002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274615 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browsing_data/browsing_data_remover.cc | 3 | ||||
-rw-r--r-- | chrome/browser/media/webrtc_log_uploader.cc | 13 | ||||
-rw-r--r-- | chrome/browser/media/webrtc_log_uploader.h | 11 | ||||
-rw-r--r-- | chrome/browser/media/webrtc_log_util.cc | 7 | ||||
-rw-r--r-- | chrome/browser/media/webrtc_log_util.h | 11 | ||||
-rw-r--r-- | chrome/browser/media/webrtc_logging_handler_host.cc | 95 | ||||
-rw-r--r-- | chrome/browser/media/webrtc_logging_handler_host.h | 11 |
7 files changed, 79 insertions, 72 deletions
diff --git a/chrome/browser/browsing_data/browsing_data_remover.cc b/chrome/browser/browsing_data/browsing_data_remover.cc index da2bb2f..bd4e2fd 100644 --- a/chrome/browser/browsing_data/browsing_data_remover.cc +++ b/chrome/browser/browsing_data/browsing_data_remover.cc @@ -388,8 +388,7 @@ void BrowsingDataRemover::RemoveImpl(int remove_mask, #if defined(ENABLE_WEBRTC) waiting_for_clear_webrtc_logs_ = true; - BrowserThread::PostTaskAndReply( - BrowserThread::FILE, + BrowserThread::PostBlockingPoolTaskAndReply( FROM_HERE, base::Bind( &WebRtcLogUtil::DeleteOldAndRecentWebRtcLogFiles, diff --git a/chrome/browser/media/webrtc_log_uploader.cc b/chrome/browser/media/webrtc_log_uploader.cc index 98b22c3..a51404c 100644 --- a/chrome/browser/media/webrtc_log_uploader.cc +++ b/chrome/browser/media/webrtc_log_uploader.cc @@ -76,7 +76,7 @@ WebRtcLogUploader::WebRtcLogUploader() : log_count_(0), post_data_(NULL), shutting_down_(false) { - file_thread_checker_.DetachFromThread(); + blocking_sequence_checker_.DetachFromSequence(); } WebRtcLogUploader::~WebRtcLogUploader() { @@ -102,8 +102,7 @@ void WebRtcLogUploader::OnURLFetchComplete( // TODO(jiayl): Add the RTP dump records to chrome://webrtc-logs. base::FilePath log_list_path = WebRtcLogList::GetWebRtcLogListFileForDirectory(it->second.log_path); - content::BrowserThread::PostTask( - content::BrowserThread::FILE, + content::BrowserThread::PostBlockingPoolTask( FROM_HERE, base::Bind(&WebRtcLogUploader::AddUploadedLogInfoToUploadListFile, base::Unretained(this), @@ -141,7 +140,7 @@ void WebRtcLogUploader::LoggingStoppedDoUpload( uint32 length, const std::map<std::string, std::string>& meta_data, const WebRtcLogUploadDoneData& upload_done_data) { - DCHECK(file_thread_checker_.CalledOnValidThread()); + DCHECK(blocking_sequence_checker_.CalledOnValidSequencedThread()); DCHECK(log_buffer.get()); DCHECK(!upload_done_data.log_path.empty()); @@ -352,7 +351,7 @@ void WebRtcLogUploader::DecreaseLogCount() { void WebRtcLogUploader::WriteCompressedLogToFile( const std::vector<uint8>& compressed_log, const base::FilePath& log_file_path) { - DCHECK(file_thread_checker_.CalledOnValidThread()); + DCHECK(blocking_sequence_checker_.CalledOnValidSequencedThread()); DCHECK(!compressed_log.empty()); base::WriteFile(log_file_path, reinterpret_cast<const char*>(&compressed_log[0]), @@ -362,7 +361,7 @@ void WebRtcLogUploader::WriteCompressedLogToFile( void WebRtcLogUploader::AddLocallyStoredLogInfoToUploadListFile( const base::FilePath& upload_list_path, const std::string& local_log_id) { - DCHECK(file_thread_checker_.CalledOnValidThread()); + DCHECK(blocking_sequence_checker_.CalledOnValidSequencedThread()); DCHECK(!upload_list_path.empty()); DCHECK(!local_log_id.empty()); @@ -406,7 +405,7 @@ void WebRtcLogUploader::AddUploadedLogInfoToUploadListFile( const base::FilePath& upload_list_path, const std::string& local_log_id, const std::string& report_id) { - DCHECK(file_thread_checker_.CalledOnValidThread()); + DCHECK(blocking_sequence_checker_.CalledOnValidSequencedThread()); DCHECK(!upload_list_path.empty()); DCHECK(!local_log_id.empty()); DCHECK(!report_id.empty()); diff --git a/chrome/browser/media/webrtc_log_uploader.h b/chrome/browser/media/webrtc_log_uploader.h index 86c2d3a..aa30bb2 100644 --- a/chrome/browser/media/webrtc_log_uploader.h +++ b/chrome/browser/media/webrtc_log_uploader.h @@ -11,6 +11,7 @@ #include "base/basictypes.h" #include "base/gtest_prod_util.h" +#include "base/sequence_checker.h" #include "base/threading/thread_checker.h" #include "chrome/browser/media/webrtc_logging_handler_host.h" #include "net/url_request/url_fetcher_delegate.h" @@ -118,7 +119,7 @@ class WebRtcLogUploader : public net::URLFetcherDelegate { void DecreaseLogCount(); - // Must be called on the FILE thread. + // Must be called on the blocking task pool. void WriteCompressedLogToFile(const std::vector<uint8>& compressed_log, const base::FilePath& log_file_path); @@ -137,7 +138,7 @@ class WebRtcLogUploader : public net::URLFetcherDelegate { // "upload_time" and "report_id" is the left empty in the entry written to the // list file. If uploading is successful, AddUploadedLogInfoToUploadListFile() // is called and those empty items are filled out. - // Must be called on the FILE thread. + // Must be called on the blocking task pool. void AddLocallyStoredLogInfoToUploadListFile( const base::FilePath& upload_list_path, const std::string& local_log_id); @@ -153,15 +154,15 @@ class WebRtcLogUploader : public net::URLFetcherDelegate { // This is the UI thread for Chromium. Some other thread for tests. base::ThreadChecker create_thread_checker_; - // This is the FILE thread for Chromium. Some other thread for tests. - base::ThreadChecker file_thread_checker_; + // This is the blocking task pool. + base::SequenceChecker blocking_sequence_checker_; // Keeps track of number of currently open logs. Must be accessed on the UI // thread. int log_count_; // For testing purposes, see OverrideUploadWithBufferForTesting. Only accessed - // on the FILE thread. + // on the blocking thread pool. std::string* post_data_; typedef std::map<const net::URLFetcher*, WebRtcLogUploadDoneData> diff --git a/chrome/browser/media/webrtc_log_util.cc b/chrome/browser/media/webrtc_log_util.cc index d443f27..d38625b 100644 --- a/chrome/browser/media/webrtc_log_util.cc +++ b/chrome/browser/media/webrtc_log_util.cc @@ -6,7 +6,9 @@ #include "base/file_util.h" #include "base/files/file_enumerator.h" +#include "base/files/file_path.h" #include "base/logging.h" +#include "base/threading/thread_restrictions.h" #include "base/time/time.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/media/webrtc_log_list.h" @@ -44,7 +46,7 @@ void WebRtcLogUtil::DeleteOldWebRtcLogFiles(const base::FilePath& log_dir) { void WebRtcLogUtil::DeleteOldAndRecentWebRtcLogFiles( const base::FilePath& log_dir, const base::Time& delete_begin_time) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); + base::ThreadRestrictions::AssertIOAllowed(); if (!base::PathExists(log_dir)) { // This will happen if no logs have been stored or uploaded. @@ -108,8 +110,7 @@ void WebRtcLogUtil::DeleteOldWebRtcLogFilesForAllProfiles() { g_browser_process->profile_manager()->GetProfileInfoCache(); size_t profiles_count = profile_cache.GetNumberOfProfiles(); for (size_t i = 0; i < profiles_count; ++i) { - content::BrowserThread::PostTask( - content::BrowserThread::FILE, + content::BrowserThread::PostBlockingPoolTask( FROM_HERE, base::Bind(&DeleteOldWebRtcLogFiles, WebRtcLogList::GetWebRtcLogDirectoryForProfile( diff --git a/chrome/browser/media/webrtc_log_util.h b/chrome/browser/media/webrtc_log_util.h index 1bc1f95..af4d06a 100644 --- a/chrome/browser/media/webrtc_log_util.h +++ b/chrome/browser/media/webrtc_log_util.h @@ -5,19 +5,22 @@ #ifndef CHROME_BROWSER_MEDIA_WEBRTC_LOG_UTIL_H_ #define CHROME_BROWSER_MEDIA_WEBRTC_LOG_UTIL_H_ -#include "base/files/file_path.h" -#include "base/time/time.h" +namespace base { +class FilePath; +class Time; +} class WebRtcLogUtil { public: // Deletes logs files older that 5 days. Updates the log file list. Must be - // called on the FILE thread. + // called on a thread that allows IO. static void DeleteOldWebRtcLogFiles(const base::FilePath& log_dir); // Deletes logs files older that 5 days and logs younger than // |delete_begin_time|. Updates the log file list. If |delete_begin_time| is // base::time::Max(), no recent logs will be deleted, and the function is - // equal to DeleteOldWebRtcLogFiles(). Must be called on the FILE thread. + // equal to DeleteOldWebRtcLogFiles(). Must be called on a thread that allows + // IO. static void DeleteOldAndRecentWebRtcLogFiles( const base::FilePath& log_dir, const base::Time& delete_begin_time); diff --git a/chrome/browser/media/webrtc_logging_handler_host.cc b/chrome/browser/media/webrtc_logging_handler_host.cc index 4d7b168..46a07df 100644 --- a/chrome/browser/media/webrtc_logging_handler_host.cc +++ b/chrome/browser/media/webrtc_logging_handler_host.cc @@ -7,25 +7,19 @@ #include <string> #include "base/bind.h" -#include "base/command_line.h" #include "base/cpu.h" #include "base/file_util.h" #include "base/logging.h" -#include "base/prefs/pref_service.h" #include "base/strings/string_number_conversions.h" #include "base/sys_info.h" #include "base/time/time.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/media/webrtc_log_list.h" #include "chrome/browser/media/webrtc_log_uploader.h" #include "chrome/browser/media/webrtc_rtp_dump_handler.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/common/chrome_switches.h" #include "chrome/common/media/webrtc_logging_messages.h" #include "chrome/common/partial_circular_buffer.h" -#include "chrome/common/pref_names.h" -#include "chromeos/settings/cros_settings_names.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/content_browser_client.h" #include "content/public/browser/gpu_data_manager.h" @@ -43,6 +37,8 @@ #endif #if defined(OS_CHROMEOS) +#include "chrome/browser/chromeos/settings/cros_settings.h" +#include "chromeos/settings/cros_settings_names.h" #include "chromeos/system/statistics_provider.h" #endif @@ -138,9 +134,9 @@ void WebRtcLoggingHandlerHost::SetMetaData( error_message = "Meta data must be set before stop or upload."; } bool success = error_message.empty(); - content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, - base::Bind(callback, success, - error_message)); + BrowserThread::PostTask(BrowserThread::UI, + FROM_HERE, + base::Bind(callback, success, error_message)); } void WebRtcLoggingHandlerHost::StartLogging( @@ -178,7 +174,7 @@ void WebRtcLoggingHandlerHost::UploadLog(const UploadDoneCallback& callback) { if (logging_state_ != STOPPED) { if (!callback.is_null()) { - content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(callback, false, "", kLogNotStoppedOrNoLogOpen)); } return; @@ -186,8 +182,8 @@ void WebRtcLoggingHandlerHost::UploadLog(const UploadDoneCallback& callback) { upload_callback_ = callback; logging_state_ = UPLOADING; - content::BrowserThread::PostTaskAndReplyWithResult( - content::BrowserThread::FILE, + base::PostTaskAndReplyWithResult( + BrowserThread::GetBlockingPool(), FROM_HERE, base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, this), @@ -240,8 +236,8 @@ void WebRtcLoggingHandlerHost::StartRtpDump( stop_rtp_dump_callback_ = stop_callback; if (!rtp_dump_handler_) { - content::BrowserThread::PostTaskAndReplyWithResult( - content::BrowserThread::FILE, + base::PostTaskAndReplyWithResult( + BrowserThread::GetBlockingPool(), FROM_HERE, base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, this), @@ -305,8 +301,8 @@ void WebRtcLoggingHandlerHost::DumpRtpPacketOnIOThread( bool incoming) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - // |rtp_dump_handler_| could be NULL if we are waiting for the FILE thread to - // create/ensure the log directory. + // |rtp_dump_handler_| could be NULL if we are waiting for the blocking + // thread pool to create/ensure the log directory. if (rtp_dump_handler_) { rtp_dump_handler_->OnRtpPacket( packet_header.get(), header_length, packet_length, incoming); @@ -319,9 +315,8 @@ void WebRtcLoggingHandlerHost::OnChannelClosing() { if (upload_log_on_render_close_) { logging_state_ = UPLOADING; logging_started_time_ = base::Time(); - - content::BrowserThread::PostTaskAndReplyWithResult( - content::BrowserThread::FILE, + base::PostTaskAndReplyWithResult( + BrowserThread::GetBlockingPool(), FROM_HERE, base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, this), @@ -330,7 +325,7 @@ void WebRtcLoggingHandlerHost::OnChannelClosing() { g_browser_process->webrtc_log_uploader()->LoggingStoppedDontUpload(); } } - content::BrowserMessageFilter::OnChannelClosing(); + BrowserMessageFilter::OnChannelClosing(); } void WebRtcLoggingHandlerHost::OnDestruct() const { @@ -405,23 +400,36 @@ void WebRtcLoggingHandlerHost::DoStartLogging() { kWebRtcLogSize / 2, false)); - BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind( - &WebRtcLoggingHandlerHost::LogInitialInfoOnFileThread, this)); + BrowserThread::PostBlockingPoolTask( + FROM_HERE, + base::Bind(&WebRtcLoggingHandlerHost::LogInitialInfoOnBlockingPool, + this)); } -void WebRtcLoggingHandlerHost::LogInitialInfoOnFileThread() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); +void WebRtcLoggingHandlerHost::LogInitialInfoOnBlockingPool() { + DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); net::NetworkInterfaceList network_list; net::GetNetworkList(&network_list, net::EXCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES); - BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( - &WebRtcLoggingHandlerHost::LogInitialInfoOnIOThread, this, network_list)); + std::string linux_distro; +#if defined(OS_LINUX) + linux_distro = base::GetLinuxDistro(); +#endif + + BrowserThread::PostTask( + BrowserThread::IO, + FROM_HERE, + base::Bind(&WebRtcLoggingHandlerHost::LogInitialInfoOnIOThread, + this, + network_list, + linux_distro)); } void WebRtcLoggingHandlerHost::LogInitialInfoOnIOThread( - const net::NetworkInterfaceList& network_list) { + const net::NetworkInterfaceList& network_list, + const std::string& linux_distro) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); // Log start time (current time). We don't use base/i18n/time_formatting.h @@ -444,7 +452,7 @@ void WebRtcLoggingHandlerHost::LogInitialInfoOnIOThread( base::SysInfo::OperatingSystemVersion() + " " + base::SysInfo::OperatingSystemArchitecture()); #if defined(OS_LINUX) - LogToCircularBuffer("Linux distribution: " + base::GetLinuxDistro()); + LogToCircularBuffer("Linux distribution: " + linux_distro); #endif // CPU @@ -515,7 +523,7 @@ void WebRtcLoggingHandlerHost::LogToCircularBuffer(const std::string& message) { } base::FilePath WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); + DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); base::FilePath log_dir_path = WebRtcLogList::GetWebRtcLogDirectoryForProfile(profile_->GetPath()); base::File::Error error; @@ -566,13 +574,14 @@ void WebRtcLoggingHandlerHost::DoUploadLogAndRtpDumps( upload_done_data.host = this; upload_callback_.Reset(); - BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind( - &WebRtcLogUploader::LoggingStoppedDoUpload, - base::Unretained(g_browser_process->webrtc_log_uploader()), - Passed(&log_buffer_), - kWebRtcLogSize, - meta_data_, - upload_done_data)); + BrowserThread::PostBlockingPoolTask( + FROM_HERE, + base::Bind(&WebRtcLogUploader::LoggingStoppedDoUpload, + base::Unretained(g_browser_process->webrtc_log_uploader()), + Passed(&log_buffer_), + kWebRtcLogSize, + meta_data_, + upload_done_data)); meta_data_.clear(); circular_buffer_.reset(); @@ -583,12 +592,10 @@ void WebRtcLoggingHandlerHost::FireGenericDoneCallback( bool success, const std::string& error_message) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - DCHECK(!(*callback).is_null()); - content::BrowserThread::PostTask( - content::BrowserThread::UI, - FROM_HERE, - base::Bind(*callback, success, error_message)); - (*callback).Reset(); + DCHECK(!callback->is_null()); + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, + base::Bind(*callback, success, error_message)); + callback->Reset(); } void WebRtcLoggingHandlerHost::CreateRtpDumpHandlerAndStart( @@ -598,8 +605,8 @@ void WebRtcLoggingHandlerHost::CreateRtpDumpHandlerAndStart( DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); // |rtp_dump_handler_| may be non-NULL if StartRtpDump is called again before - // GetLogDirectoryAndEnsureExists returns on the FILE thread for a previous - // StartRtpDump. + // GetLogDirectoryAndEnsureExists returns on the blocking thread pool for a + // previous StartRtpDump. if (!rtp_dump_handler_) rtp_dump_handler_.reset(new WebRtcRtpDumpHandler(dump_dir)); diff --git a/chrome/browser/media/webrtc_logging_handler_host.h b/chrome/browser/media/webrtc_logging_handler_host.h index dfff8c3..493dd01 100644 --- a/chrome/browser/media/webrtc_logging_handler_host.h +++ b/chrome/browser/media/webrtc_logging_handler_host.h @@ -14,10 +14,6 @@ #include "content/public/browser/render_process_host.h" #include "net/base/net_util.h" -namespace net { -class URLRequestContextGetter; -} // namespace net - class PartialCircularBuffer; class Profile; @@ -136,8 +132,9 @@ class WebRtcLoggingHandlerHost : public content::BrowserMessageFilter { void StartLoggingIfAllowed(); void DoStartLogging(); - void LogInitialInfoOnFileThread(); - void LogInitialInfoOnIOThread(const net::NetworkInterfaceList& network_list); + void LogInitialInfoOnBlockingPool(); + void LogInitialInfoOnIOThread(const net::NetworkInterfaceList& network_list, + const std::string& linux_distro); void NotifyLoggingStarted(); // Writes a formatted log |message| to the |circular_buffer_|. @@ -176,7 +173,7 @@ class WebRtcLoggingHandlerHost : public content::BrowserMessageFilter { scoped_ptr<PartialCircularBuffer> circular_buffer_; // The profile associated with our renderer process. - Profile* profile_; + const Profile* const profile_; // These are only accessed on the IO thread, except when in STARTING state. In // this state we are protected since entering any function that alters the |