Chromium Code Reviews| Index: chrome/browser/profile_resetter/automatic_profile_resetter.h |
| diff --git a/chrome/browser/profile_resetter/automatic_profile_resetter.h b/chrome/browser/profile_resetter/automatic_profile_resetter.h |
| index 8dc9176d82c3b6f9915353fcf4c2de61d41b55fa..79ef6ef0351b21692a59f3d1dd87d8f24d4e8b24 100644 |
| --- a/chrome/browser/profile_resetter/automatic_profile_resetter.h |
| +++ b/chrome/browser/profile_resetter/automatic_profile_resetter.h |
| @@ -8,69 +8,95 @@ |
| #include <string> |
| #include "base/basictypes.h" |
| +#include "base/memory/ref_counted.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/memory/weak_ptr.h" |
| #include "base/strings/string_piece.h" |
| -#include "base/values.h" |
| +#include "base/task_runner.h" |
| #include "chrome/browser/profile_resetter/automatic_profile_resetter_mementos.h" |
| #include "components/browser_context_keyed_service/browser_context_keyed_service.h" |
| +class AutomaticProfileResetterDelegate; |
| class Profile; |
| -// Defines the interface for the delegate that will actually show the prompt |
| -// and/or report statistics on behalf of the AutomaticProfileResetter. |
| -// The primary reason for this separation is to facilitate unit testing. |
| -class AutomaticProfileResetterDelegate { |
| - public: |
| - virtual ~AutomaticProfileResetterDelegate() {} |
| - |
| - // Triggers showing the one-time profile settings reset prompt. |
| - virtual void ShowPrompt() = 0; |
| - |
| - // Reports the given metrics through UMA. |
| - virtual void ReportStatistics(uint32 satisfied_criteria_mask, |
| - uint32 combined_status_mask) = 0; |
| -}; |
| +namespace base { |
| +class DictionaryValue; |
| +class ListValue; |
| +} |
| // This service becomes busy shortly after start-up, and is responsible for |
| // evaluating if the criteria for showing the one-time profile reset prompt |
| // are satisfied, and will potentially trigger the prompt, but only a single |
| // time during the lifetime of a profile on disk (this is achieved by storing |
| -// "mementos"). All methods in this class shall be called on the UI thread. |
| +// "memento"-s, see "automatic_profile_resetter_mementos.h" for details). |
| +// All methods in this class shall be called on the UI thread. |
| class AutomaticProfileResetter : public BrowserContextKeyedService { |
| public: |
| + struct EvaluationResults; |
| + |
| + // Number of bits, and maximum value (exclusive) for the mask whose bits |
| + // indicate which of reset criteria were satisfied. |
| + static const size_t kSatisfiedCriteriaMaskNumberOfBits; |
| + static const uint32 kSatisfiedCriteriaMaskMaximumValue; |
| + |
| + // Number of bits, and maximum value (exclusive) for the mask whose bits |
| + // indicate if any of reset criteria were satisfied, and which of the mementos |
| + // were already present. |
| + static const size_t kCombinedStatusMaskNumberOfBits; |
| + static const uint32 kCombinedStatusMaskMaximumValue; |
| + |
| explicit AutomaticProfileResetter(Profile* profile); |
| virtual ~AutomaticProfileResetter(); |
| - // Initializes the service, and sets up the asynchronous evaluation flow. |
| - // Called by AutomaticProfileResetterFactory. |
| - void Initialize(); |
| + // Fires up the service by unleashing the asynchronous evaluation flow, unless |
| + // the service has been already disabled in Initialize() or there is no |
| + // |program_| to run (in which case the service also gets disabled). |
| + // Called by the AutomaticProfileResetterFactory. |
| + void Activate(); |
| - // Should be called after Initialize(). |
| + // Should be called before Activate(). |
| void SetHashSeedForTesting(const base::StringPiece& hash_seed); |
| - // Should be called after Initialize(). |
| + // Should be called before Activate(). |
| void SetProgramForTesting(const base::StringPiece& program); |
| - // Should be called after Initialize(). Takes ownership. |
| - void SetDelegateForTesting(AutomaticProfileResetterDelegate* delegate); |
| + // Should be called before Activate(). |
| + void SetDelegateForTesting( |
| + scoped_ptr<AutomaticProfileResetterDelegate> delegate); |
| - private: |
| - struct EvaluationResults; |
| + // Should be called before Activate(). Sets the task runner to be used to post |
| + // task |PrepareEvaluationFlow| in a delayed manner. |
| + void SetTaskRunnerForWaitingForTesting( |
| + const scoped_refptr<base::TaskRunner>& task_runner); |
| + private: |
| enum State { |
| STATE_UNINITIALIZED, |
| + STATE_INITIALIZED, |
| STATE_DISABLED, |
| + STATE_WAITING_ON_DEPENDENCIES, |
| STATE_READY, |
| STATE_WORKING, |
| STATE_DONE |
| }; |
| - // Returns whether or not a dry-run shall be performed. |
| - bool ShouldPerformDryRun() const; |
| + // Initializes the service if it is enabled in the field trial, otherwise, |
| + // skips the initialization steps and also permanently disables the service. |
| + void Initialize(); |
| + |
| + // Prepares the asynchronous evaluation flow by requesting services that it |
| + // depends on to make themselves ready. |
| + void PrepareEvaluationFlow(); |
| - // Returns whether or not a live-run shall be performed. |
| - bool ShouldPerformLiveRun() const; |
| + // Called back by |resetter_delegate_| when the template URL service is ready. |
| + void OnTemplateURLServiceIsLoaded(); |
| + |
| + // Called back by |resetter_delegate_| when the loaded modules have been |
| + // enumerated. |
| + void OnLoadedModulesAreEnumerated(); |
| + |
| + // Invoked by the above two methods. Kicks off the actual evaluation flow. |
| + void OnDependencyIsReady(); |
| // Begins the asynchronous evaluation flow, which will assess whether the |
| // criteria for showing the reset prompt are met, whether we have already |
| @@ -88,27 +114,24 @@ class AutomaticProfileResetter : public BrowserContextKeyedService { |
| scoped_ptr<base::DictionaryValue> BuildEvaluatorProgramInput( |
|
vasilii
2013/10/17 10:57:57
Order of declaration should math the order of defi
engedy
2013/10/17 15:13:47
Done.
|
| const std::string& memento_value_in_file); |
| - // Performs the bulk of the work. Invokes the interpreter to run the |program| |
| - // that will evaluate whether the conditions are met for showing the reset |
| - // prompt. The program will make this decision based on the state information |
| - // contained in |input| in the form of key-value pairs. The program will only |
| - // see hashed keys and values that are produced using |hash_seed| as a key. |
| - static scoped_ptr<EvaluationResults> EvaluateConditionsOnWorkerPoolThread( |
| - const base::StringPiece& hash_seed, |
| - const base::StringPiece& program, |
| - scoped_ptr<base::DictionaryValue> program_input); |
| - |
| // Called back when EvaluateConditionsOnWorkerPoolThread completes executing |
| // the program with |results|. Finishes the evaluation flow, and, based on the |
| // result, will potentially show the reset prompt. |
| void FinishEvaluationFlow(scoped_ptr<EvaluationResults> results); |
| - // BrowserContextKeyedService overrides: |
| + // Reports the given metrics through UMA. Virtual, so it can be mocked out in |
| + // tests to verify that the correct value are being reported. |
| + virtual void ReportStatistics(uint32 satisfied_criteria_mask, |
| + uint32 combined_status_mask); |
| + |
| + // BrowserContextKeyedService: |
| virtual void Shutdown() OVERRIDE; |
| Profile* profile_; |
| State state_; |
| + bool enumeration_of_loaded_modules_ready_; |
| + bool template_url_service_ready_; |
| base::StringPiece hash_seed_; |
| base::StringPiece program_; |
| @@ -118,6 +141,7 @@ class AutomaticProfileResetter : public BrowserContextKeyedService { |
| FileHostedPromptMemento memento_in_file_; |
| scoped_ptr<AutomaticProfileResetterDelegate> delegate_; |
| + scoped_refptr<base::TaskRunner> task_runner_for_waiting_; |
| base::WeakPtrFactory<AutomaticProfileResetter> weak_ptr_factory_; |