cross_otr_tab_helper.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_URL_PARAM_FILTER_IOS_CROSS_OTR_TAB_HELPER_H_
  5. #define COMPONENTS_URL_PARAM_FILTER_IOS_CROSS_OTR_TAB_HELPER_H_
  6. #include "components/url_param_filter/core/cross_otr_observer.h"
  7. #include "components/url_param_filter/core/url_param_filterer.h"
  8. #include "ios/web/public/navigation/navigation_context.h"
  9. #include "ios/web/public/web_state.h"
  10. #include "ios/web/public/web_state_observer.h"
  11. #include "ios/web/public/web_state_user_data.h"
  12. #include "ui/base/page_transition_types.h"
  13. namespace web {
  14. class WebState;
  15. class NavigationContext;
  16. } // namespace web
  17. namespace url_param_filter {
  18. // This class is created to measure the effect of experimentally filtering
  19. // URLs. It is only attached to WebStates created via an "Open In Incognito"
  20. // press.
  21. //
  22. // The state-machine logic measuring refreshes in class should be kept in sync
  23. // with the CrossOtrObserver at components/url_param_filter/content/ which
  24. // performs similar observations.
  25. class CrossOtrTabHelper : public CrossOtrObserver,
  26. public web::WebStateObserver,
  27. public web::WebStateUserData<CrossOtrTabHelper> {
  28. public:
  29. ~CrossOtrTabHelper() override;
  30. // Attaches the observer in cases where it should do so; leaves `web_state`
  31. // unchanged otherwise.
  32. static void CreateForWebState(web::WebState* web_state);
  33. // web::WebStateObserver:
  34. void DidStartNavigation(web::WebState* web_state,
  35. web::NavigationContext* navigation_context) override;
  36. void DidFinishNavigation(web::WebState* web_state,
  37. web::NavigationContext* navigation_context) override;
  38. void WebStateDestroyed(web::WebState* web_state) override;
  39. // Returns whether this observer is in Cross-OTR state, used for testing.
  40. bool GetCrossOtrStateForTesting() const;
  41. // Stores the experimental status of the params being filtered for use in
  42. // sending metrics.
  43. void SetExperimentalStatus(ClassificationExperimentStatus status);
  44. private:
  45. CrossOtrTabHelper(web::WebState* web_state);
  46. friend class WebStateUserData<CrossOtrTabHelper>;
  47. // Flushes metrics and removes the observer from the WebState.
  48. void Detach(web::WebState* web_state);
  49. WEB_STATE_USER_DATA_KEY_DECL();
  50. };
  51. } // namespace url_param_filter
  52. #endif // COMPONENTS_URL_PARAM_FILTER_IOS_CROSS_OTR_TAB_HELPER_H_