Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: chrome/browser/profile_resetter/automatic_profile_resetter.h

Issue 27030002: Added collecting of data to be fed to the JTL interpreter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor changes, plus added some additional unit-tests. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
vasilii 2013/10/14 16:43:33 Used here?
engedy 2013/10/14 19:35:50 Not really, forward declarations are enough. So re
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.
vasilii 2013/10/14 16:43:33 What is "mementos"?
engedy 2013/10/14 19:35:50 Added reference to where they are explained.
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;
vasilii 2013/10/14 16:43:33 kSatisfiedCriteriaMaskBitsCount or something. I al
engedy 2013/10/14 19:35:50 Done.
vasilii 2013/10/16 13:39:48 Does it say something about kCombinedStatusMaskBit
engedy 2013/10/16 15:12:17 As discussed, we will keep the size_t, as this is
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 Initialize() 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 Activate();
48 47
49 // Should be called after Initialize(). 48 // Should be called before Activate().
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 Activate().
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 Activate(). 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 // skips the initialization steps and also permanently disables the service.
72 void Initialize();
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;
vasilii 2013/10/14 16:43:33 Those two method shouldn't be in the header. They
engedy 2013/10/14 19:35:50 Done.
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 void OnTemplateURLServiceBecameReady();
82
83 // Called back by |resetter_delegate_| when the loaded modules have been
84 // enumerated.
85 void OnEnumerationOfLoadedModulesReady();
86
75 // Begins the asynchronous evaluation flow, which will assess whether the 87 // Begins the asynchronous evaluation flow, which will assess whether the
76 // criteria for showing the reset prompt are met, whether we have already 88 // 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. 89 // shown the prompt, and, in the end, will potentially trigger the prompt.
78 void BeginEvaluationFlow(); 90 void BeginEvaluationFlow();
79 91
80 // Called back by |memento_in_file_| once it has finished reading the value of 92 // 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 93 // the file-based memento. Continues the evaluation flow with collecting state
82 // information and assembling it as the input for the evaluator program. 94 // information and assembling it as the input for the evaluator program.
83 void ContinueWithEvaluationFlow(const std::string& memento_value_in_file); 95 void ContinueWithEvaluationFlow(const std::string& memento_value_in_file);
84 96
85 // Prepare the input of the evaluator program. This will contain all the state 97 // Prepare the input of the evaluator program. This will contain all the state
86 // information required to assess whether or not the conditions for showing 98 // information required to assess whether or not the conditions for showing
87 // the reset prompt are met. 99 // the reset prompt are met.
88 scoped_ptr<base::DictionaryValue> BuildEvaluatorProgramInput( 100 scoped_ptr<base::DictionaryValue> BuildEvaluatorProgramInput(
89 const std::string& memento_value_in_file); 101 const std::string& memento_value_in_file);
90 102
91 // Performs the bulk of the work. Invokes the interpreter to run the |program| 103 // Performs the bulk of the work. Invokes the interpreter to run the |program|
92 // that will evaluate whether the conditions are met for showing the reset 104 // that will evaluate whether the conditions are met for showing the reset
93 // prompt. The program will make this decision based on the state information 105 // prompt. The program will make this decision based on the state information
94 // contained in |input| in the form of key-value pairs. The program will only 106 // contained in |input| in the form of key-value pairs. The program will only
95 // see hashed keys and values that are produced using |hash_seed| as a key. 107 // see hashed keys and values that are produced using |hash_seed| as a key.
96 static scoped_ptr<EvaluationResults> EvaluateConditionsOnWorkerPoolThread( 108 static scoped_ptr<EvaluationResults> EvaluateConditionsOnWorkerPoolThread(
vasilii 2013/10/14 16:43:33 That one can be removed from the header too.
engedy 2013/10/14 19:35:50 Then we have to make the struct "EvaluationResults
vasilii 2013/10/16 13:39:48 Its definition will stay in .cc? Then it's OK.
engedy 2013/10/16 15:12:17 Done.
97 const base::StringPiece& hash_seed, 109 const base::StringPiece& hash_seed,
98 const base::StringPiece& program, 110 const base::StringPiece& program,
99 scoped_ptr<base::DictionaryValue> program_input); 111 scoped_ptr<base::DictionaryValue> program_input);
100 112
101 // Called back when EvaluateConditionsOnWorkerPoolThread completes executing 113 // Called back when EvaluateConditionsOnWorkerPoolThread completes executing
102 // the program with |results|. Finishes the evaluation flow, and, based on the 114 // the program with |results|. Finishes the evaluation flow, and, based on the
103 // result, will potentially show the reset prompt. 115 // result, will potentially show the reset prompt.
104 void FinishEvaluationFlow(scoped_ptr<EvaluationResults> results); 116 void FinishEvaluationFlow(scoped_ptr<EvaluationResults> results);
105 117
106 // BrowserContextKeyedService overrides: 118 // BrowserContextKeyedService overrides:
107 virtual void Shutdown() OVERRIDE; 119 virtual void Shutdown() OVERRIDE;
108 120
109 Profile* profile_; 121 Profile* profile_;
110 122
111 State state_; 123 State state_;
124 bool enumeration_of_loaded_modules_ready_;
125 bool template_url_service_ready_;
112 126
113 base::StringPiece hash_seed_; 127 base::StringPiece hash_seed_;
114 base::StringPiece program_; 128 base::StringPiece program_;
115 129
116 PreferenceHostedPromptMemento memento_in_prefs_; 130 PreferenceHostedPromptMemento memento_in_prefs_;
117 LocalStateHostedPromptMemento memento_in_local_state_; 131 LocalStateHostedPromptMemento memento_in_local_state_;
118 FileHostedPromptMemento memento_in_file_; 132 FileHostedPromptMemento memento_in_file_;
119 133
120 scoped_ptr<AutomaticProfileResetterDelegate> delegate_; 134 scoped_ptr<AutomaticProfileResetterDelegate> delegate_;
121 135
122 base::WeakPtrFactory<AutomaticProfileResetter> weak_ptr_factory_; 136 base::WeakPtrFactory<AutomaticProfileResetter> weak_ptr_factory_;
123 137
124 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetter); 138 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetter);
125 }; 139 };
126 140
127 #endif // CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_H_ 141 #endif // CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698