OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ios/chrome/browser/net/ios_chrome_url_request_context_getter.h" | 5 #include "ios/chrome/browser/net/ios_chrome_url_request_context_getter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 net::URLRequestContext* Create() override { | 43 net::URLRequestContext* Create() override { |
44 io_data_->Init(&protocol_handlers_); | 44 io_data_->Init(&protocol_handlers_); |
45 return io_data_->GetMainRequestContext(); | 45 return io_data_->GetMainRequestContext(); |
46 } | 46 } |
47 | 47 |
48 private: | 48 private: |
49 const ChromeBrowserStateIOData* const io_data_; | 49 const ChromeBrowserStateIOData* const io_data_; |
50 ProtocolHandlerMap protocol_handlers_; | 50 ProtocolHandlerMap protocol_handlers_; |
51 }; | 51 }; |
52 | 52 |
53 // Factory that creates the URLRequestContext for a given isolated app. | |
54 class FactoryForIsolatedApp : public IOSChromeURLRequestContextFactory { | |
55 public: | |
56 FactoryForIsolatedApp(const ChromeBrowserStateIOData* io_data, | |
57 const base::FilePath& partition_path, | |
58 net::URLRequestContextGetter* main_context) | |
59 : io_data_(io_data), | |
60 partition_path_(partition_path), | |
61 main_request_context_getter_(main_context) {} | |
62 | |
63 net::URLRequestContext* Create() override { | |
64 // We will copy most of the state from the main request context. | |
65 // | |
66 // Note that this factory is one-shot. After Create() is called once, the | |
67 // factory is actually destroyed. Thus it is safe to destructively pass | |
68 // state onwards. | |
69 return io_data_->GetIsolatedAppRequestContext( | |
70 main_request_context_getter_->GetURLRequestContext(), partition_path_); | |
71 } | |
72 | |
73 private: | |
74 const ChromeBrowserStateIOData* const io_data_; | |
75 const base::FilePath partition_path_; | |
76 scoped_refptr<net::URLRequestContextGetter> main_request_context_getter_; | |
77 }; | |
78 | |
79 } // namespace | 53 } // namespace |
80 | 54 |
81 // ---------------------------------------------------------------------------- | 55 // ---------------------------------------------------------------------------- |
82 // IOSChromeURLRequestContextGetter | 56 // IOSChromeURLRequestContextGetter |
83 // ---------------------------------------------------------------------------- | 57 // ---------------------------------------------------------------------------- |
84 | 58 |
85 IOSChromeURLRequestContextGetter::IOSChromeURLRequestContextGetter( | 59 IOSChromeURLRequestContextGetter::IOSChromeURLRequestContextGetter( |
86 scoped_ptr<IOSChromeURLRequestContextFactory> factory) | 60 scoped_ptr<IOSChromeURLRequestContextFactory> factory) |
87 : factory_(std::move(factory)), url_request_context_(nullptr) { | 61 : factory_(std::move(factory)), url_request_context_(nullptr) { |
88 DCHECK(factory_); | 62 DCHECK(factory_); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 return web::WebThread::GetTaskRunnerForThread(web::WebThread::IO); | 95 return web::WebThread::GetTaskRunnerForThread(web::WebThread::IO); |
122 } | 96 } |
123 | 97 |
124 // static | 98 // static |
125 IOSChromeURLRequestContextGetter* IOSChromeURLRequestContextGetter::Create( | 99 IOSChromeURLRequestContextGetter* IOSChromeURLRequestContextGetter::Create( |
126 const ChromeBrowserStateIOData* io_data, | 100 const ChromeBrowserStateIOData* io_data, |
127 ProtocolHandlerMap* protocol_handlers) { | 101 ProtocolHandlerMap* protocol_handlers) { |
128 return new IOSChromeURLRequestContextGetter( | 102 return new IOSChromeURLRequestContextGetter( |
129 make_scoped_ptr(new FactoryForMain(io_data, protocol_handlers))); | 103 make_scoped_ptr(new FactoryForMain(io_data, protocol_handlers))); |
130 } | 104 } |
131 | |
132 // static | |
133 IOSChromeURLRequestContextGetter* | |
134 IOSChromeURLRequestContextGetter::CreateForIsolatedApp( | |
135 net::URLRequestContextGetter* main_context, | |
136 const ChromeBrowserStateIOData* io_data, | |
137 const base::FilePath& partition_path) { | |
138 return new IOSChromeURLRequestContextGetter(make_scoped_ptr( | |
139 new FactoryForIsolatedApp(io_data, partition_path, main_context))); | |
140 } | |
OLD | NEW |