| 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/lazy_instance.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 15 #include "content/public/common/resource_devtools_info.h" | 15 #include "content/public/common/resource_devtools_info.h" |
| 16 #include "net/log/net_log.h" | 16 #include "net/log/net_log.h" |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 class URLRequest; | 19 class URLRequest; |
| 20 class NetLogEntry; |
| 20 } // namespace net | 21 } // namespace net |
| 21 | 22 |
| 22 namespace content { | 23 namespace content { |
| 23 struct ResourceResponse; | 24 struct ResourceResponse; |
| 24 | 25 |
| 25 // NetLogObserver watches the NetLog event stream and collects the stuff that | 26 // NetLogObserver watches the NetLog event stream and collects the stuff that |
| 26 // may be of interest to the client. Currently, this only includes actual | 27 // may be of interest to the client. Currently, this only includes actual |
| 27 // HTTP/SPDY headers sent and received over the network. | 28 // HTTP/SPDY headers sent and received over the network. |
| 28 // | 29 // |
| 29 // As NetLogObserver shares live data with objects that live on the IO Thread, | 30 // As NetLogObserver shares live data with objects that live on the IO Thread, |
| 30 // it must also reside on the IO Thread. Only OnAddEntry can be called from | 31 // it must also reside on the IO Thread. Only OnAddEntry can be called from |
| 31 // other threads. | 32 // other threads. |
| 32 class NetLogObserver : public net::NetLog::ThreadSafeObserver { | 33 class NetLogObserver : public net::NetLog::ThreadSafeObserver { |
| 33 typedef ResourceDevToolsInfo ResourceInfo; | 34 typedef ResourceDevToolsInfo ResourceInfo; |
| 34 | 35 |
| 35 public: | 36 public: |
| 36 // net::NetLog::ThreadSafeObserver implementation: | 37 // net::NetLog::ThreadSafeObserver implementation: |
| 37 void OnAddEntry(const net::NetLog::Entry& entry) override; | 38 void OnAddEntry(const net::NetLogEntry& entry) override; |
| 38 | 39 |
| 39 // The NetLog instance is passed in via the |net_log| parameter. | 40 // The NetLog instance is passed in via the |net_log| parameter. |
| 40 static void Attach(net::NetLog* net_log); | 41 static void Attach(net::NetLog* net_log); |
| 41 | 42 |
| 42 static void Detach(); | 43 static void Detach(); |
| 43 | 44 |
| 44 // 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 |
| 45 // are active. | 46 // are active. |
| 46 static NetLogObserver* GetInstance(); | 47 static NetLogObserver* GetInstance(); |
| 47 static void PopulateResponseInfo(net::URLRequest*, ResourceResponse*); | 48 static void PopulateResponseInfo(net::URLRequest*, ResourceResponse*); |
| 48 | 49 |
| 49 private: | 50 private: |
| 50 static NetLogObserver* instance_; | 51 static NetLogObserver* instance_; |
| 51 | 52 |
| 52 NetLogObserver(); | 53 NetLogObserver(); |
| 53 ~NetLogObserver() override; | 54 ~NetLogObserver() override; |
| 54 | 55 |
| 55 ResourceInfo* GetResourceInfo(uint32_t id); | 56 ResourceInfo* GetResourceInfo(uint32_t id); |
| 56 | 57 |
| 57 void OnAddURLRequestEntry(const net::NetLog::Entry& entry); | 58 void OnAddURLRequestEntry(const net::NetLogEntry& entry); |
| 58 | 59 |
| 59 typedef base::hash_map<uint32_t, scoped_refptr<ResourceInfo>> | 60 typedef base::hash_map<uint32_t, scoped_refptr<ResourceInfo>> |
| 60 RequestToInfoMap; | 61 RequestToInfoMap; |
| 61 RequestToInfoMap request_to_info_; | 62 RequestToInfoMap request_to_info_; |
| 62 | 63 |
| 63 // Used to validate that calls to the NetLogObserver methods occur on the | 64 // Used to validate that calls to the NetLogObserver methods occur on the |
| 64 // thread it was instantiated on. Typically the IO thread. | 65 // thread it was instantiated on. Typically the IO thread. |
| 65 static base::LazyInstance<std::unique_ptr<base::ThreadChecker>>::Leaky | 66 static base::LazyInstance<std::unique_ptr<base::ThreadChecker>>::Leaky |
| 66 io_thread_checker_; | 67 io_thread_checker_; |
| 67 | 68 |
| 68 DISALLOW_COPY_AND_ASSIGN(NetLogObserver); | 69 DISALLOW_COPY_AND_ASSIGN(NetLogObserver); |
| 69 }; | 70 }; |
| 70 | 71 |
| 71 } // namespace content | 72 } // namespace content |
| 72 | 73 |
| 73 #endif // CONTENT_BROWSER_LOADER_NETLOG_OBSERVER_H_ | 74 #endif // CONTENT_BROWSER_LOADER_NETLOG_OBSERVER_H_ |
| OLD | NEW |