diff options
Diffstat (limited to 'chromium/content/browser/conversions/conversion_manager.h')
-rw-r--r-- | chromium/content/browser/conversions/conversion_manager.h | 110 |
1 files changed, 59 insertions, 51 deletions
diff --git a/chromium/content/browser/conversions/conversion_manager.h b/chromium/content/browser/conversions/conversion_manager.h index fe132c41e2c..ca1e1a041f8 100644 --- a/chromium/content/browser/conversions/conversion_manager.h +++ b/chromium/content/browser/conversions/conversion_manager.h @@ -5,68 +5,76 @@ #ifndef CONTENT_BROWSER_CONVERSIONS_CONVERSION_MANAGER_H_ #define CONTENT_BROWSER_CONVERSIONS_CONVERSION_MANAGER_H_ -#include <memory> +#include <vector> -#include "base/files/file_path.h" -#include "base/macros.h" -#include "base/memory/scoped_refptr.h" -#include "base/memory/weak_ptr.h" -#include "base/sequenced_task_runner.h" +#include "base/callback.h" +#include "base/callback_forward.h" #include "content/browser/conversions/conversion_policy.h" -#include "content/browser/conversions/conversion_storage.h" +#include "content/browser/conversions/conversion_report.h" #include "content/browser/conversions/storable_conversion.h" - -namespace base { -class Clock; -} // namespace base +#include "content/browser/conversions/storable_impression.h" +#include "content/common/content_export.h" +#include "url/origin.h" namespace content { -class ConversionStorage; +class WebContents; -// UI thread class that manages the lifetime of the underlying conversion -// storage. Owned by the storage partition. -class ConversionManager : public ConversionStorage::Delegate { +// Interface that mediates data flow between the network, storage layer, and +// blink. +class CONTENT_EXPORT ConversionManager { public: - // |storage_task_runner| should run with base::TaskPriority::BEST_EFFORT. - ConversionManager( - const base::FilePath& user_data_directory, - scoped_refptr<base::SequencedTaskRunner> storage_task_runner); - ConversionManager(const ConversionManager& other) = delete; - ConversionManager& operator=(const ConversionManager& other) = delete; - ~ConversionManager() override; + // Provides access to a ConversionManager implementation. This layer of + // abstraction is to allow tests to mock out the ConversionManager without + // injecting a manager explicitly. + class Provider { + public: + virtual ~Provider() = default; + + // Gets the ConversionManager that should be used for handling conversions + // that occur in the given |web_contents|. Returns nullptr if conversion + // measurement is not enabled in the given |web_contents|, e.g. when the + // browser context is off the record. + virtual ConversionManager* GetManager(WebContents* web_contents) const = 0; + }; + virtual ~ConversionManager() = default; + + // Persists the given |impression| to storage. Called when a navigation + // originating from an impression tag finishes. + virtual void HandleImpression(const StorableImpression& impression) = 0; // Process a newly registered conversion. Will create and log any new // conversion reports to storage. - void HandleConversion(const StorableConversion& conversion); - - const ConversionPolicy& GetConversionPolicy() const; - - private: - // ConversionStorageDelegate - void ProcessNewConversionReports( - std::vector<ConversionReport>* reports) override; - int GetMaxConversionsPerImpression() const override; - - void OnInitCompleted(bool success); - - // Task runner used to perform operations on |storage_|. Runs with - // base::TaskPriority::BEST_EFFORT. - scoped_refptr<base::SequencedTaskRunner> storage_task_runner_; - - base::Clock* clock_; - - // ConversionStorage instance which is scoped to lifetime of - // |storage_task_runner_|. |storage_| should be accessed by calling - // base::PostTask with |storage_task_runner_|, and should not be accessed - // directly. - std::unique_ptr<ConversionStorage, base::OnTaskRunnerDeleter> storage_; - - // Policy used for controlling API configurations such as reporting and - // attribution models. Unique ptr so it can be overridden for testing. - std::unique_ptr<ConversionPolicy> conversion_policy_; - - base::WeakPtrFactory<ConversionManager> weak_factory_; + virtual void HandleConversion(const StorableConversion& conversion) = 0; + + // Get all impressions that are currently stored in this partition. Used for + // populating WebUI. + virtual void GetActiveImpressionsForWebUI( + base::OnceCallback<void(std::vector<StorableImpression>)> callback) = 0; + + // Get all pending reports that are currently stored in this partition. Used + // for populating WebUI. + virtual void GetReportsForWebUI( + base::OnceCallback<void(std::vector<ConversionReport>)> callback, + base::Time max_report_time) = 0; + + // Sends all pending reports immediately, and runs |done| once they have all + // been sent. + virtual void SendReportsForWebUI(base::OnceClosure done) = 0; + + // Returns the ConversionPolicy that is used to control API policies such + // as noise. + virtual const ConversionPolicy& GetConversionPolicy() const = 0; + + // Deletes all data in storage for URLs matching |filter|, between + // |delete_begin| and |delete_end| time. + // + // If |filter| is null, then consider all origins in storage as matching. + virtual void ClearData( + base::Time delete_begin, + base::Time delete_end, + base::RepeatingCallback<bool(const url::Origin&)> filter, + base::OnceClosure done) = 0; }; } // namespace content |