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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 base::WeakPtrFactory<DriveIntegrationService> weak_ptr_factory_; | 178 base::WeakPtrFactory<DriveIntegrationService> weak_ptr_factory_; |
179 DISALLOW_COPY_AND_ASSIGN(DriveIntegrationService); | 179 DISALLOW_COPY_AND_ASSIGN(DriveIntegrationService); |
180 }; | 180 }; |
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 DriveIntegrationService*(FactoryFunction)(Profile* profile, |
189 FactoryCallback; | 189 void* data); |
190 | 190 |
191 // Returns the DriveIntegrationService for |profile|, creating it if it is | 191 // Returns the DriveIntegrationService for |profile|, creating it if it is |
192 // not yet created. | 192 // not yet created. |
193 static DriveIntegrationService* GetForProfile(Profile* profile); | 193 static DriveIntegrationService* GetForProfile(Profile* profile); |
194 | 194 |
195 // Same as GetForProfile. TODO(hidehiko): Remove this. | 195 // Same as GetForProfile. TODO(hidehiko): Remove this. |
196 static DriveIntegrationService* GetForProfileRegardlessOfStates( | 196 static DriveIntegrationService* GetForProfileRegardlessOfStates( |
197 Profile* profile); | 197 Profile* profile); |
198 | 198 |
199 // Returns the DriveIntegrationService that is already associated with | 199 // Returns the DriveIntegrationService that is already associated with |
200 // |profile|, if it is not yet created it will return NULL. | 200 // |profile|, if it is not yet created it will return NULL. |
201 static DriveIntegrationService* FindForProfile(Profile* profile); | 201 static DriveIntegrationService* FindForProfile(Profile* profile); |
202 | 202 |
203 // Same as FindForProfile. TODO(hidehiko): Remove this. | 203 // Same as FindForProfile. TODO(hidehiko): Remove this. |
204 static DriveIntegrationService* FindForProfileRegardlessOfStates( | 204 static DriveIntegrationService* FindForProfileRegardlessOfStates( |
205 Profile* profile); | 205 Profile* profile); |
206 | 206 |
207 // Returns the DriveIntegrationServiceFactory instance. | 207 // Returns the DriveIntegrationServiceFactory instance. |
208 static DriveIntegrationServiceFactory* GetInstance(); | 208 static DriveIntegrationServiceFactory* GetInstance(); |
209 | 209 |
210 // Sets a factory function for tests. | 210 // Sets a factory function for tests. |
211 static void SetFactoryForTest(const FactoryCallback& factory_for_test); | 211 static void SetFactoryForTest(FactoryFunction factory_for_test, void* data); |
212 | 212 |
213 private: | 213 private: |
214 friend struct DefaultSingletonTraits<DriveIntegrationServiceFactory>; | 214 friend struct DefaultSingletonTraits<DriveIntegrationServiceFactory>; |
215 | 215 |
216 DriveIntegrationServiceFactory(); | 216 DriveIntegrationServiceFactory(); |
217 virtual ~DriveIntegrationServiceFactory(); | 217 virtual ~DriveIntegrationServiceFactory(); |
218 | 218 |
219 // BrowserContextKeyedServiceFactory: | 219 // BrowserContextKeyedServiceFactory: |
220 virtual BrowserContextKeyedService* BuildServiceInstanceFor( | 220 virtual BrowserContextKeyedService* BuildServiceInstanceFor( |
221 content::BrowserContext* context) const OVERRIDE; | 221 content::BrowserContext* context) const OVERRIDE; |
222 | 222 |
223 FactoryCallback factory_for_test_; | 223 // These are static so we can delay creating an instance of this factory |
224 // (and all its dependent factories) until the profile is created. | |
tbarzic
2014/01/09 01:58:25
nit: What do you think about slightly more context
James Cook
2014/01/09 17:32:19
That's a much better comment. Done.
| |
225 static FactoryFunction* factory_function_for_test_; | |
226 static void* factory_data_for_test_; | |
224 }; | 227 }; |
225 | 228 |
226 } // namespace drive | 229 } // namespace drive |
227 | 230 |
228 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_INTEGRATION_SERVICE_H_ | 231 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_INTEGRATION_SERVICE_H_ |
OLD | NEW |