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/socket_stream/socket_stream_job_manager.h" |
| 6 |
| 7 namespace net { |
| 8 |
| 9 SocketStreamJobManager::SocketStreamJobManager() { |
| 10 } |
| 11 |
| 12 SocketStreamJobManager::~SocketStreamJobManager() { |
| 13 } |
| 14 |
| 15 SocketStreamJob* SocketStreamJobManager::CreateJob( |
| 16 const GURL& url, SocketStream::Delegate* delegate) const { |
| 17 // If url is invalid, create plain SocketStreamJob, which will close |
| 18 // the socket immediately. |
| 19 if (!url.is_valid()) { |
| 20 SocketStreamJob* job = new SocketStreamJob(); |
| 21 job->InitSocketStream(new SocketStream(url, delegate)); |
| 22 return job; |
| 23 } |
| 24 |
| 25 const std::string& scheme = url.scheme(); // already lowercase |
| 26 |
| 27 AutoLock locked(lock_); |
| 28 FactoryMap::const_iterator found = factories_.find(scheme); |
| 29 if (found != factories_.end()) { |
| 30 SocketStreamJob* job = found->second(url, delegate); |
| 31 if (job) |
| 32 return job; |
| 33 } |
| 34 SocketStreamJob* job = new SocketStreamJob(); |
| 35 job->InitSocketStream(new SocketStream(url, delegate)); |
| 36 return job; |
| 37 } |
| 38 |
| 39 SocketStreamJob::ProtocolFactory* |
| 40 SocketStreamJobManager::RegisterProtocolFactory( |
| 41 const std::string& scheme, SocketStreamJob::ProtocolFactory* factory) { |
| 42 AutoLock locked(lock_); |
| 43 |
| 44 SocketStreamJob::ProtocolFactory* old_factory; |
| 45 FactoryMap::iterator found = factories_.find(scheme); |
| 46 if (found != factories_.end()) { |
| 47 old_factory = found->second; |
| 48 } else { |
| 49 old_factory = NULL; |
| 50 } |
| 51 if (factory) { |
| 52 factories_[scheme] = factory; |
| 53 } else if (found != factories_.end()) { |
| 54 factories_.erase(found); |
| 55 } |
| 56 return old_factory; |
| 57 } |
| 58 |
| 59 } // namespace net |
OLD | NEW |