Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(741)

Side by Side Diff: components/cronet/ios/cronet_environment.mm

Issue 2639673002: Fix null TaskScheduler dereference introduced by codereview.chromium.org/2608093002 (Closed)
Patch Set: add call to `TaskScheduler::Shutdown()` Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/cronet/ios/cronet_environment.h" 5 #include "components/cronet/ios/cronet_environment.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/atomicops.h" 10 #include "base/atomicops.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/feature_list.h" 12 #include "base/feature_list.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/files/scoped_file.h" 15 #include "base/files/scoped_file.h"
16 #include "base/json/json_writer.h" 16 #include "base/json/json_writer.h"
17 #include "base/mac/bind_objc_block.h" 17 #include "base/mac/bind_objc_block.h"
18 #include "base/mac/foundation_util.h" 18 #include "base/mac/foundation_util.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/memory/ptr_util.h" 20 #include "base/memory/ptr_util.h"
21 #include "base/metrics/statistics_recorder.h" 21 #include "base/metrics/statistics_recorder.h"
22 #include "base/path_service.h" 22 #include "base/path_service.h"
23 #include "base/single_thread_task_runner.h" 23 #include "base/single_thread_task_runner.h"
24 #include "base/synchronization/waitable_event.h" 24 #include "base/synchronization/waitable_event.h"
25 #include "base/sys_info.h"
26 #include "base/task_scheduler/task_scheduler.h"
25 #include "base/threading/worker_pool.h" 27 #include "base/threading/worker_pool.h"
26 #include "components/cronet/histogram_manager.h" 28 #include "components/cronet/histogram_manager.h"
27 #include "components/cronet/ios/version.h" 29 #include "components/cronet/ios/version.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"
30 #include "ios/net/cookies/cookie_store_ios.h" 32 #include "ios/net/cookies/cookie_store_ios.h"
31 #include "ios/web/public/user_agent.h" 33 #include "ios/web/public/user_agent.h"
32 #include "net/base/network_change_notifier.h" 34 #include "net/base/network_change_notifier.h"
33 #include "net/cert/cert_verifier.h" 35 #include "net/cert/cert_verifier.h"
34 #include "net/dns/host_resolver.h" 36 #include "net/dns/host_resolver.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 return main_context_getter_.get(); 112 return main_context_getter_.get();
111 } 113 }
112 114
113 // static 115 // static
114 void CronetEnvironment::Initialize() { 116 void CronetEnvironment::Initialize() {
115 // DCHECK_EQ([NSThread currentThread], [NSThread mainThread]); 117 // DCHECK_EQ([NSThread currentThread], [NSThread mainThread]);
116 // This method must be called once from the main thread. 118 // This method must be called once from the main thread.
117 if (!g_at_exit_) 119 if (!g_at_exit_)
118 g_at_exit_ = new base::AtExitManager; 120 g_at_exit_ = new base::AtExitManager;
119 121
122 base::TaskScheduler::CreateAndSetSimpleTaskScheduler(
123 base::SysInfo::NumberOfProcessors());
124
120 url::Initialize(); 125 url::Initialize();
121 base::CommandLine::Init(0, nullptr); 126 base::CommandLine::Init(0, nullptr);
122 127
123 // Without doing this, StatisticsRecorder::FactoryGet() leaks one histogram 128 // Without doing this, StatisticsRecorder::FactoryGet() leaks one histogram
124 // per call after the first for a given name. 129 // per call after the first for a given name.
125 base::StatisticsRecorder::Initialize(); 130 base::StatisticsRecorder::Initialize();
126 131
127 // Create a message loop on the UI thread. 132 // Create a message loop on the UI thread.
128 DCHECK(!base::MessageLoop::current()); 133 DCHECK(!base::MessageLoop::current());
129 DCHECK(!g_main_message_loop); 134 DCHECK(!g_main_message_loop);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 main_context_getter_ = new CronetURLRequestContextGetter( 244 main_context_getter_ = new CronetURLRequestContextGetter(
240 this, network_io_thread_->task_runner()); 245 this, network_io_thread_->task_runner());
241 base::subtle::MemoryBarrier(); 246 base::subtle::MemoryBarrier();
242 PostToNetworkThread(FROM_HERE, 247 PostToNetworkThread(FROM_HERE,
243 base::Bind(&CronetEnvironment::InitializeOnNetworkThread, 248 base::Bind(&CronetEnvironment::InitializeOnNetworkThread,
244 base::Unretained(this))); 249 base::Unretained(this)));
245 } 250 }
246 251
247 CronetEnvironment::~CronetEnvironment() { 252 CronetEnvironment::~CronetEnvironment() {
248 // net::HTTPProtocolHandlerDelegate::SetInstance(nullptr); 253 // net::HTTPProtocolHandlerDelegate::SetInstance(nullptr);
254
255 // TODO(lilyhoughton) right now this is relying on there being
256 // only one CronetEnvironment (per process). if (when?) that
257 // changes, so will this have to.
258 base::TaskScheduler* ts = base::TaskScheduler::GetInstance();
259 if (ts)
260 ts->Shutdown();
249 } 261 }
250 262
251 void CronetEnvironment::InitializeOnNetworkThread() { 263 void CronetEnvironment::InitializeOnNetworkThread() {
252 DCHECK(network_io_thread_->task_runner()->BelongsToCurrentThread()); 264 DCHECK(network_io_thread_->task_runner()->BelongsToCurrentThread());
253 base::FeatureList::InitializeInstance(std::string(), std::string()); 265 base::FeatureList::InitializeInstance(std::string(), std::string());
254 266
255 static bool ssl_key_log_file_set = false; 267 static bool ssl_key_log_file_set = false;
256 if (!ssl_key_log_file_set && !ssl_key_log_file_name_.empty()) { 268 if (!ssl_key_log_file_set && !ssl_key_log_file_name_.empty()) {
257 ssl_key_log_file_set = true; 269 ssl_key_log_file_set = true;
258 base::FilePath ssl_key_log_file; 270 base::FilePath ssl_key_log_file;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 event->Signal(); 370 event->Signal();
359 } 371 }
360 372
361 std::string CronetEnvironment::getDefaultQuicUserAgentId() const { 373 std::string CronetEnvironment::getDefaultQuicUserAgentId() const {
362 return base::SysNSStringToUTF8([[NSBundle mainBundle] 374 return base::SysNSStringToUTF8([[NSBundle mainBundle]
363 objectForInfoDictionaryKey:@"CFBundleDisplayName"]) + 375 objectForInfoDictionaryKey:@"CFBundleDisplayName"]) +
364 " Cronet/" + CRONET_VERSION; 376 " Cronet/" + CRONET_VERSION;
365 } 377 }
366 378
367 } // namespace cronet 379 } // namespace cronet
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698