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_thread_observer.h" | 5 #include "chrome/renderer/chrome_render_thread_observer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <memory> | 10 #include <memory> |
11 #include <set> | 11 #include <set> |
12 #include <utility> | 12 #include <utility> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/base_switches.h" | 15 #include "base/base_switches.h" |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
18 #include "base/files/file_util.h" | 18 #include "base/files/file_util.h" |
19 #include "base/location.h" | 19 #include "base/location.h" |
20 #include "base/macros.h" | 20 #include "base/macros.h" |
21 #include "base/memory/weak_ptr.h" | 21 #include "base/memory/weak_ptr.h" |
22 #include "base/metrics/field_trial.h" | 22 #include "base/metrics/field_trial.h" |
23 #include "base/metrics/histogram.h" | 23 #include "base/metrics/histogram.h" |
24 #include "base/metrics/statistics_recorder.h" | 24 #include "base/metrics/statistics_recorder.h" |
25 #include "base/path_service.h" | 25 #include "base/path_service.h" |
26 #include "base/single_thread_task_runner.h" | 26 #include "base/single_thread_task_runner.h" |
27 #include "base/strings/string_number_conversions.h" | |
28 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
29 #include "base/threading/platform_thread.h" | 28 #include "base/threading/platform_thread.h" |
30 #include "base/threading/thread_task_runner_handle.h" | 29 #include "base/threading/thread_task_runner_handle.h" |
31 #include "build/build_config.h" | 30 #include "build/build_config.h" |
32 #include "chrome/common/child_process_logging.h" | 31 #include "chrome/common/child_process_logging.h" |
33 #include "chrome/common/chrome_paths.h" | 32 #include "chrome/common/chrome_paths.h" |
34 #include "chrome/common/media/media_resource_provider.h" | 33 #include "chrome/common/media/media_resource_provider.h" |
35 #include "chrome/common/net/net_resource_provider.h" | 34 #include "chrome/common/net/net_resource_provider.h" |
36 #include "chrome/common/render_messages.h" | 35 #include "chrome/common/render_messages.h" |
37 #include "chrome/common/resource_usage_reporter.mojom.h" | 36 #include "chrome/common/resource_usage_reporter.mojom.h" |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 is_incognito_process_ = is_incognito_process; | 319 is_incognito_process_ = is_incognito_process; |
321 } | 320 } |
322 | 321 |
323 void ChromeRenderThreadObserver::OnSetContentSettingRules( | 322 void ChromeRenderThreadObserver::OnSetContentSettingRules( |
324 const RendererContentSettingRules& rules) { | 323 const RendererContentSettingRules& rules) { |
325 content_setting_rules_ = rules; | 324 content_setting_rules_ = rules; |
326 } | 325 } |
327 | 326 |
328 void ChromeRenderThreadObserver::OnSetFieldTrialGroup( | 327 void ChromeRenderThreadObserver::OnSetFieldTrialGroup( |
329 const std::string& field_trial_name, | 328 const std::string& field_trial_name, |
330 const std::string& group_name, | 329 const std::string& group_name) { |
331 base::ProcessId sender_pid, | |
332 int32_t debug_token) { | |
333 // Check that the sender's PID doesn't change between messages. We expect | |
334 // these IPCs to always be delivered from the same browser process, whose pid | |
335 // should not change. | |
336 // TODO(asvitkine): Remove this after http://crbug.com/359406 is fixed. | |
337 static base::ProcessId sender_pid_cached = sender_pid; | |
338 CHECK_EQ(sender_pid_cached, sender_pid) << sender_pid_cached << "/" | |
339 << sender_pid; | |
340 // Check that the sender's debug_token doesn't change between messages. | |
341 // TODO(asvitkine): Remove this after http://crbug.com/359406 is fixed. | |
342 static int32_t debug_token_cached = debug_token; | |
343 CHECK_EQ(debug_token_cached, debug_token) << debug_token_cached << "/" | |
344 << debug_token; | |
345 // The debug token should also correspond to what was specified on the | |
346 // --force-fieldtrials command line for DebugToken trial. | |
347 const std::string debug_token_trial_value = | |
348 base::FieldTrialList::FindFullName("DebugToken"); | |
349 if (!debug_token_trial_value.empty()) { | |
350 CHECK_EQ(base::IntToString(debug_token), debug_token_trial_value) | |
351 << debug_token << "/" << debug_token_trial_value; | |
352 } | |
353 | |
354 base::FieldTrial* trial = | 330 base::FieldTrial* trial = |
355 base::FieldTrialList::CreateFieldTrial(field_trial_name, group_name); | 331 base::FieldTrialList::CreateFieldTrial(field_trial_name, group_name); |
356 // TODO(asvitkine): Remove this after http://crbug.com/359406 is fixed. | |
357 if (!trial) { | |
358 // Log the --force-fieldtrials= switch value for debugging purposes. Take | |
359 // its substring starting with the trial name, since otherwise the end of | |
360 // it can get truncated in the dump. | |
361 std::string switch_substr = base::CommandLine::ForCurrentProcess()-> | |
362 GetSwitchValueASCII(switches::kForceFieldTrials); | |
363 size_t index = switch_substr.find(field_trial_name); | |
364 if (index != std::string::npos) { | |
365 // If possible, log the string one char before the trial name, as there | |
366 // may be a leading * to indicate it should be activated. | |
367 switch_substr = switch_substr.substr(index > 0 ? index - 1 : index); | |
368 } | |
369 CHECK(trial) << field_trial_name << ":" << group_name << "=>" | |
370 << base::FieldTrialList::FindFullName(field_trial_name) | |
371 << " ] " << switch_substr; | |
372 } | |
373 // Ensure the trial is marked as "used" by calling group() on it if it is | 332 // Ensure the trial is marked as "used" by calling group() on it if it is |
374 // marked as activated. | 333 // marked as activated. |
375 trial->group(); | 334 trial->group(); |
376 variations::SetVariationListCrashKeys(); | 335 variations::SetVariationListCrashKeys(); |
377 } | 336 } |
378 | 337 |
379 const RendererContentSettingRules* | 338 const RendererContentSettingRules* |
380 ChromeRenderThreadObserver::content_setting_rules() const { | 339 ChromeRenderThreadObserver::content_setting_rules() const { |
381 return &content_setting_rules_; | 340 return &content_setting_rules_; |
382 } | 341 } |
383 | 342 |
384 void ChromeRenderThreadObserver::OnFieldTrialGroupFinalized( | 343 void ChromeRenderThreadObserver::OnFieldTrialGroupFinalized( |
385 const std::string& trial_name, | 344 const std::string& trial_name, |
386 const std::string& group_name) { | 345 const std::string& group_name) { |
387 content::RenderThread::Get()->Send( | 346 content::RenderThread::Get()->Send( |
388 new ChromeViewHostMsg_FieldTrialActivated(trial_name)); | 347 new ChromeViewHostMsg_FieldTrialActivated(trial_name)); |
389 } | 348 } |
OLD | NEW |