OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/browser/chrome_plugin_browsing_context.h" | 5 #include "chrome/browser/chrome_plugin_browsing_context.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/singleton.h" | 8 #include "base/singleton.h" |
9 #include "chrome/browser/browser_thread.h" | 9 #include "chrome/browser/browser_thread.h" |
10 #include "chrome/common/notification_service.h" | 10 #include "chrome/common/notification_service.h" |
11 | 11 |
12 CPBrowsingContextManager* CPBrowsingContextManager::GetInstance() { | 12 CPBrowsingContextManager* CPBrowsingContextManager::GetInstance() { |
13 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 13 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
14 return Singleton<CPBrowsingContextManager>::get(); | 14 return Singleton<CPBrowsingContextManager>::get(); |
15 } | 15 } |
16 | 16 |
17 CPBrowsingContextManager::CPBrowsingContextManager() { | 17 CPBrowsingContextManager::CPBrowsingContextManager() { |
18 registrar_.Add(this, NotificationType::URL_REQUEST_CONTEXT_RELEASED, | 18 registrar_.Add(this, NotificationType::URL_REQUEST_CONTEXT_RELEASED, |
19 NotificationService::AllSources()); | 19 NotificationService::AllSources()); |
20 } | 20 } |
21 | 21 |
22 CPBrowsingContextManager::~CPBrowsingContextManager() { | 22 CPBrowsingContextManager::~CPBrowsingContextManager() { |
23 } | 23 } |
24 | 24 |
25 CPBrowsingContext CPBrowsingContextManager::Allocate( | 25 CPBrowsingContext CPBrowsingContextManager::Allocate( |
26 URLRequestContext* context) { | 26 net::URLRequestContext* context) { |
27 int32 map_id = map_.Add(context); | 27 int32 map_id = map_.Add(context); |
28 return static_cast<CPBrowsingContext>(map_id); | 28 return static_cast<CPBrowsingContext>(map_id); |
29 } | 29 } |
30 | 30 |
31 URLRequestContext* CPBrowsingContextManager::ToURLRequestContext( | 31 net::URLRequestContext* CPBrowsingContextManager::ToURLRequestContext( |
32 CPBrowsingContext id) { | 32 CPBrowsingContext id) { |
33 return map_.Lookup(static_cast<int32>(id)); | 33 return map_.Lookup(static_cast<int32>(id)); |
34 } | 34 } |
35 | 35 |
36 CPBrowsingContext CPBrowsingContextManager::Lookup(URLRequestContext* context) { | 36 CPBrowsingContext CPBrowsingContextManager::Lookup( |
| 37 net::URLRequestContext* context) { |
37 ReverseMap::const_iterator it = reverse_map_.find(context); | 38 ReverseMap::const_iterator it = reverse_map_.find(context); |
38 if (it == reverse_map_.end()) { | 39 if (it == reverse_map_.end()) { |
39 CPBrowsingContext id = Allocate(context); | 40 CPBrowsingContext id = Allocate(context); |
40 reverse_map_[context] = id; | 41 reverse_map_[context] = id; |
41 return id; | 42 return id; |
42 } else { | 43 } else { |
43 return it->second; | 44 return it->second; |
44 } | 45 } |
45 } | 46 } |
46 | 47 |
47 void CPBrowsingContextManager::Observe(NotificationType type, | 48 void CPBrowsingContextManager::Observe(NotificationType type, |
48 const NotificationSource& source, | 49 const NotificationSource& source, |
49 const NotificationDetails& details) { | 50 const NotificationDetails& details) { |
50 DCHECK(type == NotificationType::URL_REQUEST_CONTEXT_RELEASED); | 51 DCHECK(type == NotificationType::URL_REQUEST_CONTEXT_RELEASED); |
51 | 52 |
52 URLRequestContext* context = Source<URLRequestContext>(source).ptr(); | 53 net::URLRequestContext* context = |
| 54 Source<net::URLRequestContext>(source).ptr(); |
53 | 55 |
54 // Multiple CPBrowsingContexts may refer to the same URLRequestContext. | 56 // Multiple CPBrowsingContexts may refer to the same URLRequestContext. |
55 for (Map::iterator it(&map_); !it.IsAtEnd(); it.Advance()) { | 57 for (Map::iterator it(&map_); !it.IsAtEnd(); it.Advance()) { |
56 if (it.GetCurrentValue() == context) | 58 if (it.GetCurrentValue() == context) |
57 map_.Remove(it.GetCurrentKey()); | 59 map_.Remove(it.GetCurrentKey()); |
58 } | 60 } |
59 | 61 |
60 reverse_map_.erase(context); | 62 reverse_map_.erase(context); |
61 } | 63 } |
OLD | NEW |