| 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/renderer/chrome_render_process_observer.h" | 5 #include "chrome/renderer/chrome_render_process_observer.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/allocator/allocator_extension.h" | 10 #include "base/allocator/allocator_extension.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/location.h" |
| 14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 15 #include "base/message_loop/message_loop.h" | |
| 16 #include "base/metrics/field_trial.h" | 16 #include "base/metrics/field_trial.h" |
| 17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 18 #include "base/metrics/statistics_recorder.h" | 18 #include "base/metrics/statistics_recorder.h" |
| 19 #include "base/native_library.h" | 19 #include "base/native_library.h" |
| 20 #include "base/path_service.h" | 20 #include "base/path_service.h" |
| 21 #include "base/single_thread_task_runner.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/thread_task_runner_handle.h" |
| 22 #include "base/threading/platform_thread.h" | 24 #include "base/threading/platform_thread.h" |
| 23 #include "chrome/common/child_process_logging.h" | 25 #include "chrome/common/child_process_logging.h" |
| 24 #include "chrome/common/chrome_paths.h" | 26 #include "chrome/common/chrome_paths.h" |
| 25 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/net/net_resource_provider.h" | 28 #include "chrome/common/net/net_resource_provider.h" |
| 27 #include "chrome/common/render_messages.h" | 29 #include "chrome/common/render_messages.h" |
| 28 #include "chrome/common/resource_usage_reporter.mojom.h" | 30 #include "chrome/common/resource_usage_reporter.mojom.h" |
| 29 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
| 30 #include "chrome/common/variations/variations_util.h" | 32 #include "chrome/common/variations/variations_util.h" |
| 31 #include "chrome/renderer/content_settings_observer.h" | 33 #include "chrome/renderer/content_settings_observer.h" |
| 32 #include "chrome/renderer/security_filter_peer.h" | 34 #include "chrome/renderer/security_filter_peer.h" |
| 33 #include "content/public/child/resource_dispatcher_delegate.h" | 35 #include "content/public/child/resource_dispatcher_delegate.h" |
| 34 #include "content/public/common/service_registry.h" | 36 #include "content/public/common/service_registry.h" |
| 35 #include "content/public/renderer/render_thread.h" | 37 #include "content/public/renderer/render_thread.h" |
| 36 #include "content/public/renderer/render_view.h" | 38 #include "content/public/renderer/render_view.h" |
| 37 #include "content/public/renderer/render_view_visitor.h" | 39 #include "content/public/renderer/render_view_visitor.h" |
| 38 #include "crypto/nss_util.h" | 40 #include "crypto/nss_util.h" |
| 39 #include "net/base/net_errors.h" | 41 #include "net/base/net_errors.h" |
| 40 #include "net/base/net_module.h" | 42 #include "net/base/net_module.h" |
| 41 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" | |
| 42 #include "third_party/WebKit/public/web/WebCache.h" | 43 #include "third_party/WebKit/public/web/WebCache.h" |
| 43 #include "third_party/WebKit/public/web/WebDocument.h" | 44 #include "third_party/WebKit/public/web/WebDocument.h" |
| 44 #include "third_party/WebKit/public/web/WebFrame.h" | 45 #include "third_party/WebKit/public/web/WebFrame.h" |
| 45 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 46 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 46 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 47 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
| 47 #include "third_party/WebKit/public/web/WebView.h" | 48 #include "third_party/WebKit/public/web/WebView.h" |
| 49 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" |
| 48 | 50 |
| 49 #if defined(ENABLE_EXTENSIONS) | 51 #if defined(ENABLE_EXTENSIONS) |
| 50 #include "chrome/renderer/extensions/extension_localization_peer.h" | 52 #include "chrome/renderer/extensions/extension_localization_peer.h" |
| 51 #endif | 53 #endif |
| 52 | 54 |
| 53 using blink::WebCache; | 55 using blink::WebCache; |
| 54 using blink::WebRuntimeFeatures; | 56 using blink::WebRuntimeFeatures; |
| 55 using blink::WebSecurityPolicy; | 57 using blink::WebSecurityPolicy; |
| 56 using blink::WebString; | 58 using blink::WebString; |
| 57 using content::RenderThread; | 59 using content::RenderThread; |
| 58 | 60 |
| 59 namespace { | 61 namespace { |
| 60 | 62 |
| 61 const int kCacheStatsDelayMS = 2000; | 63 const int kCacheStatsDelayMS = 2000; |
| 62 | 64 |
| 63 class RendererResourceDelegate : public content::ResourceDispatcherDelegate { | 65 class RendererResourceDelegate : public content::ResourceDispatcherDelegate { |
| 64 public: | 66 public: |
| 65 RendererResourceDelegate() | 67 RendererResourceDelegate() |
| 66 : weak_factory_(this) { | 68 : weak_factory_(this) { |
| 67 } | 69 } |
| 68 | 70 |
| 69 content::RequestPeer* OnRequestComplete(content::RequestPeer* current_peer, | 71 content::RequestPeer* OnRequestComplete(content::RequestPeer* current_peer, |
| 70 content::ResourceType resource_type, | 72 content::ResourceType resource_type, |
| 71 int error_code) override { | 73 int error_code) override { |
| 72 // Update the browser about our cache. | 74 // Update the browser about our cache. |
| 73 // Rate limit informing the host of our cache stats. | 75 // Rate limit informing the host of our cache stats. |
| 74 if (!weak_factory_.HasWeakPtrs()) { | 76 if (!weak_factory_.HasWeakPtrs()) { |
| 75 base::MessageLoop::current()->PostDelayedTask( | 77 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 76 FROM_HERE, | 78 FROM_HERE, |
| 77 base::Bind(&RendererResourceDelegate::InformHostOfCacheStats, | 79 base::Bind(&RendererResourceDelegate::InformHostOfCacheStats, |
| 78 weak_factory_.GetWeakPtr()), | 80 weak_factory_.GetWeakPtr()), |
| 79 base::TimeDelta::FromMilliseconds(kCacheStatsDelayMS)); | 81 base::TimeDelta::FromMilliseconds(kCacheStatsDelayMS)); |
| 80 } | 82 } |
| 81 | 83 |
| 82 if (error_code == net::ERR_ABORTED) { | 84 if (error_code == net::ERR_ABORTED) { |
| 83 return NULL; | 85 return NULL; |
| 84 } | 86 } |
| 85 | 87 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 usage_data_ = ResourceUsageData::New(); | 163 usage_data_ = ResourceUsageData::New(); |
| 162 usage_data_->reports_v8_stats = true; | 164 usage_data_->reports_v8_stats = true; |
| 163 callback_ = callback; | 165 callback_ = callback; |
| 164 | 166 |
| 165 v8::HeapStatistics heap_stats; | 167 v8::HeapStatistics heap_stats; |
| 166 v8::Isolate::GetCurrent()->GetHeapStatistics(&heap_stats); | 168 v8::Isolate::GetCurrent()->GetHeapStatistics(&heap_stats); |
| 167 usage_data_->v8_bytes_allocated = heap_stats.total_heap_size(); | 169 usage_data_->v8_bytes_allocated = heap_stats.total_heap_size(); |
| 168 usage_data_->v8_bytes_used = heap_stats.used_heap_size(); | 170 usage_data_->v8_bytes_used = heap_stats.used_heap_size(); |
| 169 base::Closure collect = base::Bind( | 171 base::Closure collect = base::Bind( |
| 170 &ResourceUsageReporterImpl::CollectOnWorkerThread, | 172 &ResourceUsageReporterImpl::CollectOnWorkerThread, |
| 171 base::MessageLoopProxy::current(), weak_factory_.GetWeakPtr()); | 173 base::ThreadTaskRunnerHandle::Get(), weak_factory_.GetWeakPtr()); |
| 172 workers_to_go_ = RenderThread::Get()->PostTaskToAllWebWorkers(collect); | 174 workers_to_go_ = RenderThread::Get()->PostTaskToAllWebWorkers(collect); |
| 173 if (workers_to_go_) { | 175 if (workers_to_go_) { |
| 174 // The guard task to send out partial stats | 176 // The guard task to send out partial stats |
| 175 // in case some workers are not responsive. | 177 // in case some workers are not responsive. |
| 176 base::MessageLoopProxy::current()->PostDelayedTask( | 178 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 177 FROM_HERE, base::Bind(&ResourceUsageReporterImpl::SendResults, | 179 FROM_HERE, base::Bind(&ResourceUsageReporterImpl::SendResults, |
| 178 weak_factory_.GetWeakPtr()), | 180 weak_factory_.GetWeakPtr()), |
| 179 base::TimeDelta::FromMilliseconds(kWaitForWorkersStatsTimeoutMS)); | 181 base::TimeDelta::FromMilliseconds(kWaitForWorkersStatsTimeoutMS)); |
| 180 } else { | 182 } else { |
| 181 // No worker threads so just send out the main thread data right away. | 183 // No worker threads so just send out the main thread data right away. |
| 182 SendResults(); | 184 SendResults(); |
| 183 } | 185 } |
| 184 } | 186 } |
| 185 | 187 |
| 186 ResourceUsageDataPtr usage_data_; | 188 ResourceUsageDataPtr usage_data_; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 ChromeRenderProcessObserver::content_setting_rules() const { | 324 ChromeRenderProcessObserver::content_setting_rules() const { |
| 323 return &content_setting_rules_; | 325 return &content_setting_rules_; |
| 324 } | 326 } |
| 325 | 327 |
| 326 void ChromeRenderProcessObserver::OnFieldTrialGroupFinalized( | 328 void ChromeRenderProcessObserver::OnFieldTrialGroupFinalized( |
| 327 const std::string& trial_name, | 329 const std::string& trial_name, |
| 328 const std::string& group_name) { | 330 const std::string& group_name) { |
| 329 content::RenderThread::Get()->Send( | 331 content::RenderThread::Get()->Send( |
| 330 new ChromeViewHostMsg_FieldTrialActivated(trial_name)); | 332 new ChromeViewHostMsg_FieldTrialActivated(trial_name)); |
| 331 } | 333 } |
| OLD | NEW |