aw_feature_list_creator.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright 2017 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 ANDROID_WEBVIEW_BROWSER_AW_FEATURE_LIST_CREATOR_H_
  5. #define ANDROID_WEBVIEW_BROWSER_AW_FEATURE_LIST_CREATOR_H_
  6. #include <memory>
  7. #include <utility>
  8. #include "android_webview/browser/aw_browser_policy_connector.h"
  9. #include "android_webview/browser/aw_field_trials.h"
  10. #include "android_webview/browser/variations/aw_variations_service_client.h"
  11. #include "components/policy/core/browser/browser_policy_connector_base.h"
  12. #include "components/variations/service/variations_field_trial_creator.h"
  13. class PrefService;
  14. namespace android_webview {
  15. // Used by WebView to set up field trials based on the stored variations seed
  16. // data.
  17. class AwFeatureListCreator {
  18. public:
  19. AwFeatureListCreator();
  20. AwFeatureListCreator(const AwFeatureListCreator&) = delete;
  21. AwFeatureListCreator& operator=(const AwFeatureListCreator&) = delete;
  22. ~AwFeatureListCreator();
  23. // Initializes all necessary parameters to create the feature list and setup
  24. // field trials.
  25. void CreateFeatureListAndFieldTrials();
  26. void CreateLocalState();
  27. // Passes ownership of the |local_state_| to the caller.
  28. std::unique_ptr<PrefService> TakePrefService() {
  29. DCHECK(local_state_);
  30. return std::move(local_state_);
  31. }
  32. // Passes ownership of the |browser_policy_connector_| to the caller.
  33. std::unique_ptr<AwBrowserPolicyConnector> TakeBrowserPolicyConnector() {
  34. DCHECK(browser_policy_connector_);
  35. return std::move(browser_policy_connector_);
  36. }
  37. static void DisableSignatureVerificationForTesting();
  38. private:
  39. std::unique_ptr<PrefService> CreatePrefService();
  40. // Sets up the field trials and related initialization.
  41. void SetUpFieldTrials();
  42. // Stores the seed. VariationsSeedStore keeps a raw pointer to this, so it
  43. // must persist for the process lifetime. Not persisted accross runs.
  44. // If TakePrefService() is called, the caller will take the ownership
  45. // of this variable. Stop using this variable afterwards.
  46. std::unique_ptr<PrefService> local_state_;
  47. // Performs set up for any WebView specific field trials.
  48. std::unique_ptr<AwFieldTrials> aw_field_trials_;
  49. // Responsible for creating a feature list from the seed.
  50. std::unique_ptr<variations::VariationsFieldTrialCreator>
  51. variations_field_trial_creator_;
  52. std::unique_ptr<AwVariationsServiceClient> client_;
  53. std::unique_ptr<AwBrowserPolicyConnector> browser_policy_connector_;
  54. };
  55. } // namespace android_webview
  56. #endif // ANDROID_WEBVIEW_BROWSER_AW_FEATURE_LIST_CREATOR_H_