Chromium Code Reviews| 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" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/profile_resetter/automatic_profile_resetter_mementos.h" | 15 #include "chrome/browser/profile_resetter/automatic_profile_resetter_mementos.h" |
| 16 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" | 16 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" |
| 17 | 17 |
| 18 class AutomaticProfileResetterDelegate; | |
| 18 class Profile; | 19 class Profile; |
| 19 | 20 |
| 20 // Defines the interface for the delegate that will actually show the prompt | |
| 21 // and/or report statistics on behalf of the AutomaticProfileResetter. | |
| 22 // The primary reason for this separation is to facilitate unit testing. | |
| 23 class AutomaticProfileResetterDelegate { | |
| 24 public: | |
| 25 virtual ~AutomaticProfileResetterDelegate() {} | |
| 26 | |
| 27 // Triggers showing the one-time profile settings reset prompt. | |
| 28 virtual void ShowPrompt() = 0; | |
| 29 | |
| 30 // Reports the given metrics through UMA. | |
| 31 virtual void ReportStatistics(uint32 satisfied_criteria_mask, | |
| 32 uint32 combined_status_mask) = 0; | |
| 33 }; | |
| 34 | |
| 35 // This service becomes busy shortly after start-up, and is responsible for | 21 // This service becomes busy shortly after start-up, and is responsible for |
| 36 // evaluating if the criteria for showing the one-time profile reset prompt | 22 // evaluating if the criteria for showing the one-time profile reset prompt |
| 37 // are satisfied, and will potentially trigger the prompt, but only a single | 23 // are satisfied, and will potentially trigger the prompt, but only a single |
| 38 // time during the lifetime of a profile on disk (this is achieved by storing | 24 // time during the lifetime of a profile on disk (this is achieved by storing |
| 39 // "mementos"). All methods in this class shall be called on the UI thread. | 25 // "mementos"). All methods in this class shall be called on the UI thread. |
| 40 class AutomaticProfileResetter : public BrowserContextKeyedService { | 26 class AutomaticProfileResetter : public BrowserContextKeyedService { |
| 41 public: | 27 public: |
| 28 // Number of bits, and maximum value (exclusive) for the mask whose bits | |
| 29 // indicate which of reset criteria were satisfied. | |
| 30 static const size_t kSatisfiedCriteriaMaskBits; | |
| 31 static const uint32 kSatisfiedCriteriaMaskMaximumValue; | |
| 32 | |
| 33 // Number of bits, and maximum value (exclusive) for the mask whose bits | |
| 34 // indicate if any of reset criteria were satisfied, and which of the mementos | |
| 35 // were already present. | |
| 36 static const size_t kCombinedStatusMaskBits; | |
| 37 static const uint32 kCombinedStatusMaskMaximumValue; | |
| 38 | |
| 42 explicit AutomaticProfileResetter(Profile* profile); | 39 explicit AutomaticProfileResetter(Profile* profile); |
| 43 virtual ~AutomaticProfileResetter(); | 40 virtual ~AutomaticProfileResetter(); |
| 44 | 41 |
| 45 // Initializes the service, and sets up the asynchronous evaluation flow. | 42 // Fires up the service by unleashing the asynchronous evaluation flow, unless |
| 46 // Called by AutomaticProfileResetterFactory. | 43 // the service has been already disabled in MaybeInitialize() or there is no |
| 47 void Initialize(); | 44 // |program_| to run (in which case the service also gets disabled). |
| 45 // Called by the AutomaticProfileResetterFactory. | |
| 46 void MaybeActivate(); | |
|
battre
2013/10/11 15:05:33
nit: I think I would prefer to drop the Maybe here
engedy
2013/10/11 16:42:16
Done.
| |
| 48 | 47 |
| 49 // Should be called after Initialize(). | 48 // Should be called before MaybeActivate(). |
| 50 void SetHashSeedForTesting(const base::StringPiece& hash_seed); | 49 void SetHashSeedForTesting(const base::StringPiece& hash_seed); |
| 51 | 50 |
| 52 // Should be called after Initialize(). | 51 // Should be called before MaybeActivate(). |
| 53 void SetProgramForTesting(const base::StringPiece& program); | 52 void SetProgramForTesting(const base::StringPiece& program); |
| 54 | 53 |
| 55 // Should be called after Initialize(). Takes ownership. | 54 // Should be called before MaybeActivate(). Takes ownership. |
| 56 void SetDelegateForTesting(AutomaticProfileResetterDelegate* delegate); | 55 void SetDelegateForTesting(AutomaticProfileResetterDelegate* delegate); |
| 57 | 56 |
| 58 private: | 57 private: |
| 59 struct EvaluationResults; | 58 struct EvaluationResults; |
| 60 | 59 |
| 61 enum State { | 60 enum State { |
| 62 STATE_UNINITIALIZED, | 61 STATE_UNINITIALIZED, |
| 62 STATE_INITIALIZED, | |
| 63 STATE_DISABLED, | 63 STATE_DISABLED, |
| 64 STATE_WAITING_ON_SERVICES, | |
| 64 STATE_READY, | 65 STATE_READY, |
| 65 STATE_WORKING, | 66 STATE_WORKING, |
| 66 STATE_DONE | 67 STATE_DONE |
| 67 }; | 68 }; |
| 68 | 69 |
| 70 // Initializes the service if it is enabled in the field trial. Otherwise, | |
| 71 // permanently disables the service and also skips the initialization steps. | |
| 72 void MaybeInitialize(); | |
| 73 | |
| 69 // Returns whether or not a dry-run shall be performed. | 74 // Returns whether or not a dry-run shall be performed. |
| 70 bool ShouldPerformDryRun() const; | 75 bool ShouldPerformDryRun() const; |
| 71 | 76 |
| 72 // Returns whether or not a live-run shall be performed. | 77 // Returns whether or not a live-run shall be performed. |
| 73 bool ShouldPerformLiveRun() const; | 78 bool ShouldPerformLiveRun() const; |
| 74 | 79 |
| 80 // Called back by |resetter_delegate_| when the template URL service is ready. | |
| 81 // Unleashes the asynchronous evaluation flow. | |
| 82 void OnTemplateURLServiceBecameReady(); | |
| 83 | |
| 75 // Begins the asynchronous evaluation flow, which will assess whether the | 84 // Begins the asynchronous evaluation flow, which will assess whether the |
| 76 // criteria for showing the reset prompt are met, whether we have already | 85 // criteria for showing the reset prompt are met, whether we have already |
| 77 // shown the prompt, and, in the end, will potentially trigger the prompt. | 86 // shown the prompt, and, in the end, will potentially trigger the prompt. |
| 78 void BeginEvaluationFlow(); | 87 void BeginEvaluationFlow(); |
| 79 | 88 |
| 80 // Called back by |memento_in_file_| once it has finished reading the value of | 89 // Called back by |memento_in_file_| once it has finished reading the value of |
| 81 // the file-based memento. Continues the evaluation flow with collecting state | 90 // the file-based memento. Continues the evaluation flow with collecting state |
| 82 // information and assembling it as the input for the evaluator program. | 91 // information and assembling it as the input for the evaluator program. |
| 83 void ContinueWithEvaluationFlow(const std::string& memento_value_in_file); | 92 void ContinueWithEvaluationFlow(const std::string& memento_value_in_file); |
| 84 | 93 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 FileHostedPromptMemento memento_in_file_; | 127 FileHostedPromptMemento memento_in_file_; |
| 119 | 128 |
| 120 scoped_ptr<AutomaticProfileResetterDelegate> delegate_; | 129 scoped_ptr<AutomaticProfileResetterDelegate> delegate_; |
| 121 | 130 |
| 122 base::WeakPtrFactory<AutomaticProfileResetter> weak_ptr_factory_; | 131 base::WeakPtrFactory<AutomaticProfileResetter> weak_ptr_factory_; |
| 123 | 132 |
| 124 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetter); | 133 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetter); |
| 125 }; | 134 }; |
| 126 | 135 |
| 127 #endif // CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_H_ | 136 #endif // CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_H_ |
| OLD | NEW |