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

Side by Side Diff: content/browser/loader/netlog_observer.h

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 unified diff | Download patch
OLDNEW
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 #ifndef CONTENT_BROWSER_LOADER_NETLOG_OBSERVER_H_ 5 #ifndef CONTENT_BROWSER_LOADER_NETLOG_OBSERVER_H_
6 #define CONTENT_BROWSER_LOADER_NETLOG_OBSERVER_H_ 6 #define CONTENT_BROWSER_LOADER_NETLOG_OBSERVER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
11 #include "base/lazy_instance.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/single_thread_task_runner.h"
13 #include "content/public/common/resource_devtools_info.h" 15 #include "content/public/common/resource_devtools_info.h"
14 #include "net/log/net_log.h" 16 #include "net/log/net_log.h"
15 17
16 namespace net { 18 namespace net {
17 class URLRequest; 19 class URLRequest;
18 } // namespace net 20 } // namespace net
19 21
20 namespace content { 22 namespace content {
21 struct ResourceResponse; 23 struct ResourceResponse;
22 24
23 // NetLogObserver watches the NetLog event stream and collects the stuff that 25 // NetLogObserver watches the NetLog event stream and collects the stuff that
24 // may be of interest to the client. Currently, this only includes actual 26 // may be of interest to the client. Currently, this only includes actual
25 // HTTP/SPDY headers sent and received over the network. 27 // HTTP/SPDY headers sent and received over the network.
26 // 28 //
27 // As NetLogObserver shares live data with objects that live on the IO Thread, 29 // As NetLogObserver shares live data with objects that live on the IO Thread,
28 // it must also reside on the IO Thread. Only OnAddEntry can be called from 30 // it must also reside on the IO Thread. Only OnAddEntry can be called from
29 // other threads. 31 // other threads.
30 class NetLogObserver : public net::NetLog::ThreadSafeObserver { 32 class NetLogObserver : public net::NetLog::ThreadSafeObserver {
31 typedef ResourceDevToolsInfo ResourceInfo; 33 typedef ResourceDevToolsInfo ResourceInfo;
32 34
33 public: 35 public:
34 // net::NetLog::ThreadSafeObserver implementation: 36 // net::NetLog::ThreadSafeObserver implementation:
35 void OnAddEntry(const net::NetLog::Entry& entry) override; 37 void OnAddEntry(const net::NetLog::Entry& entry) override;
36 38
37 void OnAddURLRequestEntry(const net::NetLog::Entry& entry); 39 // The NetLog instance is passed in via the |net_log| parameter.
40 // A reference to the IO thread task runner is passed via the
41 // |io_thread_runner| parameter.
42 static void Attach(
43 net::NetLog* net_log,
44 scoped_refptr<base::SingleThreadTaskRunner> io_thread_runner);
38 45
39 static void Attach();
40 static void Detach(); 46 static void Detach();
41 47
42 // Must be called on the IO thread. May return NULL if no observers 48 // Must be called on the IO thread. May return NULL if no observers
43 // are active. 49 // are active.
44 static NetLogObserver* GetInstance(); 50 static NetLogObserver* GetInstance();
45 static void PopulateResponseInfo(net::URLRequest*, ResourceResponse*); 51 static void PopulateResponseInfo(net::URLRequest*, ResourceResponse*);
46 52
47 private: 53 private:
48 static NetLogObserver* instance_; 54 static NetLogObserver* instance_;
49 55
50 NetLogObserver(); 56 NetLogObserver();
51 ~NetLogObserver() override; 57 ~NetLogObserver() override;
52 58
53 ResourceInfo* GetResourceInfo(uint32_t id); 59 ResourceInfo* GetResourceInfo(uint32_t id);
54 60
61 void OnAddURLRequestEntry(const net::NetLog::Entry& entry);
62
55 typedef base::hash_map<uint32_t, scoped_refptr<ResourceInfo>> 63 typedef base::hash_map<uint32_t, scoped_refptr<ResourceInfo>>
56 RequestToInfoMap; 64 RequestToInfoMap;
57 RequestToInfoMap request_to_info_; 65 RequestToInfoMap request_to_info_;
58 66
67 // Contains the IO thread task runner instance.
68 static base::LazyInstance<scoped_refptr<base::SingleThreadTaskRunner>>::Leaky
69 io_thread_task_runner_;
70
59 DISALLOW_COPY_AND_ASSIGN(NetLogObserver); 71 DISALLOW_COPY_AND_ASSIGN(NetLogObserver);
60 }; 72 };
61 73
62 } // namespace content 74 } // namespace content
63 75
64 #endif // CONTENT_BROWSER_LOADER_NETLOG_OBSERVER_H_ 76 #endif // CONTENT_BROWSER_LOADER_NETLOG_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698