OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "net/socket_stream/socket_stream_job_manager.h" | 5 #include "net/socket_stream/socket_stream_job_manager.h" |
6 | 6 |
7 #include "base/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
8 | 8 |
9 namespace net { | 9 namespace net { |
10 | 10 |
11 SocketStreamJobManager::SocketStreamJobManager() { | 11 SocketStreamJobManager::SocketStreamJobManager() { |
12 } | 12 } |
13 | 13 |
14 SocketStreamJobManager::~SocketStreamJobManager() { | 14 SocketStreamJobManager::~SocketStreamJobManager() { |
15 } | 15 } |
16 | 16 |
17 // static | 17 // static |
18 SocketStreamJobManager* SocketStreamJobManager::GetInstance() { | 18 SocketStreamJobManager* SocketStreamJobManager::GetInstance() { |
19 return Singleton<SocketStreamJobManager>::get(); | 19 return Singleton<SocketStreamJobManager>::get(); |
20 } | 20 } |
21 | 21 |
22 SocketStreamJob* SocketStreamJobManager::CreateJob( | 22 SocketStreamJob* SocketStreamJobManager::CreateJob( |
23 const GURL& url, SocketStream::Delegate* delegate, | 23 const GURL& url, |
24 URLRequestContext* context, CookieStore* cookie_store) const { | 24 SocketStream::Delegate* delegate, |
| 25 URLRequestContext* context, |
| 26 CookieStore* cookie_store) const { |
25 // If url is invalid, create plain SocketStreamJob, which will close | 27 // If url is invalid, create plain SocketStreamJob, which will close |
26 // the socket immediately. | 28 // the socket immediately. |
27 if (!url.is_valid()) { | 29 if (!url.is_valid()) { |
28 SocketStreamJob* job = new SocketStreamJob(); | 30 SocketStreamJob* job = new SocketStreamJob(); |
29 job->InitSocketStream(new SocketStream(url, delegate, context, | 31 job->InitSocketStream( |
30 cookie_store)); | 32 new SocketStream(url, delegate, context, cookie_store)); |
31 return job; | 33 return job; |
32 } | 34 } |
33 | 35 |
34 const std::string& scheme = url.scheme(); // already lowercase | 36 const std::string& scheme = url.scheme(); // already lowercase |
35 | 37 |
36 base::AutoLock locked(lock_); | 38 base::AutoLock locked(lock_); |
37 FactoryMap::const_iterator found = factories_.find(scheme); | 39 FactoryMap::const_iterator found = factories_.find(scheme); |
38 if (found != factories_.end()) { | 40 if (found != factories_.end()) { |
39 SocketStreamJob* job = found->second(url, delegate, context, cookie_store); | 41 SocketStreamJob* job = found->second(url, delegate, context, cookie_store); |
40 if (job) | 42 if (job) |
41 return job; | 43 return job; |
42 } | 44 } |
43 SocketStreamJob* job = new SocketStreamJob(); | 45 SocketStreamJob* job = new SocketStreamJob(); |
44 job->InitSocketStream(new SocketStream(url, delegate, context, cookie_store)); | 46 job->InitSocketStream(new SocketStream(url, delegate, context, cookie_store)); |
45 return job; | 47 return job; |
46 } | 48 } |
47 | 49 |
48 SocketStreamJob::ProtocolFactory* | 50 SocketStreamJob::ProtocolFactory* |
49 SocketStreamJobManager::RegisterProtocolFactory( | 51 SocketStreamJobManager::RegisterProtocolFactory( |
50 const std::string& scheme, SocketStreamJob::ProtocolFactory* factory) { | 52 const std::string& scheme, |
| 53 SocketStreamJob::ProtocolFactory* factory) { |
51 base::AutoLock locked(lock_); | 54 base::AutoLock locked(lock_); |
52 | 55 |
53 SocketStreamJob::ProtocolFactory* old_factory; | 56 SocketStreamJob::ProtocolFactory* old_factory; |
54 FactoryMap::iterator found = factories_.find(scheme); | 57 FactoryMap::iterator found = factories_.find(scheme); |
55 if (found != factories_.end()) { | 58 if (found != factories_.end()) { |
56 old_factory = found->second; | 59 old_factory = found->second; |
57 } else { | 60 } else { |
58 old_factory = NULL; | 61 old_factory = NULL; |
59 } | 62 } |
60 if (factory) { | 63 if (factory) { |
61 factories_[scheme] = factory; | 64 factories_[scheme] = factory; |
62 } else if (found != factories_.end()) { | 65 } else if (found != factories_.end()) { |
63 factories_.erase(found); | 66 factories_.erase(found); |
64 } | 67 } |
65 return old_factory; | 68 return old_factory; |
66 } | 69 } |
67 | 70 |
68 } // namespace net | 71 } // namespace net |
OLD | NEW |