OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/crnet/crnet_environment.h" | 5 #include "ios/crnet/crnet_environment.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
12 #include "base/atomicops.h" | 12 #include "base/atomicops.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/feature_list.h" |
14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
15 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
16 #include "base/files/scoped_file.h" | 17 #include "base/files/scoped_file.h" |
17 #include "base/i18n/icu_util.h" | 18 #include "base/i18n/icu_util.h" |
18 #include "base/json/json_writer.h" | 19 #include "base/json/json_writer.h" |
19 #include "base/mac/bind_objc_block.h" | 20 #include "base/mac/bind_objc_block.h" |
| 21 #include "base/mac/bundle_locations.h" |
20 #include "base/mac/foundation_util.h" | 22 #include "base/mac/foundation_util.h" |
21 #include "base/mac/scoped_block.h" | 23 #include "base/mac/scoped_block.h" |
22 #include "base/macros.h" | 24 #include "base/macros.h" |
23 #include "base/memory/ptr_util.h" | 25 #include "base/memory/ptr_util.h" |
24 #include "base/metrics/statistics_recorder.h" | 26 #include "base/metrics/statistics_recorder.h" |
25 #include "base/path_service.h" | 27 #include "base/path_service.h" |
26 #include "base/single_thread_task_runner.h" | 28 #include "base/single_thread_task_runner.h" |
27 #include "base/threading/worker_pool.h" | 29 #include "base/threading/worker_pool.h" |
28 #include "components/prefs/json_pref_store.h" | 30 #include "components/prefs/json_pref_store.h" |
29 #include "components/prefs/pref_filter.h" | 31 #include "components/prefs/pref_filter.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 const base::Closure& task) { | 147 const base::Closure& task) { |
146 file_user_blocking_thread_->message_loop()->PostTask(from_here, task); | 148 file_user_blocking_thread_->message_loop()->PostTask(from_here, task); |
147 } | 149 } |
148 | 150 |
149 // static | 151 // static |
150 void CrNetEnvironment::Initialize() { | 152 void CrNetEnvironment::Initialize() { |
151 DCHECK_EQ([NSThread currentThread], [NSThread mainThread]); | 153 DCHECK_EQ([NSThread currentThread], [NSThread mainThread]); |
152 if (!g_at_exit_) | 154 if (!g_at_exit_) |
153 g_at_exit_ = new base::AtExitManager; | 155 g_at_exit_ = new base::AtExitManager; |
154 | 156 |
| 157 // Change the framework bundle to the bundle that contain CrNet framework. |
| 158 // By default the framework bundle is set equal to the main (app) bundle. |
| 159 NSBundle* frameworkBundle = [NSBundle bundleForClass:CrNet.class]; |
| 160 base::mac::SetOverrideFrameworkBundle(frameworkBundle); |
155 #if !BUILDFLAG(USE_PLATFORM_ICU_ALTERNATIVES) | 161 #if !BUILDFLAG(USE_PLATFORM_ICU_ALTERNATIVES) |
156 CHECK(base::i18n::InitializeICU()); | 162 CHECK(base::i18n::InitializeICU()); |
157 #endif | 163 #endif |
158 url::Initialize(); | 164 url::Initialize(); |
159 base::CommandLine::Init(0, nullptr); | 165 base::CommandLine::Init(0, nullptr); |
160 | 166 |
161 // Without doing this, StatisticsRecorder::FactoryGet() leaks one histogram | 167 // Without doing this, StatisticsRecorder::FactoryGet() leaks one histogram |
162 // per call after the first for a given name. | 168 // per call after the first for a given name. |
163 base::StatisticsRecorder::Initialize(); | 169 base::StatisticsRecorder::Initialize(); |
164 | 170 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 net_pref_store_->ReadPrefsAsync(nullptr); | 351 net_pref_store_->ReadPrefsAsync(nullptr); |
346 sdch_owner_->EnablePersistentStorage( | 352 sdch_owner_->EnablePersistentStorage( |
347 std::unique_ptr<net::SdchOwner::PrefStorage>( | 353 std::unique_ptr<net::SdchOwner::PrefStorage>( |
348 new SdchOwnerPrefStorage(net_pref_store_.get()))); | 354 new SdchOwnerPrefStorage(net_pref_store_.get()))); |
349 } | 355 } |
350 context->set_sdch_manager(sdch_manager_.get()); | 356 context->set_sdch_manager(sdch_manager_.get()); |
351 } | 357 } |
352 | 358 |
353 void CrNetEnvironment::InitializeOnNetworkThread() { | 359 void CrNetEnvironment::InitializeOnNetworkThread() { |
354 DCHECK(network_io_thread_->task_runner()->BelongsToCurrentThread()); | 360 DCHECK(network_io_thread_->task_runner()->BelongsToCurrentThread()); |
| 361 base::FeatureList::InitializeInstance(std::string(), std::string()); |
355 | 362 |
356 ConfigureSdchOnNetworkThread(); | 363 ConfigureSdchOnNetworkThread(); |
357 | 364 |
| 365 // Use the framework bundle to search for resources. |
| 366 NSBundle* frameworkBundle = base::mac::FrameworkBundle(); |
358 NSString* bundlePath = | 367 NSString* bundlePath = |
359 [[NSBundle mainBundle] pathForResource:@"crnet_resources" | 368 [frameworkBundle pathForResource:@"crnet_resources" ofType:@"bundle"]; |
360 ofType:@"bundle"]; | |
361 NSBundle* bundle = [NSBundle bundleWithPath:bundlePath]; | 369 NSBundle* bundle = [NSBundle bundleWithPath:bundlePath]; |
362 NSString* acceptableLanguages = NSLocalizedStringWithDefaultValue( | 370 NSString* acceptableLanguages = NSLocalizedStringWithDefaultValue( |
363 @"IDS_ACCEPT_LANGUAGES", | 371 @"IDS_ACCEPT_LANGUAGES", |
364 @"Localizable", | 372 @"Localizable", |
365 bundle, | 373 bundle, |
366 @"en-US,en", | 374 @"en-US,en", |
367 @"These values are copied from Chrome's .xtb files, so the same " | 375 @"These values are copied from Chrome's .xtb files, so the same " |
368 "values are used in the |Accept-Language| header. Key name matches " | 376 "values are used in the |Accept-Language| header. Key name matches " |
369 "Chrome's."); | 377 "Chrome's."); |
370 if (acceptableLanguages == Nil) | 378 if (acceptableLanguages == Nil) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 cache_path = cache_path.Append(FILE_PATH_LITERAL("crnet")); | 423 cache_path = cache_path.Append(FILE_PATH_LITERAL("crnet")); |
416 std::unique_ptr<net::HttpCache::DefaultBackend> main_backend( | 424 std::unique_ptr<net::HttpCache::DefaultBackend> main_backend( |
417 new net::HttpCache::DefaultBackend(net::DISK_CACHE, | 425 new net::HttpCache::DefaultBackend(net::DISK_CACHE, |
418 net::CACHE_BACKEND_DEFAULT, cache_path, | 426 net::CACHE_BACKEND_DEFAULT, cache_path, |
419 0, // Default cache size. | 427 0, // Default cache size. |
420 network_cache_thread_->task_runner())); | 428 network_cache_thread_->task_runner())); |
421 | 429 |
422 net::HttpNetworkSession::Params params; | 430 net::HttpNetworkSession::Params params; |
423 params.host_resolver = main_context_->host_resolver(); | 431 params.host_resolver = main_context_->host_resolver(); |
424 params.cert_verifier = main_context_->cert_verifier(); | 432 params.cert_verifier = main_context_->cert_verifier(); |
| 433 params.cert_transparency_verifier = |
| 434 main_context_->cert_transparency_verifier(); |
| 435 params.ct_policy_enforcer = main_context_->ct_policy_enforcer(); |
425 params.channel_id_service = main_context_->channel_id_service(); | 436 params.channel_id_service = main_context_->channel_id_service(); |
426 params.transport_security_state = main_context_->transport_security_state(); | 437 params.transport_security_state = main_context_->transport_security_state(); |
427 params.proxy_service = main_context_->proxy_service(); | 438 params.proxy_service = main_context_->proxy_service(); |
428 params.ssl_config_service = main_context_->ssl_config_service(); | 439 params.ssl_config_service = main_context_->ssl_config_service(); |
429 params.http_auth_handler_factory = main_context_->http_auth_handler_factory(); | 440 params.http_auth_handler_factory = main_context_->http_auth_handler_factory(); |
430 params.http_server_properties = main_context_->http_server_properties(); | 441 params.http_server_properties = main_context_->http_server_properties(); |
431 params.net_log = main_context_->net_log(); | 442 params.net_log = main_context_->net_log(); |
432 params.enable_http2 = spdy_enabled(); | 443 params.enable_http2 = spdy_enabled(); |
433 params.enable_quic = quic_enabled(); | 444 params.enable_quic = quic_enabled(); |
434 | 445 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 | 490 |
480 return user_agent_settings->GetUserAgent(); | 491 return user_agent_settings->GetUserAgent(); |
481 } | 492 } |
482 | 493 |
483 void CrNetEnvironment::ClearCache(ClearCacheCallback callback) { | 494 void CrNetEnvironment::ClearCache(ClearCacheCallback callback) { |
484 PostToNetworkThread( | 495 PostToNetworkThread( |
485 FROM_HERE, | 496 FROM_HERE, |
486 base::Bind(&net::ClearHttpCache, main_context_getter_, | 497 base::Bind(&net::ClearHttpCache, main_context_getter_, |
487 network_io_thread_->task_runner(), base::BindBlock(callback))); | 498 network_io_thread_->task_runner(), base::BindBlock(callback))); |
488 } | 499 } |
OLD | NEW |