| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_METRICS_VARIATIONS_VARIATIONS_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SERVICE_H_ |
| 6 #define CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SERVICE_H_ | 6 #define CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SERVICE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // value coming from policy prefs. This should be called prior to any calls | 102 // value coming from policy prefs. This should be called prior to any calls |
| 103 // to |StartRepeatedVariationsSeedFetch|. | 103 // to |StartRepeatedVariationsSeedFetch|. |
| 104 void SetRestrictMode(const std::string& restrict_mode); | 104 void SetRestrictMode(const std::string& restrict_mode); |
| 105 | 105 |
| 106 // Exposed for testing. | 106 // Exposed for testing. |
| 107 void SetCreateTrialsFromSeedCalledForTesting(bool called); | 107 void SetCreateTrialsFromSeedCalledForTesting(bool called); |
| 108 | 108 |
| 109 // Returns the variations server URL, which can vary if a command-line flag is | 109 // Returns the variations server URL, which can vary if a command-line flag is |
| 110 // set and/or the variations restrict pref is set in |local_prefs|. Declared | 110 // set and/or the variations restrict pref is set in |local_prefs|. Declared |
| 111 // static for test purposes. | 111 // static for test purposes. |
| 112 static GURL GetVariationsServerURL(PrefService* local_prefs, | 112 GURL GetVariationsServerURL(PrefService* local_prefs, |
| 113 const std::string& restrict_mode_override); | 113 const std::string& restrict_mode_override); |
| 114 | 114 |
| 115 // Exposed for testing. | 115 // Exposed for testing. |
| 116 static std::string GetDefaultVariationsServerURLForTesting(); | 116 static std::string GetDefaultVariationsServerURLForTesting(); |
| 117 | 117 |
| 118 // Register Variations related prefs in Local State. | 118 // Register Variations related prefs in Local State. |
| 119 static void RegisterPrefs(PrefRegistrySimple* registry); | 119 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 120 | 120 |
| 121 // Register Variations related prefs in the Profile prefs. | 121 // Register Variations related prefs in the Profile prefs. |
| 122 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 122 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 123 | 123 |
| 124 // Factory method for creating a VariationsService. Does not take ownership of | 124 // Factory method for creating a VariationsService. Does not take ownership of |
| 125 // |state_manager|. Caller should ensure that |state_manager| is valid for the | 125 // |state_manager|. Caller should ensure that |state_manager| is valid for the |
| 126 // lifetime of this class. | 126 // lifetime of this class. |
| 127 static scoped_ptr<VariationsService> Create( | 127 static scoped_ptr<VariationsService> Create( |
| 128 scoped_ptr<VariationsServiceClient> client, | 128 scoped_ptr<VariationsServiceClient> client, |
| 129 PrefService* local_state, | 129 PrefService* local_state, |
| 130 metrics::MetricsStateManager* state_manager, | 130 metrics::MetricsStateManager* state_manager, |
| 131 const char* disable_network_switch); | 131 const char* disable_network_switch); |
| 132 | 132 |
| 133 // Factory method for creating a VariationsService in a testing context. |
| 134 static scoped_ptr<VariationsService> CreateForTesting( |
| 135 scoped_ptr<VariationsServiceClient> client, |
| 136 PrefService* local_state); |
| 137 |
| 133 // Set the PrefService responsible for getting policy-related preferences, | 138 // Set the PrefService responsible for getting policy-related preferences, |
| 134 // such as the restrict parameter. | 139 // such as the restrict parameter. |
| 135 void set_policy_pref_service(PrefService* service) { | 140 void set_policy_pref_service(PrefService* service) { |
| 136 DCHECK(service); | 141 DCHECK(service); |
| 137 policy_pref_service_ = service; | 142 policy_pref_service_ = service; |
| 138 } | 143 } |
| 139 | 144 |
| 140 // Returns the invalid variations seed signature in base64 format, or an empty | 145 // Returns the invalid variations seed signature in base64 format, or an empty |
| 141 // string if the signature was valid, missing, or if signature verification is | 146 // string if the signature was valid, missing, or if signature verification is |
| 142 // disabled. | 147 // disabled. |
| 143 std::string GetInvalidVariationsSeedSignature() const; | 148 std::string GetInvalidVariationsSeedSignature() const; |
| 144 | 149 |
| 145 protected: | 150 protected: |
| 146 // Starts the fetching process once, where |OnURLFetchComplete| is called with | 151 // Starts the fetching process once, where |OnURLFetchComplete| is called with |
| 147 // the response. | 152 // the response. |
| 148 virtual void DoActualFetch(); | 153 virtual void DoActualFetch(); |
| 149 | 154 |
| 150 // Stores the seed to prefs. Set as virtual and protected so that it can be | 155 // Stores the seed to prefs. Set as virtual and protected so that it can be |
| 151 // overridden by tests. | 156 // overridden by tests. |
| 152 virtual bool StoreSeed(const std::string& seed_data, | 157 virtual bool StoreSeed(const std::string& seed_data, |
| 153 const std::string& seed_signature, | 158 const std::string& seed_signature, |
| 154 const std::string& country_code, | 159 const std::string& country_code, |
| 155 const base::Time& date_fetched, | 160 const base::Time& date_fetched, |
| 156 bool is_delta_compressed); | 161 bool is_delta_compressed); |
| 157 | 162 |
| 158 // Creates the VariationsService with the given |local_state| prefs service | 163 // Creates the VariationsService with the given |local_state| prefs service |
| 159 // and |state_manager|. This instance will take ownership of |notifier|. | 164 // and |state_manager|. Does not take ownership of |state_manager|. Caller |
| 160 // Does not take ownership of |state_manager|. Caller should ensure that | 165 // should ensure that |state_manager| is valid for the lifetime of this class. |
| 161 // |state_manager| is valid for the lifetime of this class. Use the |Create| | 166 // Use the |Create| factory method to create a VariationsService. |
| 162 // factory method to create a VariationsService. | 167 VariationsService( |
| 163 VariationsService(scoped_ptr<VariationsServiceClient> client, | 168 scoped_ptr<VariationsServiceClient> client, |
| 164 web_resource::ResourceRequestAllowedNotifier* notifier, | 169 scoped_ptr<web_resource::ResourceRequestAllowedNotifier> notifier, |
| 165 PrefService* local_state, | 170 PrefService* local_state, |
| 166 metrics::MetricsStateManager* state_manager); | 171 metrics::MetricsStateManager* state_manager); |
| 167 | 172 |
| 168 private: | 173 private: |
| 169 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, Observer); | 174 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, Observer); |
| 170 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, SeedStoredWhenOKStatus); | 175 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, SeedStoredWhenOKStatus); |
| 171 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, SeedNotStoredWhenNonOKStatus); | 176 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, SeedNotStoredWhenNonOKStatus); |
| 172 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, SeedDateUpdatedOn304Status); | 177 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, SeedDateUpdatedOn304Status); |
| 173 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, | 178 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, |
| 174 LoadPermanentConsistencyCountry); | 179 LoadPermanentConsistencyCountry); |
| 175 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CountryHeader); | 180 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CountryHeader); |
| 176 | 181 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 base::ThreadChecker thread_checker_; | 289 base::ThreadChecker thread_checker_; |
| 285 | 290 |
| 286 base::WeakPtrFactory<VariationsService> weak_ptr_factory_; | 291 base::WeakPtrFactory<VariationsService> weak_ptr_factory_; |
| 287 | 292 |
| 288 DISALLOW_COPY_AND_ASSIGN(VariationsService); | 293 DISALLOW_COPY_AND_ASSIGN(VariationsService); |
| 289 }; | 294 }; |
| 290 | 295 |
| 291 } // namespace chrome_variations | 296 } // namespace chrome_variations |
| 292 | 297 |
| 293 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SERVICE_H_ | 298 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SERVICE_H_ |
| OLD | NEW |