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 "content/renderer/render_thread_impl.h" | 5 #include "content/renderer/render_thread_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 return true; | 152 return true; |
153 } | 153 } |
154 | 154 |
155 private: | 155 private: |
156 std::string host_; | 156 std::string host_; |
157 double zoom_level_; | 157 double zoom_level_; |
158 | 158 |
159 DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer); | 159 DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer); |
160 }; | 160 }; |
161 | 161 |
162 } // namespace | 162 std::string HostToCustomHistogramSuffix(const std::string& host) { |
| 163 if (host == "mail.google.com") |
| 164 return ".gmail"; |
| 165 if (host == "docs.google.com" || host == "drive.google.com") |
| 166 return ".docs"; |
| 167 if (host == "plus.google.com") |
| 168 return ".plus"; |
| 169 return ""; |
| 170 } |
163 | 171 |
164 static void* CreateHistogram( | 172 void* CreateHistogram( |
165 const char *name, int min, int max, size_t buckets) { | 173 const char *name, int min, int max, size_t buckets) { |
166 if (min <= 0) | 174 if (min <= 0) |
167 min = 1; | 175 min = 1; |
| 176 std::string histogram_name; |
| 177 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current(); |
| 178 if (render_thread_impl) { // Can be null in tests. |
| 179 histogram_name = render_thread_impl-> |
| 180 histogram_customizer()->ConvertToCustomHistogramName(name); |
| 181 } else { |
| 182 histogram_name = std::string(name); |
| 183 } |
168 base::Histogram* histogram = base::Histogram::FactoryGet( | 184 base::Histogram* histogram = base::Histogram::FactoryGet( |
169 name, min, max, buckets, base::Histogram::kUmaTargetedHistogramFlag); | 185 histogram_name, min, max, buckets, |
| 186 base::Histogram::kUmaTargetedHistogramFlag); |
170 return histogram; | 187 return histogram; |
171 } | 188 } |
172 | 189 |
173 static void AddHistogramSample(void* hist, int sample) { | 190 void AddHistogramSample(void* hist, int sample) { |
174 base::Histogram* histogram = static_cast<base::Histogram*>(hist); | 191 base::Histogram* histogram = static_cast<base::Histogram*>(hist); |
175 histogram->Add(sample); | 192 histogram->Add(sample); |
176 } | 193 } |
177 | 194 |
| 195 } // namespace |
| 196 |
178 class RenderThreadImpl::GpuVDAContextLostCallback | 197 class RenderThreadImpl::GpuVDAContextLostCallback |
179 : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { | 198 : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { |
180 public: | 199 public: |
181 GpuVDAContextLostCallback() {} | 200 GpuVDAContextLostCallback() {} |
182 virtual ~GpuVDAContextLostCallback() {} | 201 virtual ~GpuVDAContextLostCallback() {} |
183 virtual void onContextLost() { | 202 virtual void onContextLost() { |
184 ChildThread::current()->message_loop()->PostTask(FROM_HERE, base::Bind( | 203 ChildThread::current()->message_loop()->PostTask(FROM_HERE, base::Bind( |
185 &RenderThreadImpl::OnGpuVDAContextLoss)); | 204 &RenderThreadImpl::OnGpuVDAContextLoss)); |
186 } | 205 } |
187 }; | 206 }; |
188 | 207 |
| 208 RenderThreadImpl::HistogramCustomizer::HistogramCustomizer() { |
| 209 custom_histograms_.insert("V8.MemoryExternalFragmentationTotal"); |
| 210 custom_histograms_.insert("V8.MemoryHeapSampleTotalCommitted"); |
| 211 custom_histograms_.insert("V8.MemoryHeapSampleTotalUsed"); |
| 212 } |
| 213 |
| 214 RenderThreadImpl::HistogramCustomizer::~HistogramCustomizer() {} |
| 215 |
| 216 void RenderThreadImpl::HistogramCustomizer::RenderViewNavigatedToHost( |
| 217 const std::string& host, size_t view_count) { |
| 218 // Check if all RenderViews are displaying a page from the same host. If there |
| 219 // is only one RenderView, the common host is this view's host. If there are |
| 220 // many, check if this one shares the common host of the other |
| 221 // RenderViews. It's ok to not detect some cases where the RenderViews share a |
| 222 // common host. This information is only used for producing custom histograms. |
| 223 if (view_count == 1) |
| 224 SetCommonHost(host); |
| 225 else if (host != common_host_) |
| 226 SetCommonHost(std::string()); |
| 227 } |
| 228 |
| 229 std::string RenderThreadImpl::HistogramCustomizer::ConvertToCustomHistogramName( |
| 230 const char* histogram_name) const { |
| 231 std::string name(histogram_name); |
| 232 if (!common_host_histogram_suffix_.empty() && |
| 233 custom_histograms_.find(name) != custom_histograms_.end()) |
| 234 name += common_host_histogram_suffix_; |
| 235 return name; |
| 236 } |
| 237 |
| 238 void RenderThreadImpl::HistogramCustomizer::SetCommonHost( |
| 239 const std::string& host) { |
| 240 if (host != common_host_) { |
| 241 common_host_ = host; |
| 242 common_host_histogram_suffix_ = HostToCustomHistogramSuffix(host); |
| 243 v8::V8::SetCreateHistogramFunction(CreateHistogram); |
| 244 } |
| 245 } |
| 246 |
189 RenderThreadImpl* RenderThreadImpl::current() { | 247 RenderThreadImpl* RenderThreadImpl::current() { |
190 return lazy_tls.Pointer()->Get(); | 248 return lazy_tls.Pointer()->Get(); |
191 } | 249 } |
192 | 250 |
193 // When we run plugins in process, we actually run them on the render thread, | 251 // When we run plugins in process, we actually run them on the render thread, |
194 // which means that we need to make the render thread pump UI events. | 252 // which means that we need to make the render thread pump UI events. |
195 RenderThreadImpl::RenderThreadImpl() { | 253 RenderThreadImpl::RenderThreadImpl() { |
196 Init(); | 254 Init(); |
197 } | 255 } |
198 | 256 |
(...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 | 1131 |
1074 scoped_refptr<base::MessageLoopProxy> | 1132 scoped_refptr<base::MessageLoopProxy> |
1075 RenderThreadImpl::GetFileThreadMessageLoopProxy() { | 1133 RenderThreadImpl::GetFileThreadMessageLoopProxy() { |
1076 DCHECK(message_loop() == MessageLoop::current()); | 1134 DCHECK(message_loop() == MessageLoop::current()); |
1077 if (!file_thread_.get()) { | 1135 if (!file_thread_.get()) { |
1078 file_thread_.reset(new base::Thread("Renderer::FILE")); | 1136 file_thread_.reset(new base::Thread("Renderer::FILE")); |
1079 file_thread_->Start(); | 1137 file_thread_->Start(); |
1080 } | 1138 } |
1081 return file_thread_->message_loop_proxy(); | 1139 return file_thread_->message_loop_proxy(); |
1082 } | 1140 } |
OLD | NEW |