| 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 IOS_CHROME_BROWSER_BROWSER_STATE_TEST_CHROME_BROWSER_STATE_H_ | 5 #ifndef IOS_CHROME_BROWSER_BROWSER_STATE_TEST_CHROME_BROWSER_STATE_H_ |
| 6 #define IOS_CHROME_BROWSER_BROWSER_STATE_TEST_CHROME_BROWSER_STATE_H_ | 6 #define IOS_CHROME_BROWSER_BROWSER_STATE_TEST_CHROME_BROWSER_STATE_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 8 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/macros.h" | 12 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "components/keyed_service/ios/browser_state_keyed_service_factory.h" | 13 #include "components/keyed_service/ios/browser_state_keyed_service_factory.h" |
| 13 #include "components/keyed_service/ios/refcounted_browser_state_keyed_service_fa
ctory.h" | 14 #include "components/keyed_service/ios/refcounted_browser_state_keyed_service_fa
ctory.h" |
| 14 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 15 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 15 #include "ios/chrome/browser/net/net_types.h" | 16 #include "ios/chrome/browser/net/net_types.h" |
| 16 | 17 |
| 17 namespace syncable_prefs { | 18 namespace syncable_prefs { |
| 18 class PrefServiceSyncable; | 19 class PrefServiceSyncable; |
| 19 class TestingPrefServiceSyncable; | 20 class TestingPrefServiceSyncable; |
| 20 } | 21 } |
| 21 | 22 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 BrowserStateKeyedServiceFactory::TestingFactoryFunction cb); | 103 BrowserStateKeyedServiceFactory::TestingFactoryFunction cb); |
| 103 void AddTestingFactory( | 104 void AddTestingFactory( |
| 104 RefcountedBrowserStateKeyedServiceFactory* service_factory, | 105 RefcountedBrowserStateKeyedServiceFactory* service_factory, |
| 105 RefcountedBrowserStateKeyedServiceFactory::TestingFactoryFunction cb); | 106 RefcountedBrowserStateKeyedServiceFactory::TestingFactoryFunction cb); |
| 106 | 107 |
| 107 // Sets the path to the directory to be used to hold ChromeBrowserState | 108 // Sets the path to the directory to be used to hold ChromeBrowserState |
| 108 // data. | 109 // data. |
| 109 void SetPath(const base::FilePath& path); | 110 void SetPath(const base::FilePath& path); |
| 110 | 111 |
| 111 // Sets the PrefService to be used by the ChromeBrowserState. | 112 // Sets the PrefService to be used by the ChromeBrowserState. |
| 112 void SetPrefService(scoped_ptr<syncable_prefs::PrefServiceSyncable> prefs); | 113 void SetPrefService( |
| 114 std::unique_ptr<syncable_prefs::PrefServiceSyncable> prefs); |
| 113 | 115 |
| 114 // Creates the TestChromeBrowserState using previously-set settings. | 116 // Creates the TestChromeBrowserState using previously-set settings. |
| 115 scoped_ptr<TestChromeBrowserState> Build(); | 117 std::unique_ptr<TestChromeBrowserState> Build(); |
| 116 | 118 |
| 117 private: | 119 private: |
| 118 // If true, Build() has been called. | 120 // If true, Build() has been called. |
| 119 bool build_called_; | 121 bool build_called_; |
| 120 | 122 |
| 121 // Various staging variables where values are held until Build() is invoked. | 123 // Various staging variables where values are held until Build() is invoked. |
| 122 base::FilePath state_path_; | 124 base::FilePath state_path_; |
| 123 scoped_ptr<syncable_prefs::PrefServiceSyncable> pref_service_; | 125 std::unique_ptr<syncable_prefs::PrefServiceSyncable> pref_service_; |
| 124 | 126 |
| 125 TestingFactories testing_factories_; | 127 TestingFactories testing_factories_; |
| 126 RefcountedTestingFactories refcounted_testing_factories_; | 128 RefcountedTestingFactories refcounted_testing_factories_; |
| 127 | 129 |
| 128 DISALLOW_COPY_AND_ASSIGN(Builder); | 130 DISALLOW_COPY_AND_ASSIGN(Builder); |
| 129 }; | 131 }; |
| 130 | 132 |
| 131 protected: | 133 protected: |
| 132 // Used to create the principal TestChromeBrowserState. | 134 // Used to create the principal TestChromeBrowserState. |
| 133 TestChromeBrowserState( | 135 TestChromeBrowserState( |
| 134 const base::FilePath& path, | 136 const base::FilePath& path, |
| 135 scoped_ptr<syncable_prefs::PrefServiceSyncable> prefs, | 137 std::unique_ptr<syncable_prefs::PrefServiceSyncable> prefs, |
| 136 const TestingFactories& testing_factories, | 138 const TestingFactories& testing_factories, |
| 137 const RefcountedTestingFactories& refcounted_testing_factories); | 139 const RefcountedTestingFactories& refcounted_testing_factories); |
| 138 | 140 |
| 139 private: | 141 private: |
| 140 friend class Builder; | 142 friend class Builder; |
| 141 | 143 |
| 142 // Used to create the incognito TestChromeBrowserState. | 144 // Used to create the incognito TestChromeBrowserState. |
| 143 explicit TestChromeBrowserState( | 145 explicit TestChromeBrowserState( |
| 144 TestChromeBrowserState* original_browser_state); | 146 TestChromeBrowserState* original_browser_state); |
| 145 | 147 |
| 146 // Initialization of the TestChromeBrowserState. This is a separate method | 148 // Initialization of the TestChromeBrowserState. This is a separate method |
| 147 // as it needs to be called after the bi-directional link between original | 149 // as it needs to be called after the bi-directional link between original |
| 148 // and off-the-record TestChromeBrowserState has been created. | 150 // and off-the-record TestChromeBrowserState has been created. |
| 149 void Init(); | 151 void Init(); |
| 150 | 152 |
| 151 // We use a temporary directory to store testing browser state data. | 153 // We use a temporary directory to store testing browser state data. |
| 152 // This must be declared before anything that may make use of the | 154 // This must be declared before anything that may make use of the |
| 153 // directory so as to ensure files are closed before cleanup. | 155 // directory so as to ensure files are closed before cleanup. |
| 154 base::ScopedTempDir temp_dir_; | 156 base::ScopedTempDir temp_dir_; |
| 155 | 157 |
| 156 // The path to this browser state. | 158 // The path to this browser state. |
| 157 base::FilePath state_path_; | 159 base::FilePath state_path_; |
| 158 | 160 |
| 159 // If non-null, |testing_prefs_| points to |prefs_|. It is there to avoid | 161 // If non-null, |testing_prefs_| points to |prefs_|. It is there to avoid |
| 160 // casting as |prefs_| may not be a TestingPrefServiceSyncable. | 162 // casting as |prefs_| may not be a TestingPrefServiceSyncable. |
| 161 scoped_ptr<syncable_prefs::PrefServiceSyncable> prefs_; | 163 std::unique_ptr<syncable_prefs::PrefServiceSyncable> prefs_; |
| 162 syncable_prefs::TestingPrefServiceSyncable* testing_prefs_; | 164 syncable_prefs::TestingPrefServiceSyncable* testing_prefs_; |
| 163 | 165 |
| 164 // The incognito ChromeBrowserState instance that is associated with this | 166 // The incognito ChromeBrowserState instance that is associated with this |
| 165 // non-incognito ChromeBrowserState instance. | 167 // non-incognito ChromeBrowserState instance. |
| 166 scoped_ptr<TestChromeBrowserState> otr_browser_state_; | 168 std::unique_ptr<TestChromeBrowserState> otr_browser_state_; |
| 167 TestChromeBrowserState* original_browser_state_; | 169 TestChromeBrowserState* original_browser_state_; |
| 168 | 170 |
| 169 DISALLOW_COPY_AND_ASSIGN(TestChromeBrowserState); | 171 DISALLOW_COPY_AND_ASSIGN(TestChromeBrowserState); |
| 170 }; | 172 }; |
| 171 | 173 |
| 172 #endif // IOS_CHROME_BROWSER_BROWSER_STATE_TEST_CHROME_BROWSER_STATE_H_ | 174 #endif // IOS_CHROME_BROWSER_BROWSER_STATE_TEST_CHROME_BROWSER_STATE_H_ |
| OLD | NEW |