| 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/browser_state/chrome_browser_state_io_data.h" | 5 #include "ios/chrome/browser/browser_state/chrome_browser_state_io_data.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 sync_disabled_.Init(sync_driver::prefs::kSyncManaged, pref_service); | 124 sync_disabled_.Init(sync_driver::prefs::kSyncManaged, pref_service); |
| 125 sync_disabled_.MoveToThread(io_task_runner); | 125 sync_disabled_.MoveToThread(io_task_runner); |
| 126 | 126 |
| 127 signin_allowed_.Init(prefs::kSigninAllowed, pref_service); | 127 signin_allowed_.Init(prefs::kSigninAllowed, pref_service); |
| 128 signin_allowed_.MoveToThread(io_task_runner); | 128 signin_allowed_.MoveToThread(io_task_runner); |
| 129 } | 129 } |
| 130 | 130 |
| 131 initialized_on_UI_thread_ = true; | 131 initialized_on_UI_thread_ = true; |
| 132 } | 132 } |
| 133 | 133 |
| 134 ChromeBrowserStateIOData::AppRequestContext::AppRequestContext() {} | |
| 135 | |
| 136 void ChromeBrowserStateIOData::AppRequestContext::SetCookieStore( | |
| 137 net::CookieStore* cookie_store) { | |
| 138 cookie_store_ = cookie_store; | |
| 139 set_cookie_store(cookie_store); | |
| 140 } | |
| 141 | |
| 142 void ChromeBrowserStateIOData::AppRequestContext::SetHttpTransactionFactory( | |
| 143 scoped_ptr<net::HttpTransactionFactory> http_factory) { | |
| 144 http_factory_ = std::move(http_factory); | |
| 145 set_http_transaction_factory(http_factory_.get()); | |
| 146 } | |
| 147 | |
| 148 void ChromeBrowserStateIOData::AppRequestContext::SetJobFactory( | |
| 149 scoped_ptr<net::URLRequestJobFactory> job_factory) { | |
| 150 job_factory_ = std::move(job_factory); | |
| 151 set_job_factory(job_factory_.get()); | |
| 152 } | |
| 153 | |
| 154 ChromeBrowserStateIOData::AppRequestContext::~AppRequestContext() { | |
| 155 AssertNoURLRequests(); | |
| 156 } | |
| 157 | |
| 158 ChromeBrowserStateIOData::ProfileParams::ProfileParams() | 134 ChromeBrowserStateIOData::ProfileParams::ProfileParams() |
| 159 : io_thread(nullptr), browser_state(nullptr) {} | 135 : io_thread(nullptr), browser_state(nullptr) {} |
| 160 | 136 |
| 161 ChromeBrowserStateIOData::ProfileParams::~ProfileParams() {} | 137 ChromeBrowserStateIOData::ProfileParams::~ProfileParams() {} |
| 162 | 138 |
| 163 ChromeBrowserStateIOData::ChromeBrowserStateIOData( | 139 ChromeBrowserStateIOData::ChromeBrowserStateIOData( |
| 164 ios::ChromeBrowserStateType browser_state_type) | 140 ios::ChromeBrowserStateType browser_state_type) |
| 165 : initialized_(false), | 141 : initialized_(false), |
| 166 initialized_on_UI_thread_(false), | 142 initialized_on_UI_thread_(false), |
| 167 browser_state_type_(browser_state_type) { | 143 browser_state_type_(browser_state_type) { |
| 168 DCHECK_CURRENTLY_ON(web::WebThread::UI); | 144 DCHECK_CURRENTLY_ON(web::WebThread::UI); |
| 169 } | 145 } |
| 170 | 146 |
| 171 ChromeBrowserStateIOData::~ChromeBrowserStateIOData() { | 147 ChromeBrowserStateIOData::~ChromeBrowserStateIOData() { |
| 172 if (web::WebThread::IsMessageLoopValid(web::WebThread::IO)) | 148 if (web::WebThread::IsMessageLoopValid(web::WebThread::IO)) |
| 173 DCHECK_CURRENTLY_ON(web::WebThread::IO); | 149 DCHECK_CURRENTLY_ON(web::WebThread::IO); |
| 174 | 150 |
| 175 // Pull the contents of the request context maps onto the stack for sanity | |
| 176 // checking of values in a minidump. http://crbug.com/260425 | |
| 177 size_t num_app_contexts = app_request_context_map_.size(); | |
| 178 size_t current_context = 0; | |
| 179 static const size_t kMaxCachedContexts = 20; | |
| 180 net::URLRequestContext* app_context_cache[kMaxCachedContexts] = {0}; | |
| 181 void* app_context_vtable_cache[kMaxCachedContexts] = {0}; | |
| 182 void* tmp_vtable = nullptr; | |
| 183 base::debug::Alias(&num_app_contexts); | |
| 184 base::debug::Alias(¤t_context); | |
| 185 base::debug::Alias(app_context_cache); | |
| 186 base::debug::Alias(app_context_vtable_cache); | |
| 187 base::debug::Alias(&tmp_vtable); | |
| 188 | |
| 189 current_context = 0; | |
| 190 for (URLRequestContextMap::const_iterator | |
| 191 it = app_request_context_map_.begin(); | |
| 192 current_context < kMaxCachedContexts && | |
| 193 it != app_request_context_map_.end(); | |
| 194 ++it, ++current_context) { | |
| 195 app_context_cache[current_context] = it->second; | |
| 196 memcpy(&app_context_vtable_cache[current_context], | |
| 197 static_cast<void*>(it->second), sizeof(void*)); | |
| 198 } | |
| 199 | |
| 200 // Destroy certificate_report_sender_ before main_request_context_, | 151 // Destroy certificate_report_sender_ before main_request_context_, |
| 201 // since the former has a reference to the latter. | 152 // since the former has a reference to the latter. |
| 202 if (transport_security_state_) | 153 if (transport_security_state_) |
| 203 transport_security_state_->SetReportSender(nullptr); | 154 transport_security_state_->SetReportSender(nullptr); |
| 204 certificate_report_sender_.reset(); | 155 certificate_report_sender_.reset(); |
| 205 | 156 |
| 206 // TODO(ajwong): These AssertNoURLRequests() calls are unnecessary since they | 157 // TODO(ajwong): These AssertNoURLRequests() calls are unnecessary since they |
| 207 // are already done in the URLRequestContext destructor. | 158 // are already done in the URLRequestContext destructor. |
| 208 if (main_request_context_) | 159 if (main_request_context_) |
| 209 main_request_context_->AssertNoURLRequests(); | 160 main_request_context_->AssertNoURLRequests(); |
| 210 | |
| 211 current_context = 0; | |
| 212 for (URLRequestContextMap::iterator it = app_request_context_map_.begin(); | |
| 213 it != app_request_context_map_.end(); ++it) { | |
| 214 if (current_context < kMaxCachedContexts) { | |
| 215 CHECK_EQ(app_context_cache[current_context], it->second); | |
| 216 memcpy(&tmp_vtable, static_cast<void*>(it->second), sizeof(void*)); | |
| 217 CHECK_EQ(app_context_vtable_cache[current_context], tmp_vtable); | |
| 218 } | |
| 219 it->second->AssertNoURLRequests(); | |
| 220 delete it->second; | |
| 221 current_context++; | |
| 222 } | |
| 223 } | 161 } |
| 224 | 162 |
| 225 // static | 163 // static |
| 226 bool ChromeBrowserStateIOData::IsHandledProtocol(const std::string& scheme) { | 164 bool ChromeBrowserStateIOData::IsHandledProtocol(const std::string& scheme) { |
| 227 DCHECK_EQ(scheme, base::ToLowerASCII(scheme)); | 165 DCHECK_EQ(scheme, base::ToLowerASCII(scheme)); |
| 228 static const char* const kProtocolList[] = { | 166 static const char* const kProtocolList[] = { |
| 229 url::kFileScheme, kChromeUIScheme, url::kDataScheme, url::kAboutScheme, | 167 url::kFileScheme, kChromeUIScheme, url::kDataScheme, url::kAboutScheme, |
| 230 }; | 168 }; |
| 231 for (size_t i = 0; i < arraysize(kProtocolList); ++i) { | 169 for (size_t i = 0; i < arraysize(kProtocolList); ++i) { |
| 232 if (scheme == kProtocolList[i]) | 170 if (scheme == kProtocolList[i]) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 247 } | 185 } |
| 248 protocol_handlers->clear(); | 186 protocol_handlers->clear(); |
| 249 } | 187 } |
| 250 | 188 |
| 251 net::URLRequestContext* ChromeBrowserStateIOData::GetMainRequestContext() | 189 net::URLRequestContext* ChromeBrowserStateIOData::GetMainRequestContext() |
| 252 const { | 190 const { |
| 253 DCHECK(initialized_); | 191 DCHECK(initialized_); |
| 254 return main_request_context_.get(); | 192 return main_request_context_.get(); |
| 255 } | 193 } |
| 256 | 194 |
| 257 net::URLRequestContext* ChromeBrowserStateIOData::GetIsolatedAppRequestContext( | |
| 258 net::URLRequestContext* main_context, | |
| 259 const base::FilePath& partition_path) const { | |
| 260 DCHECK(initialized_); | |
| 261 net::URLRequestContext* context = nullptr; | |
| 262 if (ContainsKey(app_request_context_map_, partition_path)) { | |
| 263 context = app_request_context_map_[partition_path]; | |
| 264 } else { | |
| 265 context = AcquireIsolatedAppRequestContext(main_context); | |
| 266 app_request_context_map_[partition_path] = context; | |
| 267 } | |
| 268 DCHECK(context); | |
| 269 return context; | |
| 270 } | |
| 271 | |
| 272 content_settings::CookieSettings* ChromeBrowserStateIOData::GetCookieSettings() | 195 content_settings::CookieSettings* ChromeBrowserStateIOData::GetCookieSettings() |
| 273 const { | 196 const { |
| 274 DCHECK(initialized_); | 197 DCHECK(initialized_); |
| 275 return cookie_settings_.get(); | 198 return cookie_settings_.get(); |
| 276 } | 199 } |
| 277 | 200 |
| 278 HostContentSettingsMap* ChromeBrowserStateIOData::GetHostContentSettingsMap() | 201 HostContentSettingsMap* ChromeBrowserStateIOData::GetHostContentSettingsMap() |
| 279 const { | 202 const { |
| 280 DCHECK(initialized_); | 203 DCHECK(initialized_); |
| 281 return host_content_settings_map_.get(); | 204 return host_content_settings_map_.get(); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 return scoped_ptr<net::HttpCache>( | 406 return scoped_ptr<net::HttpCache>( |
| 484 new net::HttpCache(session, std::move(main_backend), true)); | 407 new net::HttpCache(session, std::move(main_backend), true)); |
| 485 } | 408 } |
| 486 | 409 |
| 487 scoped_ptr<net::HttpCache> ChromeBrowserStateIOData::CreateHttpFactory( | 410 scoped_ptr<net::HttpCache> ChromeBrowserStateIOData::CreateHttpFactory( |
| 488 net::HttpNetworkSession* shared_session, | 411 net::HttpNetworkSession* shared_session, |
| 489 scoped_ptr<net::HttpCache::BackendFactory> backend) const { | 412 scoped_ptr<net::HttpCache::BackendFactory> backend) const { |
| 490 return scoped_ptr<net::HttpCache>( | 413 return scoped_ptr<net::HttpCache>( |
| 491 new net::HttpCache(shared_session, std::move(backend), true)); | 414 new net::HttpCache(shared_session, std::move(backend), true)); |
| 492 } | 415 } |
| OLD | NEW |