Commit 106a571a authored by renjieliu's avatar renjieliu Committed by Commit Bot

Add switches for language detection and translation logging.

Apply switches as previosuly discussed so we easily turn off
language detection logging or translation logging if something
goes wrong.

BUG=728491, 722679

Review-Url: https://codereview.chromium.org/2941953002
Cr-Commit-Position: refs/heads/master@{#481054}
parent a965b7f0
......@@ -7,6 +7,7 @@
#include <memory>
#include <vector>
#include "base/feature_list.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/strings/string_split.h"
......@@ -31,6 +32,7 @@
#include "chrome/grit/theme_resources.h"
#include "components/metrics/proto/translate_event.pb.h"
#include "components/prefs/pref_service.h"
#include "components/sync/driver/sync_driver_switches.h"
#include "components/sync/protocol/user_event_specifics.pb.h"
#include "components/sync/user_events/user_event_service.h"
#include "components/translate/core/browser/language_model.h"
......@@ -53,6 +55,7 @@
#include "url/gurl.h"
namespace {
using base::FeatureList;
using metrics::TranslateEventProto;
TranslateEventProto::EventType BubbleResultToTranslateEvent(
......@@ -79,6 +82,8 @@ TranslateEventProto::EventType BubbleResultToTranslateEvent(
void LogLanguageDetectionEvent(
const content::WebContents* const web_contents,
const translate::LanguageDetectionDetails& details) {
if (!FeatureList::IsEnabled(switches::kSyncUserLanguageDetectionEvents))
return;
auto* const profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
......@@ -104,6 +109,8 @@ void LogLanguageDetectionEvent(
void LogTranslateEvent(const content::WebContents* const web_contents,
const metrics::TranslateEventProto& translate_event) {
if (!FeatureList::IsEnabled(switches::kSyncUserTranslationEvents))
return;
DCHECK(web_contents);
auto* const profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
......
......@@ -9,9 +9,11 @@
#include "base/command_line.h"
#include "base/memory/ref_counted.h"
#include "base/run_loop.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/user_event_service_factory.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "components/sync/driver/sync_driver_switches.h"
#include "components/sync/user_events/fake_user_event_service.h"
#include "components/translate/core/common/language_detection_details.h"
#include "content/public/browser/web_contents.h"
......@@ -31,6 +33,9 @@ class ChromeTranslateClientTest : public ChromeRenderViewHostTestHarness {
browser_sync::UserEventServiceFactory::GetInstance()
->SetTestingFactoryAndUse(browser_context(),
&BuildFakeUserEventService));
scoped_feature_list_ = base::MakeUnique<base::test::ScopedFeatureList>();
scoped_feature_list_->InitAndEnableFeature(
switches::kSyncUserLanguageDetectionEvents);
}
void TearDown() override { ChromeRenderViewHostTestHarness::TearDown(); }
......@@ -41,6 +46,7 @@ class ChromeTranslateClientTest : public ChromeRenderViewHostTestHarness {
}
private:
std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list_;
syncer::FakeUserEventService* fake_user_event_service_;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment