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 #include "chrome/test/base/testing_profile_manager.h" | 5 #include "chrome/test/base/testing_profile_manager.h" |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 9 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
10 #include "chrome/browser/prefs/pref_service_syncable.h" | 10 #include "chrome/browser/prefs/pref_service_syncable.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 bool TestingProfileManager::SetUp() { | 46 bool TestingProfileManager::SetUp() { |
47 SetUpInternal(); | 47 SetUpInternal(); |
48 return called_set_up_; | 48 return called_set_up_; |
49 } | 49 } |
50 | 50 |
51 TestingProfile* TestingProfileManager::CreateTestingProfile( | 51 TestingProfile* TestingProfileManager::CreateTestingProfile( |
52 const std::string& profile_name, | 52 const std::string& profile_name, |
53 scoped_ptr<PrefServiceSyncable> prefs, | 53 scoped_ptr<PrefServiceSyncable> prefs, |
54 const base::string16& user_name, | 54 const base::string16& user_name, |
55 int avatar_id, | 55 int avatar_id, |
56 const std::string& managed_user_id, | 56 const std::string& supervised_user_id, |
57 const TestingProfile::TestingFactories& factories) { | 57 const TestingProfile::TestingFactories& factories) { |
58 DCHECK(called_set_up_); | 58 DCHECK(called_set_up_); |
59 | 59 |
60 // Create a path for the profile based on the name. | 60 // Create a path for the profile based on the name. |
61 base::FilePath profile_path(profiles_dir_.path()); | 61 base::FilePath profile_path(profiles_dir_.path()); |
62 profile_path = profile_path.AppendASCII(profile_name); | 62 profile_path = profile_path.AppendASCII(profile_name); |
63 | 63 |
64 // Create the profile and register it. | 64 // Create the profile and register it. |
65 TestingProfile::Builder builder; | 65 TestingProfile::Builder builder; |
66 builder.SetPath(profile_path); | 66 builder.SetPath(profile_path); |
67 builder.SetPrefService(prefs.Pass()); | 67 builder.SetPrefService(prefs.Pass()); |
68 builder.SetManagedUserId(managed_user_id); | 68 builder.SetSupervisedUserId(supervised_user_id); |
69 | 69 |
70 for (TestingProfile::TestingFactories::const_iterator it = factories.begin(); | 70 for (TestingProfile::TestingFactories::const_iterator it = factories.begin(); |
71 it != factories.end(); ++it) { | 71 it != factories.end(); ++it) { |
72 builder.AddTestingFactory(it->first, it->second); | 72 builder.AddTestingFactory(it->first, it->second); |
73 } | 73 } |
74 | 74 |
75 TestingProfile* profile = builder.Build().release(); | 75 TestingProfile* profile = builder.Build().release(); |
76 profile->set_profile_name(profile_name); | 76 profile->set_profile_name(profile_name); |
77 profile_manager_->AddProfile(profile); // Takes ownership. | 77 profile_manager_->AddProfile(profile); // Takes ownership. |
78 | 78 |
79 // Update the user metadata. | 79 // Update the user metadata. |
80 ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); | 80 ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); |
81 size_t index = cache.GetIndexOfProfileWithPath(profile_path); | 81 size_t index = cache.GetIndexOfProfileWithPath(profile_path); |
82 cache.SetAvatarIconOfProfileAtIndex(index, avatar_id); | 82 cache.SetAvatarIconOfProfileAtIndex(index, avatar_id); |
83 cache.SetManagedUserIdOfProfileAtIndex(index, managed_user_id); | 83 cache.SetSupervisedUserIdOfProfileAtIndex(index, supervised_user_id); |
84 // SetNameOfProfileAtIndex may reshuffle the list of profiles, so we do it | 84 // SetNameOfProfileAtIndex may reshuffle the list of profiles, so we do it |
85 // last. | 85 // last. |
86 cache.SetNameOfProfileAtIndex(index, user_name); | 86 cache.SetNameOfProfileAtIndex(index, user_name); |
87 | 87 |
88 testing_profiles_.insert(std::make_pair(profile_name, profile)); | 88 testing_profiles_.insert(std::make_pair(profile_name, profile)); |
89 | 89 |
90 return profile; | 90 return profile; |
91 } | 91 } |
92 | 92 |
93 TestingProfile* TestingProfileManager::CreateTestingProfile( | 93 TestingProfile* TestingProfileManager::CreateTestingProfile( |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 << "ProfileManager already exists"; | 176 << "ProfileManager already exists"; |
177 | 177 |
178 // Set up the directory for profiles. | 178 // Set up the directory for profiles. |
179 ASSERT_TRUE(profiles_dir_.CreateUniqueTempDir()); | 179 ASSERT_TRUE(profiles_dir_.CreateUniqueTempDir()); |
180 | 180 |
181 profile_manager_ = new testing::ProfileManager(profiles_dir_.path()); | 181 profile_manager_ = new testing::ProfileManager(profiles_dir_.path()); |
182 browser_process_->SetProfileManager(profile_manager_); // Takes ownership. | 182 browser_process_->SetProfileManager(profile_manager_); // Takes ownership. |
183 | 183 |
184 called_set_up_ = true; | 184 called_set_up_ = true; |
185 } | 185 } |
OLD | NEW |