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) const { | 23 const GURL& url, SocketStream::Delegate* delegate, |
| 24 URLRequestContext* context, CookieStore* cookie_store) const { |
24 // If url is invalid, create plain SocketStreamJob, which will close | 25 // If url is invalid, create plain SocketStreamJob, which will close |
25 // the socket immediately. | 26 // the socket immediately. |
26 if (!url.is_valid()) { | 27 if (!url.is_valid()) { |
27 SocketStreamJob* job = new SocketStreamJob(); | 28 SocketStreamJob* job = new SocketStreamJob(); |
28 job->InitSocketStream(new SocketStream(url, delegate)); | 29 job->InitSocketStream(new SocketStream(url, delegate, context, |
| 30 cookie_store)); |
29 return job; | 31 return job; |
30 } | 32 } |
31 | 33 |
32 const std::string& scheme = url.scheme(); // already lowercase | 34 const std::string& scheme = url.scheme(); // already lowercase |
33 | 35 |
34 base::AutoLock locked(lock_); | 36 base::AutoLock locked(lock_); |
35 FactoryMap::const_iterator found = factories_.find(scheme); | 37 FactoryMap::const_iterator found = factories_.find(scheme); |
36 if (found != factories_.end()) { | 38 if (found != factories_.end()) { |
37 SocketStreamJob* job = found->second(url, delegate); | 39 SocketStreamJob* job = found->second(url, delegate, context, cookie_store); |
38 if (job) | 40 if (job) |
39 return job; | 41 return job; |
40 } | 42 } |
41 SocketStreamJob* job = new SocketStreamJob(); | 43 SocketStreamJob* job = new SocketStreamJob(); |
42 job->InitSocketStream(new SocketStream(url, delegate)); | 44 job->InitSocketStream(new SocketStream(url, delegate, context, cookie_store)); |
43 return job; | 45 return job; |
44 } | 46 } |
45 | 47 |
46 SocketStreamJob::ProtocolFactory* | 48 SocketStreamJob::ProtocolFactory* |
47 SocketStreamJobManager::RegisterProtocolFactory( | 49 SocketStreamJobManager::RegisterProtocolFactory( |
48 const std::string& scheme, SocketStreamJob::ProtocolFactory* factory) { | 50 const std::string& scheme, SocketStreamJob::ProtocolFactory* factory) { |
49 base::AutoLock locked(lock_); | 51 base::AutoLock locked(lock_); |
50 | 52 |
51 SocketStreamJob::ProtocolFactory* old_factory; | 53 SocketStreamJob::ProtocolFactory* old_factory; |
52 FactoryMap::iterator found = factories_.find(scheme); | 54 FactoryMap::iterator found = factories_.find(scheme); |
53 if (found != factories_.end()) { | 55 if (found != factories_.end()) { |
54 old_factory = found->second; | 56 old_factory = found->second; |
55 } else { | 57 } else { |
56 old_factory = NULL; | 58 old_factory = NULL; |
57 } | 59 } |
58 if (factory) { | 60 if (factory) { |
59 factories_[scheme] = factory; | 61 factories_[scheme] = factory; |
60 } else if (found != factories_.end()) { | 62 } else if (found != factories_.end()) { |
61 factories_.erase(found); | 63 factories_.erase(found); |
62 } | 64 } |
63 return old_factory; | 65 return old_factory; |
64 } | 66 } |
65 | 67 |
66 } // namespace net | 68 } // namespace net |
OLD | NEW |