Commit 59bb8c22 authored by Xi Han's avatar Xi Han Committed by Commit Bot

Persist histogram data when Chrome is running in the reduced mode.

Recently we noticed that the histogram data is lost when Chrome is
running in the reduced mode and get killed before the full browser
starts. This is because there isn't a SystemProfile set in the
reduced mode. Thus, the previous data in the BrowserMetrics-active.pma
file isn't picked up by Chrome the next time it is launched in the
full browser mode.

In this CL, we write the initial system profile to the mapped memory
file, so Chrome will pick up the data when it restarts in the full
browser mode.

Note: the histogram data is only persistent on the memory mapped file,
but not being uploaded when Chrome is running in the reduced mode.

Bug: 959854
Change-Id: Idc1cea6edfa854edf94f791f2df8a9ebb6a0af8e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1601307Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarBrian White <bcwhite@chromium.org>
Commit-Queue: Xi Han <hanxi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#662815}
parent 85106229
...@@ -1564,6 +1564,7 @@ _chrome_public_shared_deps = [ ...@@ -1564,6 +1564,7 @@ _chrome_public_shared_deps = [
generate_jni("test_support_jni_headers") { generate_jni("test_support_jni_headers") {
sources = [ sources = [
"javatests/src/org/chromium/chrome/browser/ServicificationBackgroundService.java",
"javatests/src/org/chromium/chrome/browser/offlinepages/OfflineTestUtil.java", "javatests/src/org/chromium/chrome/browser/offlinepages/OfflineTestUtil.java",
"javatests/src/org/chromium/chrome/browser/offlinepages/prefetch/PrefetchTestBridge.java", "javatests/src/org/chromium/chrome/browser/offlinepages/prefetch/PrefetchTestBridge.java",
"javatests/src/org/chromium/chrome/browser/test/MockCertVerifierRuleAndroid.java", "javatests/src/org/chromium/chrome/browser/test/MockCertVerifierRuleAndroid.java",
...@@ -1579,9 +1580,11 @@ android_library("browser_java_test_support") { ...@@ -1579,9 +1580,11 @@ android_library("browser_java_test_support") {
"javatests/src/org/chromium/chrome/browser/offlinepages/OfflineTestUtil.java", "javatests/src/org/chromium/chrome/browser/offlinepages/OfflineTestUtil.java",
"javatests/src/org/chromium/chrome/browser/sync/FakeServerHelper.java", "javatests/src/org/chromium/chrome/browser/sync/FakeServerHelper.java",
"javatests/src/org/chromium/chrome/browser/test/MockCertVerifierRuleAndroid.java", "javatests/src/org/chromium/chrome/browser/test/MockCertVerifierRuleAndroid.java",
"javatests/src/org/chromium/chrome/browser/ServicificationBackgroundService.java",
] ]
deps = [ deps = [
":chrome_java", ":chrome_java",
"$google_play_services_package:google_play_services_gcm_java",
"//base:base_java", "//base:base_java",
"//base:base_java_test_support", "//base:base_java_test_support",
"//chrome/android/public/profiles:java", "//chrome/android/public/profiles:java",
...@@ -1597,6 +1600,7 @@ android_library("browser_java_test_support") { ...@@ -1597,6 +1600,7 @@ android_library("browser_java_test_support") {
static_library("browser_test_support") { static_library("browser_test_support") {
testonly = true testonly = true
sources = [ sources = [
"../browser/android/servicification_background_service_jni.cc",
"../browser/android/ssl/mock_cert_verifier_rule_android.cc", "../browser/android/ssl/mock_cert_verifier_rule_android.cc",
"../browser/android/ssl/mock_cert_verifier_rule_android.h", "../browser/android/ssl/mock_cert_verifier_rule_android.h",
"../browser/offline_pages/android/offline_test_util_jni.cc", "../browser/offline_pages/android/offline_test_util_jni.cc",
......
...@@ -35,7 +35,6 @@ chrome_test_java_sources = [ ...@@ -35,7 +35,6 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/RestoreHistogramTest.java", "javatests/src/org/chromium/chrome/browser/RestoreHistogramTest.java",
"javatests/src/org/chromium/chrome/browser/SafeBrowsingTest.java", "javatests/src/org/chromium/chrome/browser/SafeBrowsingTest.java",
"javatests/src/org/chromium/chrome/browser/SelectFileDialogTest.java", "javatests/src/org/chromium/chrome/browser/SelectFileDialogTest.java",
"javatests/src/org/chromium/chrome/browser/ServicificationBackgroundService.java",
"javatests/src/org/chromium/chrome/browser/ServicificationBackgroundServiceTest.java", "javatests/src/org/chromium/chrome/browser/ServicificationBackgroundServiceTest.java",
"javatests/src/org/chromium/chrome/browser/ShareIntentTest.java", "javatests/src/org/chromium/chrome/browser/ShareIntentTest.java",
"javatests/src/org/chromium/chrome/browser/SmartClipProviderTest.java", "javatests/src/org/chromium/chrome/browser/SmartClipProviderTest.java",
......
...@@ -117,4 +117,10 @@ public class ServicificationBackgroundService extends ChromeBackgroundService { ...@@ -117,4 +117,10 @@ public class ServicificationBackgroundService extends ChromeBackgroundService {
BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER) BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER)
.isStartupSuccessfullyCompleted())); .isStartupSuccessfullyCompleted()));
} }
public void assertPersistentHistogramsOnDiskSystemProfile() {
Assert.assertTrue(nativeTestPersistentHistogramsOnDiskSystemProfile());
}
private static native boolean nativeTestPersistentHistogramsOnDiskSystemProfile();
} }
...@@ -4,15 +4,20 @@ ...@@ -4,15 +4,20 @@
package org.chromium.chrome.browser; package org.chromium.chrome.browser;
import android.support.test.filters.LargeTest;
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
import com.google.android.gms.gcm.TaskParams; import com.google.android.gms.gcm.TaskParams;
import org.junit.After; import org.junit.After;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.StrictModeContext;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
...@@ -20,6 +25,12 @@ import org.chromium.base.test.util.RetryOnFailure; ...@@ -20,6 +25,12 @@ import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.browser.init.ServiceManagerStartupUtils; import org.chromium.chrome.browser.init.ServiceManagerStartupUtils;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
/** /**
* Tests background tasks can be run in Service Manager only mode, i.e., without starting the full * Tests background tasks can be run in Service Manager only mode, i.e., without starting the full
* browser. * browser.
...@@ -28,6 +39,18 @@ import org.chromium.chrome.test.ChromeJUnit4ClassRunner; ...@@ -28,6 +39,18 @@ import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
@RetryOnFailure @RetryOnFailure
public final class ServicificationBackgroundServiceTest { public final class ServicificationBackgroundServiceTest {
private ServicificationBackgroundService mServicificationBackgroundService; private ServicificationBackgroundService mServicificationBackgroundService;
private RandomAccessFile mMappedSpareFile;
private File mSpareFile;
/**
The size of the persistent/shared memory to store histograms. It should be consistent with
the |kAllocSize| in persistent_histograms.cc.
*/
private static final int ALLOC_SIZE = 4 << 20; // 4 MiB
private static final String APP_CHROME_DIR = "app_chrome";
private static final String SPARE_FILE_NAME = "BrowserMetrics-spare.pma";
private static final String TAG = "ServicificationStartupTest";
@Before @Before
public void setUp() { public void setUp() {
...@@ -40,6 +63,51 @@ public final class ServicificationBackgroundServiceTest { ...@@ -40,6 +63,51 @@ public final class ServicificationBackgroundServiceTest {
@After @After
public void tearDown() { public void tearDown() {
RecordHistogram.setDisabledForTests(false); RecordHistogram.setDisabledForTests(false);
closeBrowserMetricsSpareFile();
}
// Creates the memory-mapped file which is used to persist histograms data before native is
// loaded.
private void createBrowserMetricsSpareFile() {
File appChromeDir = new File(
ContextUtils.getApplicationContext().getApplicationInfo().dataDir, APP_CHROME_DIR);
if (!appChromeDir.exists()) appChromeDir.mkdir();
mSpareFile = new File(appChromeDir + File.separator + SPARE_FILE_NAME);
try {
mSpareFile.createNewFile();
} catch (IOException e) {
Log.d(TAG, "Fail to create file: %s", SPARE_FILE_NAME);
return;
}
try (StrictModeContext smc = StrictModeContext.allowDiskWrites()) {
try {
mMappedSpareFile = new RandomAccessFile(mSpareFile, "rw");
MappedByteBuffer mappedByteBuffer = mMappedSpareFile.getChannel().map(
FileChannel.MapMode.READ_WRITE, 0, ALLOC_SIZE);
mappedByteBuffer.load();
Assert.assertTrue(mappedByteBuffer.isLoaded());
mappedByteBuffer.put(0, (byte) 0);
Assert.assertTrue(Byte.compare(mappedByteBuffer.get(0), (byte) 0) == 0);
} catch (Exception e) {
Log.d(TAG, "Fail to create memory-mapped file: %s", SPARE_FILE_NAME);
}
}
}
private void closeBrowserMetricsSpareFile() {
if (mMappedSpareFile == null) return;
try (StrictModeContext smc = StrictModeContext.allowDiskWrites()) {
try {
mMappedSpareFile.close();
} catch (IOException e) {
Log.d(TAG, "Fail to close memory-mapped file: %s", SPARE_FILE_NAME);
}
}
} }
private static void startServiceAndWaitForNative( private static void startServiceAndWaitForNative(
...@@ -49,6 +117,23 @@ public final class ServicificationBackgroundServiceTest { ...@@ -49,6 +117,23 @@ public final class ServicificationBackgroundServiceTest {
backgroundService.waitForNativeLoaded(); backgroundService.waitForNativeLoaded();
} }
@Test
@LargeTest
@Feature({"ServicificationStartup"})
@CommandLineFlags.Add({"enable-features=NetworkService,AllowStartingServiceManagerOnly,"
+ "WriteBasicSystemProfileToPersistentHistogramsFile"})
public void
testHistogramsPersistedWithServiceManagerOnlyStart() {
createBrowserMetricsSpareFile();
Assert.assertTrue(mSpareFile.exists());
startServiceAndWaitForNative(mServicificationBackgroundService);
ServicificationBackgroundService.assertOnlyServiceManagerStarted();
mServicificationBackgroundService.assertPersistentHistogramsOnDiskSystemProfile();
ServicificationBackgroundService.assertOnlyServiceManagerStarted();
}
@Test @Test
@MediumTest @MediumTest
@Feature({"ServicificationStartup"}) @Feature({"ServicificationStartup"})
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "chrome/common/channel_info.h" #include "chrome/common/channel_info.h"
#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_content_client.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_paths_internal.h" #include "chrome/common/chrome_paths_internal.h"
#include "chrome/common/chrome_result_codes.h" #include "chrome/common/chrome_result_codes.h"
...@@ -550,11 +551,15 @@ bool ChromeMainDelegate::ShouldCreateFeatureList() { ...@@ -550,11 +551,15 @@ bool ChromeMainDelegate::ShouldCreateFeatureList() {
return false; return false;
} }
#if defined(OS_ANDROID)
void ChromeMainDelegate::PostTaskSchedulerStart() { void ChromeMainDelegate::PostTaskSchedulerStart() {
#if defined(OS_ANDROID)
startup_data_->CreateProfilePrefService(); startup_data_->CreateProfilePrefService();
}
#endif #endif
if (base::FeatureList::IsEnabled(
features::kWriteBasicSystemProfileToPersistentHistogramsFile)) {
startup_data_->RecordCoreSystemProfile();
}
}
#endif #endif
......
...@@ -66,9 +66,7 @@ class ChromeMainDelegate : public content::ContentMainDelegate { ...@@ -66,9 +66,7 @@ class ChromeMainDelegate : public content::ContentMainDelegate {
#if !defined(CHROME_MULTIPLE_DLL_CHILD) #if !defined(CHROME_MULTIPLE_DLL_CHILD)
void PostEarlyInitialization(bool is_running_tests) override; void PostEarlyInitialization(bool is_running_tests) override;
bool ShouldCreateFeatureList() override; bool ShouldCreateFeatureList() override;
#if defined(OS_ANDROID)
void PostTaskSchedulerStart() override; void PostTaskSchedulerStart() override;
#endif // defined(OS_ANDROID)
#endif // !defined(CHROME_MULTIPLE_DLL_CHILD) #endif // !defined(CHROME_MULTIPLE_DLL_CHILD)
void PostFieldTrialInitialization() override; void PostFieldTrialInitialization() override;
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <sstream>
#include "base/android/jni_android.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/memory_mapped_file.h"
#include "base/metrics/persistent_histogram_allocator.h"
#include "base/system/sys_info.h"
#include "components/metrics/persistent_system_profile.h"
#include "jni/ServicificationBackgroundService_jni.h"
#include "third_party/metrics_proto/system_profile.pb.h"
// Verifies that the memory-mapped file for persistent histograms data exists
// and contains a valid SystemProfile.
jboolean
JNI_ServicificationBackgroundService_TestPersistentHistogramsOnDiskSystemProfile(
JNIEnv* env) {
base::GlobalHistogramAllocator* allocator =
base::GlobalHistogramAllocator::Get();
if (!allocator)
return false;
const base::FilePath& persistent_file_path =
allocator->GetPersistentLocation();
if (persistent_file_path.empty())
return false;
base::File file(persistent_file_path,
base::File::FLAG_OPEN | base::File::FLAG_READ);
if (!file.IsValid())
return false;
std::unique_ptr<base::MemoryMappedFile> mapped(new base::MemoryMappedFile());
if (!mapped->Initialize(std::move(file), base::MemoryMappedFile::READ_ONLY))
return false;
if (!base::FilePersistentMemoryAllocator::IsFileAcceptable(
*mapped, true /* read_only */)) {
return false;
}
// Map the file and validate it.
std::unique_ptr<base::FilePersistentMemoryAllocator> memory_allocator =
std::make_unique<base::FilePersistentMemoryAllocator>(
std::move(mapped), 0, 0, base::StringPiece(), /* read_only */ true);
if (memory_allocator->GetMemoryState() ==
base::PersistentMemoryAllocator::MEMORY_DELETED) {
return false;
}
if (memory_allocator->IsCorrupt())
return false;
if (!metrics::PersistentSystemProfile::HasSystemProfile(*memory_allocator))
return false;
metrics::SystemProfileProto system_profile_proto;
if (!metrics::PersistentSystemProfile::GetSystemProfile(
*memory_allocator, &system_profile_proto))
return false;
if (!system_profile_proto.has_os())
return false;
const metrics::SystemProfileProto_OS& os = system_profile_proto.os();
if (!os.has_version())
return false;
return base::SysInfo::OperatingSystemVersion().compare(os.version()) == 0;
}
...@@ -100,7 +100,6 @@ ...@@ -100,7 +100,6 @@
#include "services/network/public/cpp/shared_url_loader_factory.h" #include "services/network/public/cpp/shared_url_loader_factory.h"
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "base/android/build_info.h"
#include "chrome/browser/metrics/android_metrics_provider.h" #include "chrome/browser/metrics/android_metrics_provider.h"
#include "chrome/browser/metrics/page_load_metrics_provider.h" #include "chrome/browser/metrics/page_load_metrics_provider.h"
#endif #endif
...@@ -1060,10 +1059,7 @@ bool ChromeMetricsServiceClient:: ...@@ -1060,10 +1059,7 @@ bool ChromeMetricsServiceClient::
} }
std::string ChromeMetricsServiceClient::GetAppPackageName() { std::string ChromeMetricsServiceClient::GetAppPackageName() {
#if defined(OS_ANDROID) return metrics::GetAppPackageName();
return base::android::BuildInfo::GetInstance()->package_name();
#endif
return std::string();
} }
std::string ChromeMetricsServiceClient::GetUploadSigningKey() { std::string ChromeMetricsServiceClient::GetUploadSigningKey() {
......
...@@ -6,6 +6,11 @@ ...@@ -6,6 +6,11 @@
#include "chrome/browser/metrics/chrome_feature_list_creator.h" #include "chrome/browser/metrics/chrome_feature_list_creator.h"
#include "chrome/browser/prefs/profile_pref_store_manager.h" #include "chrome/browser/prefs/profile_pref_store_manager.h"
#include "chrome/common/channel_info.h"
#include "components/metrics/metrics_log.h"
#include "components/metrics/persistent_system_profile.h"
#include "components/metrics/version_utils.h"
#include "third_party/metrics_proto/system_profile.pb.h"
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "base/files/file_util.h" #include "base/files/file_util.h"
...@@ -59,6 +64,19 @@ StartupData::StartupData() ...@@ -59,6 +64,19 @@ StartupData::StartupData()
StartupData::~StartupData() = default; StartupData::~StartupData() = default;
void StartupData::RecordCoreSystemProfile() {
metrics::SystemProfileProto system_profile;
metrics::MetricsLog::RecordCoreSystemProfile(
metrics::GetVersionString(),
metrics::AsProtobufChannel(chrome::GetChannel()),
chrome_feature_list_creator_->actual_locale(),
metrics::GetAppPackageName(), &system_profile);
// TODO(crbug.com/965482): Records other information, such as field trials.
metrics::GlobalPersistentSystemProfile::GetInstance()->SetSystemProfile(
system_profile, /* complete */ false);
}
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
void StartupData::CreateProfilePrefService() { void StartupData::CreateProfilePrefService() {
key_ = std::make_unique<ProfileKey>(GetProfilePath()); key_ = std::make_unique<ProfileKey>(GetProfilePath());
......
...@@ -38,6 +38,13 @@ class StartupData { ...@@ -38,6 +38,13 @@ class StartupData {
StartupData(); StartupData();
~StartupData(); ~StartupData();
// Records core profile settings into the SystemProfileProto. It is important
// when Chrome is running in the reduced mode, which doesn't start UMA
// recording but persists all of the UMA data into a memory mapped file. The
// file will be picked up by Chrome next time it is launched in the full
// browser mode.
void RecordCoreSystemProfile();
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// Initializes all necessary parameters to create the Profile's PrefService. // Initializes all necessary parameters to create the Profile's PrefService.
void CreateProfilePrefService(); void CreateProfilePrefService();
......
...@@ -744,6 +744,12 @@ const base::Feature kWin10AcceleratedDefaultBrowserFlow{ ...@@ -744,6 +744,12 @@ const base::Feature kWin10AcceleratedDefaultBrowserFlow{
"Win10AcceleratedDefaultBrowserFlow", base::FEATURE_ENABLED_BY_DEFAULT}; "Win10AcceleratedDefaultBrowserFlow", base::FEATURE_ENABLED_BY_DEFAULT};
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
// Enables writing basic system profile to the persistent histograms files
// earlier.
const base::Feature kWriteBasicSystemProfileToPersistentHistogramsFile{
"WriteBasicSystemProfileToPersistentHistogramsFile",
base::FEATURE_ENABLED_BY_DEFAULT};
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// Enables showing alternative incognito strings. // Enables showing alternative incognito strings.
const base::Feature kIncognitoStrings{"IncognitoStrings", const base::Feature kIncognitoStrings{"IncognitoStrings",
......
...@@ -471,6 +471,9 @@ COMPONENT_EXPORT(CHROME_FEATURES) ...@@ -471,6 +471,9 @@ COMPONENT_EXPORT(CHROME_FEATURES)
extern const base::Feature kWin10AcceleratedDefaultBrowserFlow; extern const base::Feature kWin10AcceleratedDefaultBrowserFlow;
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
COMPONENT_EXPORT(CHROME_FEATURES)
extern const base::Feature kWriteBasicSystemProfileToPersistentHistogramsFile;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
COMPONENT_EXPORT(CHROME_FEATURES) extern const base::Feature kIncognitoStrings; COMPONENT_EXPORT(CHROME_FEATURES) extern const base::Feature kIncognitoStrings;
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
......
...@@ -163,12 +163,25 @@ void MetricsLog::RecordUserAction(const std::string& key) { ...@@ -163,12 +163,25 @@ void MetricsLog::RecordUserAction(const std::string& key) {
user_action->set_time_sec(GetCurrentTime()); user_action->set_time_sec(GetCurrentTime());
} }
// static
void MetricsLog::RecordCoreSystemProfile(MetricsServiceClient* client, void MetricsLog::RecordCoreSystemProfile(MetricsServiceClient* client,
SystemProfileProto* system_profile) { SystemProfileProto* system_profile) {
RecordCoreSystemProfile(client->GetVersionString(), client->GetChannel(),
client->GetApplicationLocale(),
client->GetAppPackageName(), system_profile);
}
// static
void MetricsLog::RecordCoreSystemProfile(
const std::string& version,
metrics::SystemProfileProto::Channel channel,
const std::string& application_locale,
const std::string& package_name,
SystemProfileProto* system_profile) {
system_profile->set_build_timestamp(metrics::MetricsLog::GetBuildTime()); system_profile->set_build_timestamp(metrics::MetricsLog::GetBuildTime());
system_profile->set_app_version(client->GetVersionString()); system_profile->set_app_version(version);
system_profile->set_channel(client->GetChannel()); system_profile->set_channel(channel);
system_profile->set_application_locale(client->GetApplicationLocale()); system_profile->set_application_locale(application_locale);
#if defined(ADDRESS_SANITIZER) || DCHECK_IS_ON() #if defined(ADDRESS_SANITIZER) || DCHECK_IS_ON()
// Set if a build is instrumented (e.g. built with ASAN, or with DCHECKs). // Set if a build is instrumented (e.g. built with ASAN, or with DCHECKs).
...@@ -206,7 +219,6 @@ void MetricsLog::RecordCoreSystemProfile(MetricsServiceClient* client, ...@@ -206,7 +219,6 @@ void MetricsLog::RecordCoreSystemProfile(MetricsServiceClient* client,
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
os->set_build_fingerprint( os->set_build_fingerprint(
base::android::BuildInfo::GetInstance()->android_build_fp()); base::android::BuildInfo::GetInstance()->android_build_fp());
std::string package_name = client->GetAppPackageName();
if (!package_name.empty() && package_name != "com.android.chrome") if (!package_name.empty() && package_name != "com.android.chrome")
system_profile->set_app_package_name(package_name); system_profile->set_app_package_name(package_name);
#elif defined(OS_IOS) #elif defined(OS_IOS)
......
...@@ -110,6 +110,14 @@ class MetricsLog { ...@@ -110,6 +110,14 @@ class MetricsLog {
static void RecordCoreSystemProfile(MetricsServiceClient* client, static void RecordCoreSystemProfile(MetricsServiceClient* client,
SystemProfileProto* system_profile); SystemProfileProto* system_profile);
// Record core profile settings into the SystemProfileProto without a client.
static void RecordCoreSystemProfile(
const std::string& version,
metrics::SystemProfileProto::Channel channel,
const std::string& application_locale,
const std::string& package_name,
SystemProfileProto* system_profile);
// Records a user-initiated action. // Records a user-initiated action.
void RecordUserAction(const std::string& key); void RecordUserAction(const std::string& key);
......
...@@ -123,6 +123,8 @@ void InstantiatePersistentHistograms(const base::FilePath& metrics_dir) { ...@@ -123,6 +123,8 @@ void InstantiatePersistentHistograms(const base::FilePath& metrics_dir) {
// it. Memory that is not actualy used won't be physically mapped by the // it. Memory that is not actualy used won't be physically mapped by the
// system. BrowserMetrics usage, as reported in UMA, has the 99.99 // system. BrowserMetrics usage, as reported in UMA, has the 99.99
// percentile around 3MiB as of 2018-10-22. // percentile around 3MiB as of 2018-10-22.
// Please update ServicificationBackgroundServiceTest.java if the |kAllocSize|
// is changed.
const size_t kAllocSize = 4 << 20; // 4 MiB const size_t kAllocSize = 4 << 20; // 4 MiB
const uint32_t kAllocId = 0x935DDD43; // SHA1(BrowserMetrics) const uint32_t kAllocId = 0x935DDD43; // SHA1(BrowserMetrics)
std::string storage = variations::GetVariationParamValueByFeature( std::string storage = variations::GetVariationParamValueByFeature(
......
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "components/version_info/version_info.h" #include "components/version_info/version_info.h"
#if defined(OS_ANDROID)
#include "base/android/build_info.h"
#endif
namespace metrics { namespace metrics {
std::string GetVersionString() { std::string GetVersionString() {
...@@ -43,4 +47,11 @@ SystemProfileProto::Channel AsProtobufChannel(version_info::Channel channel) { ...@@ -43,4 +47,11 @@ SystemProfileProto::Channel AsProtobufChannel(version_info::Channel channel) {
return SystemProfileProto::CHANNEL_UNKNOWN; return SystemProfileProto::CHANNEL_UNKNOWN;
} }
std::string GetAppPackageName() {
#if defined(OS_ANDROID)
return base::android::BuildInfo::GetInstance()->package_name();
#endif
return std::string();
}
} // namespace metrics } // namespace metrics
...@@ -23,6 +23,10 @@ std::string GetVersionString(); ...@@ -23,6 +23,10 @@ std::string GetVersionString();
// SystemProfileProto::Channel. // SystemProfileProto::Channel.
SystemProfileProto::Channel AsProtobufChannel(version_info::Channel channel); SystemProfileProto::Channel AsProtobufChannel(version_info::Channel channel);
// Gets Chrome's package name in Android Chrome, or an empty string on other
// platforms.
std::string GetAppPackageName();
} // namespace metrics } // namespace metrics
#endif // COMPONENTS_METRICS_VERSION_UTILS_H_ #endif // COMPONENTS_METRICS_VERSION_UTILS_H_
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