OLD | NEW |
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 void OnAddURLRequestEntry(const net::NetLog::Entry& entry); |
38 | 40 |
39 static void Attach(); | 41 // The NetLog instance is passed in via the |net_log| parameter. |
| 42 static void Attach(net::NetLog* net_log); |
40 static void Detach(); | 43 static void Detach(); |
41 | 44 |
42 // Must be called on the IO thread. May return NULL if no observers | 45 // Must be called on the IO thread. May return NULL if no observers |
43 // are active. | 46 // are active. |
44 static NetLogObserver* GetInstance(); | 47 static NetLogObserver* GetInstance(); |
45 static void PopulateResponseInfo(net::URLRequest*, ResourceResponse*); | 48 static void PopulateResponseInfo(net::URLRequest*, ResourceResponse*); |
46 | 49 |
| 50 // The IO thread task runner is passed in via this function. |
| 51 static void SetIOThreadTaskRunner( |
| 52 scoped_refptr<base::SingleThreadTaskRunner> io_thread_runner); |
| 53 |
47 private: | 54 private: |
48 static NetLogObserver* instance_; | 55 static NetLogObserver* instance_; |
49 | 56 |
50 NetLogObserver(); | 57 NetLogObserver(); |
51 ~NetLogObserver() override; | 58 ~NetLogObserver() override; |
52 | 59 |
53 ResourceInfo* GetResourceInfo(uint32_t id); | 60 ResourceInfo* GetResourceInfo(uint32_t id); |
54 | 61 |
55 typedef base::hash_map<uint32_t, scoped_refptr<ResourceInfo>> | 62 typedef base::hash_map<uint32_t, scoped_refptr<ResourceInfo>> |
56 RequestToInfoMap; | 63 RequestToInfoMap; |
57 RequestToInfoMap request_to_info_; | 64 RequestToInfoMap request_to_info_; |
58 | 65 |
| 66 // Contains the IO thread task runner instance. |
| 67 static base::LazyInstance<scoped_refptr<base::SingleThreadTaskRunner>>::Leaky |
| 68 io_thread_task_runner_; |
| 69 |
59 DISALLOW_COPY_AND_ASSIGN(NetLogObserver); | 70 DISALLOW_COPY_AND_ASSIGN(NetLogObserver); |
60 }; | 71 }; |
61 | 72 |
62 } // namespace content | 73 } // namespace content |
63 | 74 |
64 #endif // CONTENT_BROWSER_LOADER_NETLOG_OBSERVER_H_ | 75 #endif // CONTENT_BROWSER_LOADER_NETLOG_OBSERVER_H_ |
OLD | NEW |