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_CHROMEOS_DRIVE_DRIVE_INTEGRATION_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_INTEGRATION_SERVICE_H_ |
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_INTEGRATION_SERVICE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_INTEGRATION_SERVICE_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 181 |
182 // Singleton that owns all instances of DriveIntegrationService and | 182 // Singleton that owns all instances of DriveIntegrationService and |
183 // associates them with Profiles. | 183 // associates them with Profiles. |
184 class DriveIntegrationServiceFactory | 184 class DriveIntegrationServiceFactory |
185 : public BrowserContextKeyedServiceFactory { | 185 : public BrowserContextKeyedServiceFactory { |
186 public: | 186 public: |
187 // Factory function used by tests. | 187 // Factory function used by tests. |
188 typedef base::Callback<DriveIntegrationService*(Profile* profile)> | 188 typedef base::Callback<DriveIntegrationService*(Profile* profile)> |
189 FactoryCallback; | 189 FactoryCallback; |
190 | 190 |
| 191 // Sets and resets a factory function for tests. See below for why we can't |
| 192 // use BrowserContextKeyedServiceFactory::SetTestingFactory(). |
| 193 class ScopedFactoryForTest { |
| 194 public: |
| 195 explicit ScopedFactoryForTest(FactoryCallback* factory_for_test); |
| 196 ~ScopedFactoryForTest(); |
| 197 }; |
| 198 |
191 // Returns the DriveIntegrationService for |profile|, creating it if it is | 199 // Returns the DriveIntegrationService for |profile|, creating it if it is |
192 // not yet created. | 200 // not yet created. |
193 static DriveIntegrationService* GetForProfile(Profile* profile); | 201 static DriveIntegrationService* GetForProfile(Profile* profile); |
194 | 202 |
195 // Same as GetForProfile. TODO(hidehiko): Remove this. | 203 // Same as GetForProfile. TODO(hidehiko): Remove this. |
196 static DriveIntegrationService* GetForProfileRegardlessOfStates( | 204 static DriveIntegrationService* GetForProfileRegardlessOfStates( |
197 Profile* profile); | 205 Profile* profile); |
198 | 206 |
199 // Returns the DriveIntegrationService that is already associated with | 207 // Returns the DriveIntegrationService that is already associated with |
200 // |profile|, if it is not yet created it will return NULL. | 208 // |profile|, if it is not yet created it will return NULL. |
201 static DriveIntegrationService* FindForProfile(Profile* profile); | 209 static DriveIntegrationService* FindForProfile(Profile* profile); |
202 | 210 |
203 // Same as FindForProfile. TODO(hidehiko): Remove this. | 211 // Same as FindForProfile. TODO(hidehiko): Remove this. |
204 static DriveIntegrationService* FindForProfileRegardlessOfStates( | 212 static DriveIntegrationService* FindForProfileRegardlessOfStates( |
205 Profile* profile); | 213 Profile* profile); |
206 | 214 |
207 // Returns the DriveIntegrationServiceFactory instance. | 215 // Returns the DriveIntegrationServiceFactory instance. |
208 static DriveIntegrationServiceFactory* GetInstance(); | 216 static DriveIntegrationServiceFactory* GetInstance(); |
209 | 217 |
210 // Sets a factory function for tests. | |
211 static void SetFactoryForTest(const FactoryCallback& factory_for_test); | |
212 | |
213 private: | 218 private: |
214 friend struct DefaultSingletonTraits<DriveIntegrationServiceFactory>; | 219 friend struct DefaultSingletonTraits<DriveIntegrationServiceFactory>; |
215 | 220 |
216 DriveIntegrationServiceFactory(); | 221 DriveIntegrationServiceFactory(); |
217 virtual ~DriveIntegrationServiceFactory(); | 222 virtual ~DriveIntegrationServiceFactory(); |
218 | 223 |
219 // BrowserContextKeyedServiceFactory: | 224 // BrowserContextKeyedServiceFactory: |
220 virtual BrowserContextKeyedService* BuildServiceInstanceFor( | 225 virtual BrowserContextKeyedService* BuildServiceInstanceFor( |
221 content::BrowserContext* context) const OVERRIDE; | 226 content::BrowserContext* context) const OVERRIDE; |
222 | 227 |
223 FactoryCallback factory_for_test_; | 228 // This is static so it can be set without instantiating the factory. This |
| 229 // allows factory creation to be delayed until it normally happens (on profile |
| 230 // creation) rather than when tests are set up. DriveIntegrationServiceFactory |
| 231 // transitively depends on ExtensionSystemFactory which crashes if created too |
| 232 // soon (i.e. before the BrowserProcess exists). |
| 233 static FactoryCallback* factory_for_test_; |
224 }; | 234 }; |
225 | 235 |
226 } // namespace drive | 236 } // namespace drive |
227 | 237 |
228 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_INTEGRATION_SERVICE_H_ | 238 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_INTEGRATION_SERVICE_H_ |
OLD | NEW |