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_; |
} |