| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_H_ | 5 #ifndef CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_H_ |
| 6 #define CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_H_ | 6 #define CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 // The service is created automatically with the Profile and is activated right | 32 // The service is created automatically with the Profile and is activated right |
| 33 // away by its factory. To avoid delaying start-up, however, it will only start | 33 // away by its factory. To avoid delaying start-up, however, it will only start |
| 34 // working after a short delay. | 34 // working after a short delay. |
| 35 // All methods in this class shall be called on the UI thread, except when noted | 35 // All methods in this class shall be called on the UI thread, except when noted |
| 36 // otherwise. | 36 // otherwise. |
| 37 class AutomaticProfileResetter : public BrowserContextKeyedService { | 37 class AutomaticProfileResetter : public BrowserContextKeyedService { |
| 38 public: | 38 public: |
| 39 explicit AutomaticProfileResetter(Profile* profile); | 39 explicit AutomaticProfileResetter(Profile* profile); |
| 40 virtual ~AutomaticProfileResetter(); | 40 virtual ~AutomaticProfileResetter(); |
| 41 | 41 |
| 42 // Initializes the service if it is enabled in the field trial. Otherwise, |
| 43 // skips the initialization steps, and also permanently disables the service. |
| 44 // Called by AutomaticProfileResetterFactory. |
| 45 void Initialize(); |
| 46 |
| 42 // Fires up the service by unleashing the asynchronous evaluation flow, unless | 47 // Fires up the service by unleashing the asynchronous evaluation flow, unless |
| 43 // the service has been already disabled in Initialize() or there is no | 48 // the service has been already disabled in Initialize() or there is no |
| 44 // |program_| to run (in which case the service also gets disabled). | 49 // |program_| to run (in which case the service also gets disabled). |
| 45 // Called by the AutomaticProfileResetterFactory. | 50 // Called by the AutomaticProfileResetterFactory. |
| 46 void Activate(); | 51 void Activate(); |
| 47 | 52 |
| 48 // Should be called before Activate(). | 53 // Should be called before Activate(). |
| 49 void SetHashSeedForTesting(const base::StringPiece& hash_seed); | 54 void SetProgramForTesting(const std::string& program); |
| 50 | 55 |
| 51 // Should be called before Activate(). | 56 // Should be called before Activate(). |
| 52 void SetProgramForTesting(const base::StringPiece& program); | 57 void SetHashSeedForTesting(const std::string& hash_seed); |
| 53 | 58 |
| 54 // Should be called before Activate(). | 59 // Should be called before Activate(). |
| 55 void SetDelegateForTesting( | 60 void SetDelegateForTesting( |
| 56 scoped_ptr<AutomaticProfileResetterDelegate> delegate); | 61 scoped_ptr<AutomaticProfileResetterDelegate> delegate); |
| 57 | 62 |
| 58 // Should be called before Activate(). Sets the task runner to be used to post | 63 // Should be called before Activate(). Sets the task runner to be used to post |
| 59 // task |PrepareEvaluationFlow| in a delayed manner. | 64 // task |PrepareEvaluationFlow| in a delayed manner. |
| 60 void SetTaskRunnerForWaitingForTesting( | 65 void SetTaskRunnerForWaitingForTesting( |
| 61 const scoped_refptr<base::TaskRunner>& task_runner); | 66 const scoped_refptr<base::TaskRunner>& task_runner); |
| 62 | 67 |
| 63 private: | 68 private: |
| 64 struct EvaluationResults; | 69 struct EvaluationResults; |
| 65 | 70 |
| 66 enum State { | 71 enum State { |
| 67 STATE_UNINITIALIZED, | 72 STATE_UNINITIALIZED, |
| 68 STATE_INITIALIZED, | 73 STATE_INITIALIZED, |
| 69 STATE_DISABLED, | 74 STATE_DISABLED, |
| 70 STATE_WAITING_ON_DEPENDENCIES, | 75 STATE_WAITING_ON_DEPENDENCIES, |
| 71 STATE_READY, | 76 STATE_READY, |
| 72 STATE_WORKING, | 77 STATE_WORKING, |
| 73 STATE_DONE | 78 STATE_DONE |
| 74 }; | 79 }; |
| 75 | 80 |
| 76 // Initializes the service if it is enabled in the field trial, otherwise, | |
| 77 // skips the initialization steps and also permanently disables the service. | |
| 78 void Initialize(); | |
| 79 | |
| 80 // Prepares the asynchronous evaluation flow by requesting services that it | 81 // Prepares the asynchronous evaluation flow by requesting services that it |
| 81 // depends on to make themselves ready. | 82 // depends on to make themselves ready. |
| 82 void PrepareEvaluationFlow(); | 83 void PrepareEvaluationFlow(); |
| 83 | 84 |
| 84 // Called back by |resetter_delegate_| when the template URL service is ready. | 85 // Called back by |resetter_delegate_| when the template URL service is ready. |
| 85 void OnTemplateURLServiceIsLoaded(); | 86 void OnTemplateURLServiceIsLoaded(); |
| 86 | 87 |
| 87 // Called back by |resetter_delegate_| when the loaded modules have been | 88 // Called back by |resetter_delegate_| when the loaded modules have been |
| 88 // enumerated. | 89 // enumerated. |
| 89 void OnLoadedModulesAreEnumerated(); | 90 void OnLoadedModulesAreEnumerated(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 107 // information and assembling it as the input for the evaluator program. | 108 // information and assembling it as the input for the evaluator program. |
| 108 void ContinueWithEvaluationFlow(const std::string& memento_value_in_file); | 109 void ContinueWithEvaluationFlow(const std::string& memento_value_in_file); |
| 109 | 110 |
| 110 // Performs the bulk of the work. Invokes the JTL interpreter to run the | 111 // Performs the bulk of the work. Invokes the JTL interpreter to run the |
| 111 // |program| that will evaluate whether the conditions are met for showing the | 112 // |program| that will evaluate whether the conditions are met for showing the |
| 112 // reset prompt. The program will make this decision based on the state | 113 // reset prompt. The program will make this decision based on the state |
| 113 // information contained in |input| in the form of key-value pairs. The | 114 // information contained in |input| in the form of key-value pairs. The |
| 114 // program will only see hashed keys and values that are produced using | 115 // program will only see hashed keys and values that are produced using |
| 115 // |hash_seed| as a key. | 116 // |hash_seed| as a key. |
| 116 static scoped_ptr<EvaluationResults> EvaluateConditionsOnWorkerPoolThread( | 117 static scoped_ptr<EvaluationResults> EvaluateConditionsOnWorkerPoolThread( |
| 117 const base::StringPiece& hash_seed, | 118 const std::string& hash_seed, |
| 118 const base::StringPiece& program, | 119 const std::string& program, |
| 119 scoped_ptr<base::DictionaryValue> program_input); | 120 scoped_ptr<base::DictionaryValue> program_input); |
| 120 | 121 |
| 121 // Called back when EvaluateConditionsOnWorkerPoolThread completes executing | 122 // Called back when EvaluateConditionsOnWorkerPoolThread completes executing |
| 122 // the program with |results|. Finishes the evaluation flow, and, based on the | 123 // the program with |results|. Finishes the evaluation flow, and, based on the |
| 123 // result, will potentially show the reset prompt. | 124 // result, will potentially show the reset prompt. |
| 124 void FinishEvaluationFlow(scoped_ptr<EvaluationResults> results); | 125 void FinishEvaluationFlow(scoped_ptr<EvaluationResults> results); |
| 125 | 126 |
| 126 // Reports the given metrics through UMA. Virtual, so it can be mocked out in | 127 // Reports the given metrics through UMA. Virtual, so it can be mocked out in |
| 127 // tests to verify that the correct value are being reported. | 128 // tests to verify that the correct value are being reported. |
| 128 virtual void ReportStatistics(uint32 satisfied_criteria_mask, | 129 virtual void ReportStatistics(uint32 satisfied_criteria_mask, |
| 129 uint32 combined_status_mask); | 130 uint32 combined_status_mask); |
| 130 | 131 |
| 131 // BrowserContextKeyedService: | 132 // BrowserContextKeyedService: |
| 132 virtual void Shutdown() OVERRIDE; | 133 virtual void Shutdown() OVERRIDE; |
| 133 | 134 |
| 134 Profile* profile_; | 135 Profile* profile_; |
| 135 | 136 |
| 136 State state_; | 137 State state_; |
| 137 bool enumeration_of_loaded_modules_ready_; | 138 bool enumeration_of_loaded_modules_ready_; |
| 138 bool template_url_service_ready_; | 139 bool template_url_service_ready_; |
| 139 | 140 |
| 140 base::StringPiece hash_seed_; | 141 std::string hash_seed_; |
| 141 base::StringPiece program_; | 142 std::string program_; |
| 142 | 143 |
| 143 PreferenceHostedPromptMemento memento_in_prefs_; | 144 PreferenceHostedPromptMemento memento_in_prefs_; |
| 144 LocalStateHostedPromptMemento memento_in_local_state_; | 145 LocalStateHostedPromptMemento memento_in_local_state_; |
| 145 FileHostedPromptMemento memento_in_file_; | 146 FileHostedPromptMemento memento_in_file_; |
| 146 | 147 |
| 147 scoped_ptr<AutomaticProfileResetterDelegate> delegate_; | 148 scoped_ptr<AutomaticProfileResetterDelegate> delegate_; |
| 148 scoped_refptr<base::TaskRunner> task_runner_for_waiting_; | 149 scoped_refptr<base::TaskRunner> task_runner_for_waiting_; |
| 149 | 150 |
| 150 base::WeakPtrFactory<AutomaticProfileResetter> weak_ptr_factory_; | 151 base::WeakPtrFactory<AutomaticProfileResetter> weak_ptr_factory_; |
| 151 | 152 |
| 152 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetter); | 153 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetter); |
| 153 }; | 154 }; |
| 154 | 155 |
| 155 #endif // CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_H_ | 156 #endif // CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_H_ |
| OLD | NEW |