OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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/singleton.h" | 7 #include "base/singleton.h" |
8 | 8 |
9 namespace net { | 9 namespace net { |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 // If url is invalid, create plain SocketStreamJob, which will close | 24 // If url is invalid, create plain SocketStreamJob, which will close |
25 // the socket immediately. | 25 // the socket immediately. |
26 if (!url.is_valid()) { | 26 if (!url.is_valid()) { |
27 SocketStreamJob* job = new SocketStreamJob(); | 27 SocketStreamJob* job = new SocketStreamJob(); |
28 job->InitSocketStream(new SocketStream(url, delegate)); | 28 job->InitSocketStream(new SocketStream(url, delegate)); |
29 return job; | 29 return job; |
30 } | 30 } |
31 | 31 |
32 const std::string& scheme = url.scheme(); // already lowercase | 32 const std::string& scheme = url.scheme(); // already lowercase |
33 | 33 |
34 AutoLock locked(lock_); | 34 base::AutoLock locked(lock_); |
35 FactoryMap::const_iterator found = factories_.find(scheme); | 35 FactoryMap::const_iterator found = factories_.find(scheme); |
36 if (found != factories_.end()) { | 36 if (found != factories_.end()) { |
37 SocketStreamJob* job = found->second(url, delegate); | 37 SocketStreamJob* job = found->second(url, delegate); |
38 if (job) | 38 if (job) |
39 return job; | 39 return job; |
40 } | 40 } |
41 SocketStreamJob* job = new SocketStreamJob(); | 41 SocketStreamJob* job = new SocketStreamJob(); |
42 job->InitSocketStream(new SocketStream(url, delegate)); | 42 job->InitSocketStream(new SocketStream(url, delegate)); |
43 return job; | 43 return job; |
44 } | 44 } |
45 | 45 |
46 SocketStreamJob::ProtocolFactory* | 46 SocketStreamJob::ProtocolFactory* |
47 SocketStreamJobManager::RegisterProtocolFactory( | 47 SocketStreamJobManager::RegisterProtocolFactory( |
48 const std::string& scheme, SocketStreamJob::ProtocolFactory* factory) { | 48 const std::string& scheme, SocketStreamJob::ProtocolFactory* factory) { |
49 AutoLock locked(lock_); | 49 base::AutoLock locked(lock_); |
50 | 50 |
51 SocketStreamJob::ProtocolFactory* old_factory; | 51 SocketStreamJob::ProtocolFactory* old_factory; |
52 FactoryMap::iterator found = factories_.find(scheme); | 52 FactoryMap::iterator found = factories_.find(scheme); |
53 if (found != factories_.end()) { | 53 if (found != factories_.end()) { |
54 old_factory = found->second; | 54 old_factory = found->second; |
55 } else { | 55 } else { |
56 old_factory = NULL; | 56 old_factory = NULL; |
57 } | 57 } |
58 if (factory) { | 58 if (factory) { |
59 factories_[scheme] = factory; | 59 factories_[scheme] = factory; |
60 } else if (found != factories_.end()) { | 60 } else if (found != factories_.end()) { |
61 factories_.erase(found); | 61 factories_.erase(found); |
62 } | 62 } |
63 return old_factory; | 63 return old_factory; |
64 } | 64 } |
65 | 65 |
66 } // namespace net | 66 } // namespace net |
OLD | NEW |