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

Side by Side Diff: chrome/test/base/testing_profile.h

Issue 10693022: Add support for loading user cloud policy on desktop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: removed redundant #ifdef OS_CHROMEOS guard Created 8 years, 4 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 (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_TEST_BASE_TESTING_PROFILE_H_ 5 #ifndef CHROME_TEST_BASE_TESTING_PROFILE_H_
6 #define CHROME_TEST_BASE_TESTING_PROFILE_H_ 6 #define CHROME_TEST_BASE_TESTING_PROFILE_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // platforms but must be different on ChromeOS because a logged-in user cannot 51 // platforms but must be different on ChromeOS because a logged-in user cannot
52 // use "Default" as profile directory. 52 // use "Default" as profile directory.
53 // Browser- and UI tests should always use this to get to the user's profile 53 // Browser- and UI tests should always use this to get to the user's profile
54 // directory. Unit-tests, though, should use |kInitialProfile|, which is 54 // directory. Unit-tests, though, should use |kInitialProfile|, which is
55 // always "Default", because they are runnining without logged-in user. 55 // always "Default", because they are runnining without logged-in user.
56 static const char kTestUserProfileDir[]; 56 static const char kTestUserProfileDir[];
57 57
58 // Default constructor that cannot be used with multi-profiles. 58 // Default constructor that cannot be used with multi-profiles.
59 TestingProfile(); 59 TestingProfile();
60 60
61 // Helper class for building an instance of TestingProfile (allows injecting
62 // mocks for various services prior to profile initialization).
63 // TODO(atwilson): Remove non-default constructors and various setters in
64 // favor of using the Builder API.
65 class Builder {
66 public:
67 Builder();
68 ~Builder();
69
70 // Sets a Delegate to be called back when the Profile is fully initialized.
71 // This causes the final initialization to be performed via a task so the
72 // caller must run a MessageLoop. Caller maintains ownership of the Delegate
73 // and must manage its lifetime so it continues to exist until profile
74 // initialization is complete.
75 void SetDelegate(Delegate* delegate);
76
77 // Sets the ExtensionSpecialStoragePolicy to be returned by
78 // GetExtensionSpecialStoragePolicy().
79 void SetExtensionSpecialStoragePolicy(
80 scoped_refptr<ExtensionSpecialStoragePolicy> policy);
81
82 // Sets the path to the directory to be used to hold profile data.
83 void SetPath(const FilePath& path);
84
85 // Sets the PrefService to be used by this profile.
86 void SetPrefService(scoped_ptr<PrefService> prefs);
87
88 // Sets the UserCloudPolicyManager to be used by this profile.
89 void SetUserCloudPolicyManager(
90 scoped_ptr<policy::UserCloudPolicyManager> manager);
91
92 // Creates the TestingProfile using previously-set settings.
93 scoped_ptr<TestingProfile> Build();
94
95 private:
96 // If true, Build() has already been called.
97 bool build_called_;
98
99 // Various staging variables where values are held until Build() is invoked.
100 scoped_ptr<policy::UserCloudPolicyManager> user_cloud_policy_manager_;
101 scoped_ptr<PrefService> pref_service_;
102 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy_;
103 FilePath path_;
104 Delegate* delegate_;
105
106 DISALLOW_COPY_AND_ASSIGN(Builder);
107 };
108
61 // Multi-profile aware constructor that takes the path to a directory managed 109 // Multi-profile aware constructor that takes the path to a directory managed
62 // for this profile. This constructor is meant to be used by 110 // for this profile. This constructor is meant to be used by
63 // TestingProfileManager::CreateTestingProfile. If you need to create multi- 111 // TestingProfileManager::CreateTestingProfile. If you need to create multi-
64 // profile profiles, use that factory method instead of this directly. 112 // profile profiles, use that factory method instead of this directly.
65 // Exception: if you need to create multi-profile profiles for testing the 113 // Exception: if you need to create multi-profile profiles for testing the
66 // ProfileManager, then use the constructor below instead. 114 // ProfileManager, then use the constructor below instead.
67 explicit TestingProfile(const FilePath& path); 115 explicit TestingProfile(const FilePath& path);
68 116
69 // Multi-profile aware constructor that takes the path to a directory managed 117 // Multi-profile aware constructor that takes the path to a directory managed
70 // for this profile and a delegate. This constructor is meant to be used 118 // for this profile and a delegate. This constructor is meant to be used
71 // for unittesting the ProfileManager. 119 // for unittesting the ProfileManager.
72 TestingProfile(const FilePath& path, Delegate* delegate); 120 TestingProfile(const FilePath& path, Delegate* delegate);
73 121
122 // Full constructor allowing the setting of all possible instance data.
123 // Callers should use Builder::Build() instead of invoking this constructor.
124 TestingProfile(const FilePath& path,
sky 2012/08/06 22:28:27 We already have so many constructors in this class
Andrew T Wilson (Slow) 2012/08/06 23:12:25 I have a TODO to do exactly this (see above), but
Andrew T Wilson (Slow) 2012/08/06 23:59:14 To be clear, my intent is to remove all other cons
125 Delegate* delegate,
126 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy,
127 scoped_ptr<PrefService> prefs,
128 scoped_ptr<policy::UserCloudPolicyManager> manager);
129
74 virtual ~TestingProfile(); 130 virtual ~TestingProfile();
75 131
76 // Creates the favicon service. Consequent calls would recreate the service. 132 // Creates the favicon service. Consequent calls would recreate the service.
77 void CreateFaviconService(); 133 void CreateFaviconService();
78 134
79 // Creates the history service. If |delete_file| is true, the history file is 135 // Creates the history service. If |delete_file| is true, the history file is
80 // deleted first, then the HistoryService is created. As TestingProfile 136 // deleted first, then the HistoryService is created. As TestingProfile
81 // deletes the directory containing the files used by HistoryService, this 137 // deletes the directory containing the files used by HistoryService, this
82 // only matters if you're recreating the HistoryService. If |no_db| is true, 138 // only matters if you're recreating the HistoryService. If |no_db| is true,
83 // the history backend will fail to initialize its database; this is useful 139 // the history backend will fail to initialize its database; this is useful
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 ExtensionSpecialStoragePolicy* extension_special_storage_policy); 216 ExtensionSpecialStoragePolicy* extension_special_storage_policy);
161 virtual ExtensionSpecialStoragePolicy* 217 virtual ExtensionSpecialStoragePolicy*
162 GetExtensionSpecialStoragePolicy() OVERRIDE; 218 GetExtensionSpecialStoragePolicy() OVERRIDE;
163 virtual FaviconService* GetFaviconService(ServiceAccessType access) OVERRIDE; 219 virtual FaviconService* GetFaviconService(ServiceAccessType access) OVERRIDE;
164 virtual HistoryService* GetHistoryService(ServiceAccessType access) OVERRIDE; 220 virtual HistoryService* GetHistoryService(ServiceAccessType access) OVERRIDE;
165 virtual HistoryService* GetHistoryServiceWithoutCreating() OVERRIDE; 221 virtual HistoryService* GetHistoryServiceWithoutCreating() OVERRIDE;
166 // The CookieMonster will only be returned if a Context has been created. Do 222 // The CookieMonster will only be returned if a Context has been created. Do
167 // this by calling CreateRequestContext(). See the note at GetRequestContext 223 // this by calling CreateRequestContext(). See the note at GetRequestContext
168 // for more information. 224 // for more information.
169 net::CookieMonster* GetCookieMonster(); 225 net::CookieMonster* GetCookieMonster();
226
227 virtual policy::UserCloudPolicyManager* GetUserCloudPolicyManager() OVERRIDE;
170 virtual policy::PolicyService* GetPolicyService() OVERRIDE; 228 virtual policy::PolicyService* GetPolicyService() OVERRIDE;
171 // Sets the profile's PrefService. If a pref service hasn't been explicitly 229 // Sets the profile's PrefService. If a pref service hasn't been explicitly
172 // set GetPrefs creates one, so normally you need not invoke this. If you need 230 // set GetPrefs creates one, so normally you need not invoke this. If you need
173 // to set a pref service you must invoke this before GetPrefs. 231 // to set a pref service you must invoke this before GetPrefs.
174 // TestingPrefService takes ownership of |prefs|. 232 // TestingPrefService takes ownership of |prefs|.
175 void SetPrefService(PrefService* prefs); 233 void SetPrefService(PrefService* prefs);
176 virtual PrefService* GetPrefs() OVERRIDE; 234 virtual PrefService* GetPrefs() OVERRIDE;
177 virtual history::TopSites* GetTopSites() OVERRIDE; 235 virtual history::TopSites* GetTopSites() OVERRIDE;
178 virtual history::TopSites* GetTopSitesWithoutCreating() OVERRIDE; 236 virtual history::TopSites* GetTopSitesWithoutCreating() OVERRIDE;
179 237
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 293
236 virtual PrefService* GetOffTheRecordPrefs() OVERRIDE; 294 virtual PrefService* GetOffTheRecordPrefs() OVERRIDE;
237 295
238 protected: 296 protected:
239 base::Time start_time_; 297 base::Time start_time_;
240 scoped_ptr<PrefService> prefs_; 298 scoped_ptr<PrefService> prefs_;
241 // ref only for right type, lifecycle is managed by prefs_ 299 // ref only for right type, lifecycle is managed by prefs_
242 TestingPrefService* testing_prefs_; 300 TestingPrefService* testing_prefs_;
243 301
244 private: 302 private:
303 // Creates a temporary directory for use by this profile.
304 void CreateTempProfileDir();
305
245 // Common initialization between the two constructors. 306 // Common initialization between the two constructors.
246 void Init(); 307 void Init();
247 308
248 // Finishes initialization when a profile is created asynchronously. 309 // Finishes initialization when a profile is created asynchronously.
249 void FinishInit(); 310 void FinishInit();
250 311
251 // Destroys favicon service if it has been created. 312 // Destroys favicon service if it has been created.
252 void DestroyFaviconService(); 313 void DestroyFaviconService();
253 314
254 // Creates a TestingPrefService and associates it with the TestingProfile. 315 // Creates a TestingPrefService and associates it with the TestingProfile.
(...skipping 27 matching lines...) Expand all
282 343
283 FilePath last_selected_directory_; 344 FilePath last_selected_directory_;
284 scoped_refptr<history::TopSites> top_sites_; // For history and thumbnails. 345 scoped_refptr<history::TopSites> top_sites_; // For history and thumbnails.
285 346
286 scoped_refptr<ExtensionSpecialStoragePolicy> 347 scoped_refptr<ExtensionSpecialStoragePolicy>
287 extension_special_storage_policy_; 348 extension_special_storage_policy_;
288 349
289 // The proxy prefs tracker. 350 // The proxy prefs tracker.
290 scoped_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_; 351 scoped_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
291 352
353 // UserCloudPolicyManager returned by GetUserCloudPolicyManager().
354 scoped_ptr<policy::UserCloudPolicyManager> user_cloud_policy_manager_;
355
292 // We use a temporary directory to store testing profile data. In a multi- 356 // We use a temporary directory to store testing profile data. In a multi-
293 // profile environment, this is invalid and the directory is managed by the 357 // profile environment, this is invalid and the directory is managed by the
294 // TestingProfileManager. 358 // TestingProfileManager.
295 ScopedTempDir temp_dir_; 359 ScopedTempDir temp_dir_;
296 // The path to this profile. This will be valid in either of the two above 360 // The path to this profile. This will be valid in either of the two above
297 // cases. 361 // cases.
298 FilePath profile_path_; 362 FilePath profile_path_;
299 363
300 // We keep a weak pointer to the dependency manager we want to notify on our 364 // We keep a weak pointer to the dependency manager we want to notify on our
301 // death. Defaults to the Singleton implementation but overridable for 365 // death. Defaults to the Singleton implementation but overridable for
302 // testing. 366 // testing.
303 ProfileDependencyManager* profile_dependency_manager_; 367 ProfileDependencyManager* profile_dependency_manager_;
304 368
305 scoped_ptr<content::MockResourceContext> resource_context_; 369 scoped_ptr<content::MockResourceContext> resource_context_;
306 370
307 // Weak pointer to a delegate for indicating that a profile was created. 371 // Weak pointer to a delegate for indicating that a profile was created.
308 Delegate* delegate_; 372 Delegate* delegate_;
309 }; 373 };
310 374
311 #endif // CHROME_TEST_BASE_TESTING_PROFILE_H_ 375 #endif // CHROME_TEST_BASE_TESTING_PROFILE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698