Skip to content

Commit

Permalink
Convert ChromeViewMsg_SetFieldTrialGroup to use mojo.
Browse files Browse the repository at this point in the history
BUG=577685

Review-Url: https://codereview.chromium.org/2642263002
Cr-Commit-Position: refs/heads/master@{#448132}
  • Loading branch information
nigeltao authored and Commit bot committed Feb 4, 2017
1 parent 90396e6 commit f007b70
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 29 deletions.
11 changes: 8 additions & 3 deletions chrome/browser/metrics/field_trial_synchronizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "base/bind.h"
#include "base/logging.h"
#include "base/threading/thread.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/renderer_configuration.mojom.h"
#include "components/variations/variations_util.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
Expand Down Expand Up @@ -42,8 +42,13 @@ void FieldTrialSynchronizer::NotifyAllRenderers(
for (content::RenderProcessHost::iterator it(
content::RenderProcessHost::AllHostsIterator());
!it.IsAtEnd(); it.Advance()) {
it.GetCurrentValue()->Send(new ChromeViewMsg_SetFieldTrialGroup(
field_trial_name, group_name));
IPC::ChannelProxy* channel = it.GetCurrentValue()->GetChannel();
// channel might be null in tests.
if (channel) {
chrome::mojom::RendererConfigurationAssociatedPtr renderer_configuration;
channel->GetRemoteAssociatedInterface(&renderer_configuration);
renderer_configuration->SetFieldTrialGroup(field_trial_name, group_name);
}
}
}

Expand Down
6 changes: 0 additions & 6 deletions chrome/common/render_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,6 @@ IPC_MESSAGE_ROUTED1(ChromeViewMsg_WebUIJavaScript,
IPC_MESSAGE_ROUTED1(ChromeViewMsg_LoadBlockedPlugins,
std::string /* identifier */)

// Tells the renderer to create a FieldTrial, and by using a 100% probability
// for the FieldTrial, forces the FieldTrial to have assigned group name.
IPC_MESSAGE_CONTROL2(ChromeViewMsg_SetFieldTrialGroup,
std::string /* field trial name */,
std::string /* group name that was assigned. */)

// Sent to allow or forbid the running of insecure mixed-content.
IPC_MESSAGE_ROUTED1(ChromeViewMsg_SetAllowRunningInsecureContent,
bool /* allowed */)
Expand Down
6 changes: 6 additions & 0 deletions chrome/common/renderer_configuration.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ interface RendererConfiguration {
// Set the content setting rules stored by the renderer.
SetContentSettingRules(
content_settings.mojom.RendererContentSettingRules rules);

// Tells the renderer to create a FieldTrial, and by using a 100% probability
// for the FieldTrial, forces the FieldTrial to have assigned group name.
//
// See base/metrics/field_trial.h for more information.
SetFieldTrialGroup(string trial_name, string group_name);
};
22 changes: 6 additions & 16 deletions chrome/renderer/chrome_render_thread_observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,6 @@ void ChromeRenderThreadObserver::UnregisterMojoInterfaces(
chrome::mojom::RendererConfiguration::Name_);
}

bool ChromeRenderThreadObserver::OnControlMessageReceived(
const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ChromeRenderThreadObserver, message)
IPC_MESSAGE_HANDLER(ChromeViewMsg_SetFieldTrialGroup, OnSetFieldTrialGroup)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}

void ChromeRenderThreadObserver::OnRenderProcessShutdown() {
visited_link_slave_.reset();

Expand All @@ -324,17 +314,17 @@ void ChromeRenderThreadObserver::SetContentSettingRules(
content_setting_rules_ = rules;
}

void ChromeRenderThreadObserver::OnRendererConfigurationAssociatedRequest(
chrome::mojom::RendererConfigurationAssociatedRequest request) {
renderer_configuration_bindings_.AddBinding(this, std::move(request));
}

void ChromeRenderThreadObserver::OnSetFieldTrialGroup(
void ChromeRenderThreadObserver::SetFieldTrialGroup(
const std::string& trial_name,
const std::string& group_name) {
field_trial_syncer_.OnSetFieldTrialGroup(trial_name, group_name);
}

void ChromeRenderThreadObserver::OnRendererConfigurationAssociatedRequest(
chrome::mojom::RendererConfigurationAssociatedRequest request) {
renderer_configuration_bindings_.AddBinding(this, std::move(request));
}

const RendererContentSettingRules*
ChromeRenderThreadObserver::content_setting_rules() const {
return &content_setting_rules_;
Expand Down
6 changes: 2 additions & 4 deletions chrome/renderer/chrome_render_thread_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class ChromeRenderThreadObserver : public content::RenderThreadObserver,
content::AssociatedInterfaceRegistry* associated_interfaces) override;
void UnregisterMojoInterfaces(
content::AssociatedInterfaceRegistry* associated_interfaces) override;
bool OnControlMessageReceived(const IPC::Message& message) override;
void OnRenderProcessShutdown() override;

// base::FieldTrialList::Observer:
Expand All @@ -64,13 +63,12 @@ class ChromeRenderThreadObserver : public content::RenderThreadObserver,
void SetInitialConfiguration(bool is_incognito_process) override;
void SetContentSettingRules(
const RendererContentSettingRules& rules) override;
void SetFieldTrialGroup(const std::string& trial_name,
const std::string& group_name) override;

void OnRendererConfigurationAssociatedRequest(
chrome::mojom::RendererConfigurationAssociatedRequest request);

void OnSetFieldTrialGroup(const std::string& trial_name,
const std::string& group_name);

static bool is_incognito_process_;
std::unique_ptr<content::ResourceDispatcherDelegate> resource_delegate_;
RendererContentSettingRules content_setting_rules_;
Expand Down

0 comments on commit f007b70

Please sign in to comment.