| 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 #include "chrome/renderer/extensions/chrome_v8_context_set.h" | 5 #include "chrome/renderer/extensions/chrome_v8_context_set.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/tracked_objects.h" | 9 #include "base/tracked_objects.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 ChromeV8ContextSet::ChromeV8ContextSet() { | 28 ChromeV8ContextSet::ChromeV8ContextSet() { |
| 29 } | 29 } |
| 30 ChromeV8ContextSet::~ChromeV8ContextSet() { | 30 ChromeV8ContextSet::~ChromeV8ContextSet() { |
| 31 } | 31 } |
| 32 | 32 |
| 33 int ChromeV8ContextSet::size() const { | 33 int ChromeV8ContextSet::size() const { |
| 34 return static_cast<int>(contexts_.size()); | 34 return static_cast<int>(contexts_.size()); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void ChromeV8ContextSet::Add(ChromeV8Context* context) { | 37 void ChromeV8ContextSet::Add(ChromeV8Context* context) { |
| 38 if (DCHECK_IS_ON()) { | 38 #if DCHECK_IS_ON |
| 39 // It's OK to insert the same context twice, but we should only ever have | 39 // It's OK to insert the same context twice, but we should only ever have |
| 40 // one ChromeV8Context per v8::Context. | 40 // one ChromeV8Context per v8::Context. |
| 41 for (ContextSet::iterator iter = contexts_.begin(); iter != contexts_.end(); | 41 for (ContextSet::iterator iter = contexts_.begin(); iter != contexts_.end(); |
| 42 ++iter) { | 42 ++iter) { |
| 43 ChromeV8Context* candidate = *iter; | 43 ChromeV8Context* candidate = *iter; |
| 44 if (candidate != context) | 44 if (candidate != context) |
| 45 DCHECK(candidate->v8_context() != context->v8_context()); | 45 DCHECK(candidate->v8_context() != context->v8_context()); |
| 46 } | |
| 47 } | 46 } |
| 47 #endif |
| 48 contexts_.insert(context); | 48 contexts_.insert(context); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void ChromeV8ContextSet::Remove(ChromeV8Context* context) { | 51 void ChromeV8ContextSet::Remove(ChromeV8Context* context) { |
| 52 if (contexts_.erase(context)) { | 52 if (contexts_.erase(context)) { |
| 53 context->Invalidate(); | 53 context->Invalidate(); |
| 54 base::MessageLoop::current()->DeleteSoon(FROM_HERE, context); | 54 base::MessageLoop::current()->DeleteSoon(FROM_HERE, context); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 (*it)->DispatchOnUnloadEvent(); | 129 (*it)->DispatchOnUnloadEvent(); |
| 130 removed.insert(*it); | 130 removed.insert(*it); |
| 131 Remove(*it); | 131 Remove(*it); |
| 132 } | 132 } |
| 133 } | 133 } |
| 134 | 134 |
| 135 return removed; | 135 return removed; |
| 136 } | 136 } |
| 137 | 137 |
| 138 } // namespace extensions | 138 } // namespace extensions |
| OLD | NEW |