Commit 3c5ec913 authored by Eugene But's avatar Eugene But Committed by Commit Bot

[ios] Don't log redundand device orientation breadcrumbs

- don't log "unknown" orientation on startup
- don't log duplicate orientation changes

Bug: 1046225
Change-Id: Idc9dbbb444737520d86edbc3306157992d599d82
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2363353
Commit-Queue: Eugene But <eugenebut@chromium.org>
Auto-Submit: Eugene But <eugenebut@chromium.org>
Reviewed-by: default avatarMike Dougherty <michaeldo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799714}
parent fc2b1eeb
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#ifndef IOS_CHROME_BROWSER_CRASH_REPORT_BREADCRUMBS_APPLICATION_BREADCRUMBS_LOGGER_H_ #ifndef IOS_CHROME_BROWSER_CRASH_REPORT_BREADCRUMBS_APPLICATION_BREADCRUMBS_LOGGER_H_
#define IOS_CHROME_BROWSER_CRASH_REPORT_BREADCRUMBS_APPLICATION_BREADCRUMBS_LOGGER_H_ #define IOS_CHROME_BROWSER_CRASH_REPORT_BREADCRUMBS_APPLICATION_BREADCRUMBS_LOGGER_H_
#import <Foundation/Foundation.h> #import <UIKit/UIKit.h>
#include <memory> #include <memory>
...@@ -51,6 +51,11 @@ class ApplicationBreadcrumbsLogger { ...@@ -51,6 +51,11 @@ class ApplicationBreadcrumbsLogger {
std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_;
// Observes device orientation. // Observes device orientation.
id<NSObject> orientation_observer_; id<NSObject> orientation_observer_;
// Used to avoid logging the same orientation twice as well as logging
// UIDeviceOrientationUnknown on startup (the only place where "unknown"
// shows up). Fewer logs leave more room for more useful logs.
UIDeviceOrientation last_orientation_ = UIDeviceOrientationUnknown;
}; };
#endif // IOS_CHROME_BROWSER_CRASH_REPORT_BREADCRUMBS_APPLICATION_BREADCRUMBS_LOGGER_H_ #endif // IOS_CHROME_BROWSER_CRASH_REPORT_BREADCRUMBS_APPLICATION_BREADCRUMBS_LOGGER_H_
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
#import "ios/chrome/browser/crash_report/breadcrumbs/application_breadcrumbs_logger.h" #import "ios/chrome/browser/crash_report/breadcrumbs/application_breadcrumbs_logger.h"
#import <UIKit/UIKit.h>
#include "base/bind.h" #include "base/bind.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "ios/chrome/browser/crash_report/breadcrumbs/application_breadcrumbs_not_user_action.inc" #include "ios/chrome/browser/crash_report/breadcrumbs/application_breadcrumbs_not_user_action.inc"
...@@ -37,6 +35,10 @@ ApplicationBreadcrumbsLogger::ApplicationBreadcrumbsLogger( ...@@ -37,6 +35,10 @@ ApplicationBreadcrumbsLogger::ApplicationBreadcrumbsLogger(
object:nil object:nil
queue:nil queue:nil
usingBlock:^(NSNotification*) { usingBlock:^(NSNotification*) {
if (UIDevice.currentDevice.orientation == last_orientation_)
return;
last_orientation_ = UIDevice.currentDevice.orientation;
std::string event(kBreadcrumbOrientation); std::string event(kBreadcrumbOrientation);
switch (UIDevice.currentDevice.orientation) { switch (UIDevice.currentDevice.orientation) {
case UIDeviceOrientationUnknown: case UIDeviceOrientationUnknown:
......
...@@ -109,4 +109,10 @@ TEST_F(ApplicationBreadcrumbsLoggerTest, Orientation) { ...@@ -109,4 +109,10 @@ TEST_F(ApplicationBreadcrumbsLoggerTest, Orientation) {
EXPECT_NE(std::string::npos, events.back().find(kBreadcrumbOrientation)) EXPECT_NE(std::string::npos, events.back().find(kBreadcrumbOrientation))
<< events.back(); << events.back();
// Ensure that same orientation is not logged more than once.
[NSNotificationCenter.defaultCenter
postNotificationName:UIDeviceOrientationDidChangeNotification
object:nil];
EXPECT_EQ(2ul, breadcrumb_manager_.GetEvents(0).size());
} }
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