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

Unified Diff: content/browser/loader/netlog_observer.cc

Issue 2115823004: Avoid using BrowserThread and ContentBrowserClient in NetLogObserver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build error Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/loader/netlog_observer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/loader/netlog_observer.cc
diff --git a/content/browser/loader/netlog_observer.cc b/content/browser/loader/netlog_observer.cc
index 3f9405a827e1f143bafd92d61ed7f27dc9396f56..fca4bfcf13a7efec7681d2c4d1308dcc18341f06 100644
--- a/content/browser/loader/netlog_observer.cc
+++ b/content/browser/loader/netlog_observer.cc
@@ -9,8 +9,6 @@
#include "base/strings/string_util.h"
#include "base/values.h"
#include "content/browser/loader/resource_request_info_impl.h"
-#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/content_browser_client.h"
#include "content/public/common/resource_response.h"
#include "net/base/load_flags.h"
#include "net/http/http_response_headers.h"
@@ -22,8 +20,13 @@
namespace content {
const size_t kMaxNumEntries = 1000;
+// static
NetLogObserver* NetLogObserver::instance_ = NULL;
+// static
+base::LazyInstance<scoped_refptr<base::SingleThreadTaskRunner>>::Leaky
+ NetLogObserver::io_thread_task_runner_;
+
NetLogObserver::NetLogObserver() {}
NetLogObserver::~NetLogObserver() {}
@@ -36,8 +39,10 @@ NetLogObserver::ResourceInfo* NetLogObserver::GetResourceInfo(uint32_t id) {
}
void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) {
+ DCHECK(io_thread_task_runner_.Get().get());
+
// The events that the Observer is interested in only occur on the IO thread.
- if (!BrowserThread::CurrentlyOn(BrowserThread::IO))
+ if (!io_thread_task_runner_.Get()->BelongsToCurrentThread())
return;
if (entry.source().type == net::NetLog::SOURCE_URL_REQUEST)
@@ -45,8 +50,6 @@ void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) {
}
void NetLogObserver::OnAddURLRequestEntry(const net::NetLog::Entry& entry) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
-
bool is_begin = entry.phase() == net::NetLog::PHASE_BEGIN;
bool is_end = entry.phase() == net::NetLog::PHASE_END;
@@ -153,9 +156,11 @@ void NetLogObserver::OnAddURLRequestEntry(const net::NetLog::Entry& entry) {
}
}
-void NetLogObserver::Attach() {
+void NetLogObserver::Attach(
+ net::NetLog* net_log,
+ scoped_refptr<base::SingleThreadTaskRunner> io_thread_runner) {
DCHECK(!instance_);
- net::NetLog* net_log = GetContentClient()->browser()->GetNetLog();
+ io_thread_task_runner_.Get() = io_thread_runner;
if (net_log) {
instance_ = new NetLogObserver();
net_log->DeprecatedAddObserver(
@@ -164,8 +169,9 @@ void NetLogObserver::Attach() {
}
void NetLogObserver::Detach() {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
-
+ DCHECK(io_thread_task_runner_.Get().get() &&
+ io_thread_task_runner_.Get()->BelongsToCurrentThread());
+ io_thread_task_runner_.Get() = nullptr;
if (instance_) {
// Safest not to do this in the destructor to maintain thread safety across
// refactorings.
@@ -176,7 +182,8 @@ void NetLogObserver::Detach() {
}
NetLogObserver* NetLogObserver::GetInstance() {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK(io_thread_task_runner_.Get().get() &&
pfeldman 2016/07/13 18:16:19 Before the change: calling NetLogObserver::GetInst
ananta 2016/07/13 18:52:55 Fixed this. Changed the task runner to a thread ch
+ io_thread_task_runner_.Get()->BelongsToCurrentThread());
return instance_;
}
« no previous file with comments | « content/browser/loader/netlog_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698