| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/io_thread.h" | 5 #include "chrome/browser/io_thread.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 } | 257 } |
| 258 return value; | 258 return value; |
| 259 } | 259 } |
| 260 | 260 |
| 261 // This function is for forwarding metrics usage pref changes to the metrics | 261 // This function is for forwarding metrics usage pref changes to the metrics |
| 262 // service on the appropriate thread. | 262 // service on the appropriate thread. |
| 263 // TODO(gayane): Reduce the frequency of posting tasks from IO to UI thread. | 263 // TODO(gayane): Reduce the frequency of posting tasks from IO to UI thread. |
| 264 void UpdateMetricsUsagePrefsOnUIThread(const std::string& service_name, | 264 void UpdateMetricsUsagePrefsOnUIThread(const std::string& service_name, |
| 265 int message_size, | 265 int message_size, |
| 266 bool is_cellular) { | 266 bool is_cellular) { |
| 267 BrowserThread::PostTask( | 267 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 268 BrowserThread::UI, | 268 base::BindOnce( |
| 269 FROM_HERE, | 269 [](const std::string& service_name, |
| 270 base::Bind([](const std::string& service_name, | 270 int message_size, bool is_cellular) { |
| 271 int message_size, | 271 // Some unit tests use IOThread but do not |
| 272 bool is_cellular) { | 272 // initialize MetricsService. In that case it's |
| 273 // Some unit tests use IOThread but do not initialize | 273 // fine to skip the update. |
| 274 // MetricsService. In that case it's fine to skip the update. | 274 auto* metrics_service = |
| 275 auto* metrics_service = g_browser_process->metrics_service(); | 275 g_browser_process->metrics_service(); |
| 276 if (metrics_service) { | 276 if (metrics_service) { |
| 277 metrics_service->UpdateMetricsUsagePrefs(service_name, | 277 metrics_service->UpdateMetricsUsagePrefs( |
| 278 message_size, | 278 service_name, message_size, is_cellular); |
| 279 is_cellular); | 279 } |
| 280 } | 280 }, |
| 281 }, | 281 service_name, message_size, is_cellular)); |
| 282 service_name, | |
| 283 message_size, | |
| 284 is_cellular)); | |
| 285 } | 282 } |
| 286 | 283 |
| 287 } // namespace | 284 } // namespace |
| 288 | 285 |
| 289 class SystemURLRequestContextGetter : public net::URLRequestContextGetter { | 286 class SystemURLRequestContextGetter : public net::URLRequestContextGetter { |
| 290 public: | 287 public: |
| 291 explicit SystemURLRequestContextGetter(IOThread* io_thread); | 288 explicit SystemURLRequestContextGetter(IOThread* io_thread); |
| 292 | 289 |
| 293 // Implementation for net::UrlRequestContextGetter. | 290 // Implementation for net::UrlRequestContextGetter. |
| 294 net::URLRequestContext* GetURLRequestContext() override; | 291 net::URLRequestContext* GetURLRequestContext() override; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 globals_ = globals; | 465 globals_ = globals; |
| 469 } | 466 } |
| 470 | 467 |
| 471 net_log::ChromeNetLog* IOThread::net_log() { | 468 net_log::ChromeNetLog* IOThread::net_log() { |
| 472 return net_log_; | 469 return net_log_; |
| 473 } | 470 } |
| 474 | 471 |
| 475 void IOThread::ChangedToOnTheRecord() { | 472 void IOThread::ChangedToOnTheRecord() { |
| 476 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 473 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 477 BrowserThread::PostTask( | 474 BrowserThread::PostTask( |
| 478 BrowserThread::IO, | 475 BrowserThread::IO, FROM_HERE, |
| 479 FROM_HERE, | 476 base::BindOnce(&IOThread::ChangedToOnTheRecordOnIOThread, |
| 480 base::Bind(&IOThread::ChangedToOnTheRecordOnIOThread, | 477 base::Unretained(this))); |
| 481 base::Unretained(this))); | |
| 482 } | 478 } |
| 483 | 479 |
| 484 net::URLRequestContextGetter* IOThread::system_url_request_context_getter() { | 480 net::URLRequestContextGetter* IOThread::system_url_request_context_getter() { |
| 485 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 481 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 486 if (!system_url_request_context_getter_.get()) { | 482 if (!system_url_request_context_getter_.get()) { |
| 487 InitSystemRequestContext(); | 483 InitSystemRequestContext(); |
| 488 } | 484 } |
| 489 return system_url_request_context_getter_.get(); | 485 return system_url_request_context_getter_.get(); |
| 490 } | 486 } |
| 491 | 487 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 // InitSystemRequestContext turns right around and posts a task back | 664 // InitSystemRequestContext turns right around and posts a task back |
| 669 // to the IO thread, so we can't let it run until we know the IO | 665 // to the IO thread, so we can't let it run until we know the IO |
| 670 // thread has started. | 666 // thread has started. |
| 671 // | 667 // |
| 672 // Note that since we are at BrowserThread::Init time, the UI thread | 668 // Note that since we are at BrowserThread::Init time, the UI thread |
| 673 // is blocked waiting for the thread to start. Therefore, posting | 669 // is blocked waiting for the thread to start. Therefore, posting |
| 674 // this task to the main thread's message loop here is guaranteed to | 670 // this task to the main thread's message loop here is guaranteed to |
| 675 // get it onto the message loop while the IOThread object still | 671 // get it onto the message loop while the IOThread object still |
| 676 // exists. However, the message might not be processed on the UI | 672 // exists. However, the message might not be processed on the UI |
| 677 // thread until after IOThread is gone, so use a weak pointer. | 673 // thread until after IOThread is gone, so use a weak pointer. |
| 678 BrowserThread::PostTask(BrowserThread::UI, | 674 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 679 FROM_HERE, | 675 base::BindOnce(&IOThread::InitSystemRequestContext, |
| 680 base::Bind(&IOThread::InitSystemRequestContext, | 676 weak_factory_.GetWeakPtr())); |
| 681 weak_factory_.GetWeakPtr())); | |
| 682 | 677 |
| 683 #if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL) | 678 #if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL) |
| 684 // Record how common CPUs with broken NEON units are. See | 679 // Record how common CPUs with broken NEON units are. See |
| 685 // https://crbug.com/341598. | 680 // https://crbug.com/341598. |
| 686 crypto::EnsureOpenSSLInit(); | 681 crypto::EnsureOpenSSLInit(); |
| 687 UMA_HISTOGRAM_BOOLEAN("Net.HasBrokenNEON", CRYPTO_has_broken_NEON()); | 682 UMA_HISTOGRAM_BOOLEAN("Net.HasBrokenNEON", CRYPTO_has_broken_NEON()); |
| 688 #endif | 683 #endif |
| 689 } | 684 } |
| 690 | 685 |
| 691 void IOThread::CleanUp() { | 686 void IOThread::CleanUp() { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 // If we're in unit_tests, IOThread may not be run. | 833 // If we're in unit_tests, IOThread may not be run. |
| 839 if (!BrowserThread::IsMessageLoopValid(BrowserThread::IO)) | 834 if (!BrowserThread::IsMessageLoopValid(BrowserThread::IO)) |
| 840 return; | 835 return; |
| 841 system_proxy_config_service_ = ProxyServiceFactory::CreateProxyConfigService( | 836 system_proxy_config_service_ = ProxyServiceFactory::CreateProxyConfigService( |
| 842 pref_proxy_config_tracker_.get()); | 837 pref_proxy_config_tracker_.get()); |
| 843 system_url_request_context_getter_ = | 838 system_url_request_context_getter_ = |
| 844 new SystemURLRequestContextGetter(this); | 839 new SystemURLRequestContextGetter(this); |
| 845 // Safe to post an unretained this pointer, since IOThread is | 840 // Safe to post an unretained this pointer, since IOThread is |
| 846 // guaranteed to outlive the IO BrowserThread. | 841 // guaranteed to outlive the IO BrowserThread. |
| 847 BrowserThread::PostTask( | 842 BrowserThread::PostTask( |
| 848 BrowserThread::IO, | 843 BrowserThread::IO, FROM_HERE, |
| 849 FROM_HERE, | 844 base::BindOnce(&IOThread::InitSystemRequestContextOnIOThread, |
| 850 base::Bind(&IOThread::InitSystemRequestContextOnIOThread, | 845 base::Unretained(this))); |
| 851 base::Unretained(this))); | |
| 852 } | 846 } |
| 853 | 847 |
| 854 void IOThread::InitSystemRequestContextOnIOThread() { | 848 void IOThread::InitSystemRequestContextOnIOThread() { |
| 855 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 849 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 856 DCHECK(!globals_->system_proxy_service.get()); | 850 DCHECK(!globals_->system_proxy_service.get()); |
| 857 DCHECK(system_proxy_config_service_.get()); | 851 DCHECK(system_proxy_config_service_.get()); |
| 858 | 852 |
| 859 const base::CommandLine& command_line = | 853 const base::CommandLine& command_line = |
| 860 *base::CommandLine::ForCurrentProcess(); | 854 *base::CommandLine::ForCurrentProcess(); |
| 861 globals_->system_proxy_service = ProxyServiceFactory::CreateProxyService( | 855 globals_->system_proxy_service = ProxyServiceFactory::CreateProxyService( |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1102 | 1096 |
| 1103 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the | 1097 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the |
| 1104 // system URLRequestContext too. There's no reason this should be tied to a | 1098 // system URLRequestContext too. There's no reason this should be tied to a |
| 1105 // profile. | 1099 // profile. |
| 1106 return context; | 1100 return context; |
| 1107 } | 1101 } |
| 1108 | 1102 |
| 1109 metrics::UpdateUsagePrefCallbackType IOThread::GetMetricsDataUseForwarder() { | 1103 metrics::UpdateUsagePrefCallbackType IOThread::GetMetricsDataUseForwarder() { |
| 1110 return base::Bind(&UpdateMetricsUsagePrefsOnUIThread); | 1104 return base::Bind(&UpdateMetricsUsagePrefsOnUIThread); |
| 1111 } | 1105 } |
| OLD | NEW |