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/threading/thread_checker.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 static void Attach(net::NetLog* net_log); |
38 | 41 |
39 static void Attach(); | |
40 static void Detach(); | 42 static void Detach(); |
41 | 43 |
42 // Must be called on the IO thread. May return NULL if no observers | 44 // Must be called on the IO thread. May return NULL if no observers |
43 // are active. | 45 // are active. |
44 static NetLogObserver* GetInstance(); | 46 static NetLogObserver* GetInstance(); |
45 static void PopulateResponseInfo(net::URLRequest*, ResourceResponse*); | 47 static void PopulateResponseInfo(net::URLRequest*, ResourceResponse*); |
46 | 48 |
47 private: | 49 private: |
48 static NetLogObserver* instance_; | 50 static NetLogObserver* instance_; |
49 | 51 |
50 NetLogObserver(); | 52 NetLogObserver(); |
51 ~NetLogObserver() override; | 53 ~NetLogObserver() override; |
52 | 54 |
53 ResourceInfo* GetResourceInfo(uint32_t id); | 55 ResourceInfo* GetResourceInfo(uint32_t id); |
54 | 56 |
| 57 void OnAddURLRequestEntry(const net::NetLog::Entry& entry); |
| 58 |
55 typedef base::hash_map<uint32_t, scoped_refptr<ResourceInfo>> | 59 typedef base::hash_map<uint32_t, scoped_refptr<ResourceInfo>> |
56 RequestToInfoMap; | 60 RequestToInfoMap; |
57 RequestToInfoMap request_to_info_; | 61 RequestToInfoMap request_to_info_; |
58 | 62 |
| 63 // Used to validate that calls to the NetLogObserver methods occur on the |
| 64 // thread it was instantiated on. Typically the IO thread. |
| 65 static base::LazyInstance<std::unique_ptr<base::ThreadChecker>>::Leaky |
| 66 io_thread_checker_; |
| 67 |
59 DISALLOW_COPY_AND_ASSIGN(NetLogObserver); | 68 DISALLOW_COPY_AND_ASSIGN(NetLogObserver); |
60 }; | 69 }; |
61 | 70 |
62 } // namespace content | 71 } // namespace content |
63 | 72 |
64 #endif // CONTENT_BROWSER_LOADER_NETLOG_OBSERVER_H_ | 73 #endif // CONTENT_BROWSER_LOADER_NETLOG_OBSERVER_H_ |
OLD | NEW |