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 = RenderThreadImpl::current()-> |
| 177 histogram_customizer()->ConvertToCustomHistogramName(name); |
168 base::Histogram* histogram = base::Histogram::FactoryGet( | 178 base::Histogram* histogram = base::Histogram::FactoryGet( |
169 name, min, max, buckets, base::Histogram::kUmaTargetedHistogramFlag); | 179 histogram_name, min, max, buckets, |
| 180 base::Histogram::kUmaTargetedHistogramFlag); |
170 return histogram; | 181 return histogram; |
171 } | 182 } |
172 | 183 |
173 static void AddHistogramSample(void* hist, int sample) { | 184 void AddHistogramSample(void* hist, int sample) { |
174 base::Histogram* histogram = static_cast<base::Histogram*>(hist); | 185 base::Histogram* histogram = static_cast<base::Histogram*>(hist); |
175 histogram->Add(sample); | 186 histogram->Add(sample); |
176 } | 187 } |
177 | 188 |
| 189 } // namespace |
| 190 |
178 class RenderThreadImpl::GpuVDAContextLostCallback | 191 class RenderThreadImpl::GpuVDAContextLostCallback |
179 : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { | 192 : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { |
180 public: | 193 public: |
181 GpuVDAContextLostCallback() {} | 194 GpuVDAContextLostCallback() {} |
182 virtual ~GpuVDAContextLostCallback() {} | 195 virtual ~GpuVDAContextLostCallback() {} |
183 virtual void onContextLost() { | 196 virtual void onContextLost() { |
184 ChildThread::current()->message_loop()->PostTask(FROM_HERE, base::Bind( | 197 ChildThread::current()->message_loop()->PostTask(FROM_HERE, base::Bind( |
185 &RenderThreadImpl::OnGpuVDAContextLoss)); | 198 &RenderThreadImpl::OnGpuVDAContextLoss)); |
186 } | 199 } |
187 }; | 200 }; |
188 | 201 |
| 202 RenderThreadImpl::HistogramCustomizer::HistogramCustomizer() { |
| 203 custom_histograms_.insert("V8.GCCompactor"); |
| 204 custom_histograms_.insert("V8.GCScavenger"); |
| 205 custom_histograms_.insert("V8.GCContext"); |
| 206 custom_histograms_.insert("V8.Parse"); |
| 207 custom_histograms_.insert("V8.ParseLazy"); |
| 208 custom_histograms_.insert("V8.PreParse"); |
| 209 custom_histograms_.insert("V8.Compile"); |
| 210 custom_histograms_.insert("V8.CompileEval"); |
| 211 custom_histograms_.insert("V8.CompileLazy"); |
| 212 custom_histograms_.insert("V8.MemoryExternalFragmentationTotal"); |
| 213 custom_histograms_.insert("V8.MemoryExternalFragmentationOldPointerSpace"); |
| 214 custom_histograms_.insert("V8.MemoryExternalFragmentationOldDataSpace"); |
| 215 custom_histograms_.insert("V8.MemoryExternalFragmentationCodeSpace"); |
| 216 custom_histograms_.insert("V8.MemoryExternalFragmentationMapSpace"); |
| 217 custom_histograms_.insert("V8.MemoryExternalFragmentationCellSpace"); |
| 218 custom_histograms_.insert("V8.MemoryExternalFragmentationLoSpace"); |
| 219 } |
| 220 |
| 221 RenderThreadImpl::HistogramCustomizer::~HistogramCustomizer() {} |
| 222 |
| 223 void RenderThreadImpl::HistogramCustomizer::RenderViewNavigatedToHost( |
| 224 const std::string& host, size_t view_count) { |
| 225 // Check if all RenderViews are displaying a page from the same host. If there |
| 226 // is only one RenderView, the common host is this view's host. If there are |
| 227 // many, check if this one shares the common host of the other |
| 228 // RenderViews. It's ok to not detect some cases where the RenderViews share a |
| 229 // common host. This information is only used for producing custom histograms. |
| 230 if (view_count == 1) |
| 231 SetCommonHost(host); |
| 232 else if (host != common_host_) |
| 233 SetCommonHost(std::string()); |
| 234 } |
| 235 |
| 236 std::string RenderThreadImpl::HistogramCustomizer::ConvertToCustomHistogramName( |
| 237 const char* histogram_name) const { |
| 238 std::string name(histogram_name); |
| 239 if (!common_host_histogram_suffix_.empty() && |
| 240 custom_histograms_.find(name) != custom_histograms_.end()) |
| 241 name += common_host_histogram_suffix_; |
| 242 return name; |
| 243 } |
| 244 |
| 245 void RenderThreadImpl::HistogramCustomizer::SetCommonHost( |
| 246 const std::string& host) { |
| 247 if (host != common_host_) { |
| 248 common_host_ = host; |
| 249 common_host_histogram_suffix_ = HostToCustomHistogramSuffix(host); |
| 250 v8::V8::SetCreateHistogramFunction(CreateHistogram); |
| 251 } |
| 252 } |
| 253 |
189 RenderThreadImpl* RenderThreadImpl::current() { | 254 RenderThreadImpl* RenderThreadImpl::current() { |
190 return lazy_tls.Pointer()->Get(); | 255 return lazy_tls.Pointer()->Get(); |
191 } | 256 } |
192 | 257 |
193 // When we run plugins in process, we actually run them on the render thread, | 258 // 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. | 259 // which means that we need to make the render thread pump UI events. |
195 RenderThreadImpl::RenderThreadImpl() { | 260 RenderThreadImpl::RenderThreadImpl() { |
196 Init(); | 261 Init(); |
197 } | 262 } |
198 | 263 |
(...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 | 1138 |
1074 scoped_refptr<base::MessageLoopProxy> | 1139 scoped_refptr<base::MessageLoopProxy> |
1075 RenderThreadImpl::GetFileThreadMessageLoopProxy() { | 1140 RenderThreadImpl::GetFileThreadMessageLoopProxy() { |
1076 DCHECK(message_loop() == MessageLoop::current()); | 1141 DCHECK(message_loop() == MessageLoop::current()); |
1077 if (!file_thread_.get()) { | 1142 if (!file_thread_.get()) { |
1078 file_thread_.reset(new base::Thread("Renderer::FILE")); | 1143 file_thread_.reset(new base::Thread("Renderer::FILE")); |
1079 file_thread_->Start(); | 1144 file_thread_->Start(); |
1080 } | 1145 } |
1081 return file_thread_->message_loop_proxy(); | 1146 return file_thread_->message_loop_proxy(); |
1082 } | 1147 } |
OLD | NEW |