| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/base/forwarding_net_log.h" | |
| 6 | |
| 7 #include "base/lock.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/message_loop.h" | |
| 10 | |
| 11 namespace net { | |
| 12 | |
| 13 // Reference-counted wrapper, so we can use PostThread and it can safely | |
| 14 // outlive the parent ForwardingNetLog. | |
| 15 class ForwardingNetLog::Core | |
| 16 : public base::RefCountedThreadSafe<ForwardingNetLog::Core> { | |
| 17 public: | |
| 18 Core(NetLog* impl, MessageLoop* loop) : impl_(impl), loop_(loop) { | |
| 19 DCHECK(impl); | |
| 20 DCHECK(loop); | |
| 21 } | |
| 22 | |
| 23 // Called once the parent ForwardingNetLog is being destroyed. It | |
| 24 // is invalid to access |loop_| and |impl_| afterwards. | |
| 25 void Orphan() { | |
| 26 AutoLock l(lock_); | |
| 27 loop_ = NULL; | |
| 28 impl_ = NULL; | |
| 29 } | |
| 30 | |
| 31 void AddEntry(EventType type, | |
| 32 const base::TimeTicks& time, | |
| 33 const Source& source, | |
| 34 EventPhase phase, | |
| 35 EventParameters* params) { | |
| 36 AutoLock l(lock_); | |
| 37 if (!loop_) | |
| 38 return; // Was orphaned. | |
| 39 | |
| 40 loop_->PostTask( | |
| 41 FROM_HERE, | |
| 42 NewRunnableMethod( | |
| 43 this, &Core::AddEntryOnLoop, type, time, source, phase, | |
| 44 scoped_refptr<EventParameters>(params))); | |
| 45 } | |
| 46 | |
| 47 private: | |
| 48 void AddEntryOnLoop(EventType type, | |
| 49 const base::TimeTicks& time, | |
| 50 const Source& source, | |
| 51 EventPhase phase, | |
| 52 scoped_refptr<EventParameters> params) { | |
| 53 AutoLock l(lock_); | |
| 54 if (!loop_) | |
| 55 return; // Was orphaned. | |
| 56 | |
| 57 DCHECK_EQ(MessageLoop::current(), loop_); | |
| 58 | |
| 59 impl_->AddEntry(type, time, source, phase, params); | |
| 60 } | |
| 61 | |
| 62 Lock lock_; | |
| 63 NetLog* impl_; | |
| 64 MessageLoop* loop_; | |
| 65 }; | |
| 66 | |
| 67 ForwardingNetLog::ForwardingNetLog(NetLog* impl, MessageLoop* loop) | |
| 68 : core_(new Core(impl, loop)) { | |
| 69 } | |
| 70 | |
| 71 ForwardingNetLog::~ForwardingNetLog() { | |
| 72 core_->Orphan(); | |
| 73 } | |
| 74 | |
| 75 void ForwardingNetLog::AddEntry(EventType type, | |
| 76 const base::TimeTicks& time, | |
| 77 const Source& source, | |
| 78 EventPhase phase, | |
| 79 EventParameters* params) { | |
| 80 core_->AddEntry(type, time, source, phase, params); | |
| 81 } | |
| 82 | |
| 83 uint32 ForwardingNetLog::NextID() { | |
| 84 // Can't forward a synchronous API. | |
| 85 CHECK(false) << "Not supported"; | |
| 86 return 0; | |
| 87 } | |
| 88 | |
| 89 NetLog::LogLevel ForwardingNetLog::GetLogLevel() const { | |
| 90 // Can't forward a synchronous API. | |
| 91 CHECK(false) << "Not supported"; | |
| 92 return LOG_ALL_BUT_BYTES; | |
| 93 } | |
| 94 | |
| 95 } // namespace net | |
| 96 | |
| OLD | NEW |