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

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

Issue 23068005: Convert UserPolicySigninService to use OAuth2TokenService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with ToT Created 7 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
« no previous file with comments | « chrome/test/base/testing_profile.h ('k') | chrome/test/base/testing_profile_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/test/base/testing_profile.h" 5 #include "chrome/test/base/testing_profile.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 // ChromeBrowserMainPartsChromeos::PreEarlyInitialization. 160 // ChromeBrowserMainPartsChromeos::PreEarlyInitialization.
161 const char TestingProfile::kTestUserProfileDir[] = "test-user"; 161 const char TestingProfile::kTestUserProfileDir[] = "test-user";
162 #else 162 #else
163 const char TestingProfile::kTestUserProfileDir[] = "Default"; 163 const char TestingProfile::kTestUserProfileDir[] = "Default";
164 #endif 164 #endif
165 165
166 TestingProfile::TestingProfile() 166 TestingProfile::TestingProfile()
167 : start_time_(Time::Now()), 167 : start_time_(Time::Now()),
168 testing_prefs_(NULL), 168 testing_prefs_(NULL),
169 incognito_(false), 169 incognito_(false),
170 force_incognito_(false),
170 original_profile_(NULL), 171 original_profile_(NULL),
171 last_session_exited_cleanly_(true), 172 last_session_exited_cleanly_(true),
172 browser_context_dependency_manager_( 173 browser_context_dependency_manager_(
173 BrowserContextDependencyManager::GetInstance()), 174 BrowserContextDependencyManager::GetInstance()),
174 resource_context_(NULL), 175 resource_context_(NULL),
175 delegate_(NULL) { 176 delegate_(NULL) {
176 CreateTempProfileDir(); 177 CreateTempProfileDir();
177 profile_path_ = temp_dir_.path(); 178 profile_path_ = temp_dir_.path();
178 179
179 Init(); 180 Init();
180 FinishInit(); 181 FinishInit();
181 } 182 }
182 183
183 TestingProfile::TestingProfile(const base::FilePath& path) 184 TestingProfile::TestingProfile(const base::FilePath& path)
184 : start_time_(Time::Now()), 185 : start_time_(Time::Now()),
185 testing_prefs_(NULL), 186 testing_prefs_(NULL),
186 incognito_(false), 187 incognito_(false),
188 force_incognito_(false),
187 original_profile_(NULL), 189 original_profile_(NULL),
188 last_session_exited_cleanly_(true), 190 last_session_exited_cleanly_(true),
189 profile_path_(path), 191 profile_path_(path),
190 browser_context_dependency_manager_( 192 browser_context_dependency_manager_(
191 BrowserContextDependencyManager::GetInstance()), 193 BrowserContextDependencyManager::GetInstance()),
192 resource_context_(NULL), 194 resource_context_(NULL),
193 delegate_(NULL) { 195 delegate_(NULL) {
194 Init(); 196 Init();
195 FinishInit(); 197 FinishInit();
196 } 198 }
197 199
198 TestingProfile::TestingProfile(const base::FilePath& path, 200 TestingProfile::TestingProfile(const base::FilePath& path,
199 Delegate* delegate) 201 Delegate* delegate)
200 : start_time_(Time::Now()), 202 : start_time_(Time::Now()),
201 testing_prefs_(NULL), 203 testing_prefs_(NULL),
202 incognito_(false), 204 incognito_(false),
205 force_incognito_(false),
203 original_profile_(NULL), 206 original_profile_(NULL),
204 last_session_exited_cleanly_(true), 207 last_session_exited_cleanly_(true),
205 profile_path_(path), 208 profile_path_(path),
206 browser_context_dependency_manager_( 209 browser_context_dependency_manager_(
207 BrowserContextDependencyManager::GetInstance()), 210 BrowserContextDependencyManager::GetInstance()),
208 resource_context_(NULL), 211 resource_context_(NULL),
209 delegate_(delegate) { 212 delegate_(delegate) {
210 Init(); 213 Init();
211 if (delegate_) { 214 if (delegate_) {
212 base::MessageLoop::current()->PostTask( 215 base::MessageLoop::current()->PostTask(
213 FROM_HERE, 216 FROM_HERE,
214 base::Bind(&TestingProfile::FinishInit, base::Unretained(this))); 217 base::Bind(&TestingProfile::FinishInit, base::Unretained(this)));
215 } else { 218 } else {
216 FinishInit(); 219 FinishInit();
217 } 220 }
218 } 221 }
219 222
220 TestingProfile::TestingProfile( 223 TestingProfile::TestingProfile(
221 const base::FilePath& path, 224 const base::FilePath& path,
222 Delegate* delegate, 225 Delegate* delegate,
223 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, 226 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy,
224 scoped_ptr<PrefServiceSyncable> prefs) 227 scoped_ptr<PrefServiceSyncable> prefs,
228 bool incognito,
229 const TestingFactories& factories)
225 : start_time_(Time::Now()), 230 : start_time_(Time::Now()),
226 prefs_(prefs.release()), 231 prefs_(prefs.release()),
227 testing_prefs_(NULL), 232 testing_prefs_(NULL),
228 incognito_(false), 233 incognito_(incognito),
234 force_incognito_(false),
229 original_profile_(NULL), 235 original_profile_(NULL),
230 last_session_exited_cleanly_(true), 236 last_session_exited_cleanly_(true),
231 extension_special_storage_policy_(extension_policy), 237 extension_special_storage_policy_(extension_policy),
232 profile_path_(path), 238 profile_path_(path),
233 browser_context_dependency_manager_( 239 browser_context_dependency_manager_(
234 BrowserContextDependencyManager::GetInstance()), 240 BrowserContextDependencyManager::GetInstance()),
235 resource_context_(NULL), 241 resource_context_(NULL),
236 delegate_(delegate) { 242 delegate_(delegate) {
237 243
238 // If no profile path was supplied, create one. 244 // If no profile path was supplied, create one.
239 if (profile_path_.empty()) { 245 if (profile_path_.empty()) {
240 CreateTempProfileDir(); 246 CreateTempProfileDir();
241 profile_path_ = temp_dir_.path(); 247 profile_path_ = temp_dir_.path();
242 } 248 }
243 249
250 // Set any testing factories prior to initializing the services.
251 for (TestingFactories::const_iterator it = factories.begin();
252 it != factories.end(); ++it) {
253 it->first->SetTestingFactory(this, it->second);
254 }
255
244 Init(); 256 Init();
245 // If caller supplied a delegate, delay the FinishInit invocation until other 257 // If caller supplied a delegate, delay the FinishInit invocation until other
246 // tasks have run. 258 // tasks have run.
247 // TODO(atwilson): See if this is still required once we convert the current 259 // TODO(atwilson): See if this is still required once we convert the current
248 // users of the constructor that takes a Delegate* param. 260 // users of the constructor that takes a Delegate* param.
249 if (delegate_) { 261 if (delegate_) {
250 base::MessageLoop::current()->PostTask( 262 base::MessageLoop::current()->PostTask(
251 FROM_HERE, 263 FROM_HERE,
252 base::Bind(&TestingProfile::FinishInit, base::Unretained(this))); 264 base::Bind(&TestingProfile::FinishInit, base::Unretained(this)));
253 } else { 265 } else {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 file_util::CreateDirectory(profile_path_); 314 file_util::CreateDirectory(profile_path_);
303 315
304 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl 316 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl
305 // anymore, after converting the PrefService to a PKS. Until then it must 317 // anymore, after converting the PrefService to a PKS. Until then it must
306 // be associated with a TestingProfile too. 318 // be associated with a TestingProfile too.
307 CreateProfilePolicyConnector(); 319 CreateProfilePolicyConnector();
308 320
309 extensions::ExtensionSystemFactory::GetInstance()->SetTestingFactory( 321 extensions::ExtensionSystemFactory::GetInstance()->SetTestingFactory(
310 this, extensions::TestExtensionSystem::Build); 322 this, extensions::TestExtensionSystem::Build);
311 323
312 browser_context_dependency_manager_->CreateBrowserContextServices(this, true); 324 // If there is no separate original profile specified for this profile, then
325 // force preferences to be registered - this allows tests to create a
326 // standalone incognito profile while still having prefs registered.
327 browser_context_dependency_manager_->CreateBrowserContextServicesForTest(
328 this, !original_profile_);
313 329
314 #if defined(ENABLE_NOTIFICATIONS) 330 #if defined(ENABLE_NOTIFICATIONS)
315 // Install profile keyed service factory hooks for dummy/test services 331 // Install profile keyed service factory hooks for dummy/test services
316 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( 332 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory(
317 this, CreateTestDesktopNotificationService); 333 this, CreateTestDesktopNotificationService);
318 #endif 334 #endif
319 } 335 }
320 336
321 void TestingProfile::FinishInit() { 337 void TestingProfile::FinishInit() {
322 DCHECK(content::NotificationService::current()); 338 DCHECK(content::NotificationService::current());
323 content::NotificationService::current()->Notify( 339 content::NotificationService::current()->Notify(
324 chrome::NOTIFICATION_PROFILE_CREATED, 340 chrome::NOTIFICATION_PROFILE_CREATED,
325 content::Source<Profile>(static_cast<Profile*>(this)), 341 content::Source<Profile>(static_cast<Profile*>(this)),
326 content::NotificationService::NoDetails()); 342 content::NotificationService::NoDetails());
327 343
328 if (delegate_) 344 if (delegate_)
329 delegate_->OnProfileCreated(this, true, false); 345 delegate_->OnProfileCreated(this, true, false);
330 } 346 }
331 347
332 TestingProfile::~TestingProfile() { 348 TestingProfile::~TestingProfile() {
349 // Revert to non-incognito mode before shutdown.
350 force_incognito_ = false;
351
333 // Any objects holding live URLFetchers should be deleted before teardown. 352 // Any objects holding live URLFetchers should be deleted before teardown.
334 TemplateURLFetcherFactory::ShutdownForProfile(this); 353 TemplateURLFetcherFactory::ShutdownForProfile(this);
335 354
336 MaybeSendDestroyedNotification(); 355 MaybeSendDestroyedNotification();
337 356
338 browser_context_dependency_manager_->DestroyBrowserContextServices(this); 357 browser_context_dependency_manager_->DestroyBrowserContextServices(this);
339 358
340 if (host_content_settings_map_.get()) 359 if (host_content_settings_map_.get())
341 host_content_settings_map_->ShutdownOnUIThread(); 360 host_content_settings_map_->ShutdownOnUIThread();
342 361
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 538
520 TestingProfile* TestingProfile::AsTestingProfile() { 539 TestingProfile* TestingProfile::AsTestingProfile() {
521 return this; 540 return this;
522 } 541 }
523 542
524 std::string TestingProfile::GetProfileName() { 543 std::string TestingProfile::GetProfileName() {
525 return std::string("testing_profile"); 544 return std::string("testing_profile");
526 } 545 }
527 546
528 bool TestingProfile::IsOffTheRecord() const { 547 bool TestingProfile::IsOffTheRecord() const {
529 return incognito_; 548 return force_incognito_ || incognito_;
530 } 549 }
531 550
532 void TestingProfile::SetOffTheRecordProfile(Profile* profile) { 551 void TestingProfile::SetOffTheRecordProfile(scoped_ptr<Profile> profile) {
533 incognito_profile_.reset(profile); 552 DCHECK(!IsOffTheRecord());
553 incognito_profile_ = profile.Pass();
534 } 554 }
535 555
536 void TestingProfile::SetOriginalProfile(Profile* profile) { 556 void TestingProfile::SetOriginalProfile(Profile* profile) {
557 DCHECK(IsOffTheRecord());
537 original_profile_ = profile; 558 original_profile_ = profile;
538 } 559 }
539 560
540 Profile* TestingProfile::GetOffTheRecordProfile() { 561 Profile* TestingProfile::GetOffTheRecordProfile() {
562 if (IsOffTheRecord())
563 return this;
541 return incognito_profile_.get(); 564 return incognito_profile_.get();
542 } 565 }
543 566
544 bool TestingProfile::HasOffTheRecordProfile() { 567 bool TestingProfile::HasOffTheRecordProfile() {
545 return incognito_profile_.get() != NULL; 568 return incognito_profile_.get() != NULL;
546 } 569 }
547 570
548 Profile* TestingProfile::GetOriginalProfile() { 571 Profile* TestingProfile::GetOriginalProfile() {
549 if (original_profile_) 572 if (original_profile_)
550 return original_profile_; 573 return original_profile_;
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 812
790 bool TestingProfile::IsGuestSession() const { 813 bool TestingProfile::IsGuestSession() const {
791 return false; 814 return false;
792 } 815 }
793 Profile::ExitType TestingProfile::GetLastSessionExitType() { 816 Profile::ExitType TestingProfile::GetLastSessionExitType() {
794 return last_session_exited_cleanly_ ? EXIT_NORMAL : EXIT_CRASHED; 817 return last_session_exited_cleanly_ ? EXIT_NORMAL : EXIT_CRASHED;
795 } 818 }
796 819
797 TestingProfile::Builder::Builder() 820 TestingProfile::Builder::Builder()
798 : build_called_(false), 821 : build_called_(false),
799 delegate_(NULL) { 822 delegate_(NULL),
823 incognito_(false) {
800 } 824 }
801 825
802 TestingProfile::Builder::~Builder() { 826 TestingProfile::Builder::~Builder() {
803 } 827 }
804 828
805 void TestingProfile::Builder::SetPath(const base::FilePath& path) { 829 void TestingProfile::Builder::SetPath(const base::FilePath& path) {
806 path_ = path; 830 path_ = path;
807 } 831 }
808 832
809 void TestingProfile::Builder::SetDelegate(Delegate* delegate) { 833 void TestingProfile::Builder::SetDelegate(Delegate* delegate) {
810 delegate_ = delegate; 834 delegate_ = delegate;
811 } 835 }
812 836
813 void TestingProfile::Builder::SetExtensionSpecialStoragePolicy( 837 void TestingProfile::Builder::SetExtensionSpecialStoragePolicy(
814 scoped_refptr<ExtensionSpecialStoragePolicy> policy) { 838 scoped_refptr<ExtensionSpecialStoragePolicy> policy) {
815 extension_policy_ = policy; 839 extension_policy_ = policy;
816 } 840 }
817 841
818 void TestingProfile::Builder::SetPrefService( 842 void TestingProfile::Builder::SetPrefService(
819 scoped_ptr<PrefServiceSyncable> prefs) { 843 scoped_ptr<PrefServiceSyncable> prefs) {
820 pref_service_ = prefs.Pass(); 844 pref_service_ = prefs.Pass();
821 } 845 }
822 846
847 void TestingProfile::Builder::SetIncognito() {
848 incognito_ = true;
849 }
850
851 void TestingProfile::Builder::AddTestingFactory(
852 BrowserContextKeyedServiceFactory* service_factory,
853 BrowserContextKeyedServiceFactory::FactoryFunction callback) {
854 testing_factories_.push_back(std::make_pair(service_factory, callback));
855 }
856
823 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { 857 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() {
824 DCHECK(!build_called_); 858 DCHECK(!build_called_);
825 build_called_ = true; 859 build_called_ = true;
826 return scoped_ptr<TestingProfile>(new TestingProfile( 860 return scoped_ptr<TestingProfile>(new TestingProfile(
827 path_, 861 path_,
828 delegate_, 862 delegate_,
829 extension_policy_, 863 extension_policy_,
830 pref_service_.Pass())); 864 pref_service_.Pass(),
865 incognito_,
866 testing_factories_));
831 } 867 }
OLDNEW
« no previous file with comments | « chrome/test/base/testing_profile.h ('k') | chrome/test/base/testing_profile_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698