OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/browser/profile.h" | 5 #include "chrome/browser/profile.h" |
6 | 6 |
7 #include "app/theme_provider.h" | 7 #include "app/theme_provider.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 return base.Append(chrome::kMediaCacheDirname); | 118 return base.Append(chrome::kMediaCacheDirname); |
119 } | 119 } |
120 | 120 |
121 bool HasACacheSubdir(const FilePath &dir) { | 121 bool HasACacheSubdir(const FilePath &dir) { |
122 return file_util::PathExists(GetCachePath(dir)) || | 122 return file_util::PathExists(GetCachePath(dir)) || |
123 file_util::PathExists(GetMediaCachePath(dir)); | 123 file_util::PathExists(GetMediaCachePath(dir)); |
124 } | 124 } |
125 | 125 |
126 } // namespace | 126 } // namespace |
127 | 127 |
| 128 // This helper class owns the VisitedLinkMaster and exposes a way to load it |
| 129 // from on the file thread. |
| 130 class VisitedLinkCreator |
| 131 : public base::RefCountedThreadSafe<VisitedLinkCreator> { |
| 132 public: |
| 133 enum LoadState { |
| 134 NOT_LOADED, |
| 135 FILE_LOAD_FAILED, |
| 136 LOAD_FINISHED |
| 137 }; |
| 138 |
| 139 explicit VisitedLinkCreator(Profile* profile) |
| 140 : listener_(new VisitedLinkEventListener()), |
| 141 profile_(profile), |
| 142 load_state_(NOT_LOADED) { |
| 143 visited_link_master_.reset(new VisitedLinkMaster(listener_.get(), |
| 144 profile_)); |
| 145 } |
| 146 |
| 147 // Preload the visited link master on the file thread. |
| 148 void Preload() { |
| 149 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 150 ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE, NewRunnableMethod( |
| 151 this, &VisitedLinkCreator::LoadBackground)); |
| 152 } |
| 153 |
| 154 // This method can return NULL if for some reason we can't initialize the |
| 155 // visited link master. |
| 156 VisitedLinkMaster* GetMaster() { |
| 157 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 158 // Go ahead and try to load the VisitedLink table. If the data was |
| 159 // preloaded, Load() does nothing. |
| 160 AutoLock l(lock_); |
| 161 if (LOAD_FINISHED != load_state_) { |
| 162 bool success = false; |
| 163 if (FILE_LOAD_FAILED == load_state_) { |
| 164 success = visited_link_master_->InitFromScratch(); |
| 165 } else if (NOT_LOADED == load_state_) { |
| 166 // We haven't tried to load from file yet, so go ahead and do that. |
| 167 success = visited_link_master_->Init(); |
| 168 } |
| 169 |
| 170 if (!success) { |
| 171 NOTREACHED() << "Failed to init visited link master."; |
| 172 visited_link_master_.reset(); |
| 173 } |
| 174 load_state_ = LOAD_FINISHED; |
| 175 } |
| 176 |
| 177 // We don't need to lock here because after Load() has been called, we |
| 178 // never change vistied_link_master_. |
| 179 return visited_link_master_.get(); |
| 180 } |
| 181 |
| 182 private: |
| 183 // Tries to load the visited link database from the UI thread. |
| 184 void LoadBackground() { |
| 185 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); |
| 186 AutoLock l(lock_); |
| 187 if (NOT_LOADED != load_state_) |
| 188 return; |
| 189 |
| 190 // We only want to try to load the data from a file (it's not thread safe |
| 191 // to InitFromScratch on the file thread). |
| 192 load_state_ = visited_link_master_->InitFromFile() ? LOAD_FINISHED |
| 193 : FILE_LOAD_FAILED; |
| 194 } |
| 195 |
| 196 scoped_ptr<VisitedLinkMaster::Listener> listener_; |
| 197 Profile* profile_; |
| 198 |
| 199 // This lock protects visited_link_master_ and load_state_. |
| 200 Lock lock_; |
| 201 scoped_ptr<VisitedLinkMaster> visited_link_master_; |
| 202 // Once created_ is true, we can stop trying to create and init the |
| 203 // VisitedLinkMaster. |
| 204 LoadState load_state_; |
| 205 |
| 206 DISALLOW_COPY_AND_ASSIGN(VisitedLinkCreator); |
| 207 }; |
| 208 |
128 // A pointer to the request context for the default profile. See comments on | 209 // A pointer to the request context for the default profile. See comments on |
129 // Profile::GetDefaultRequestContext. | 210 // Profile::GetDefaultRequestContext. |
130 URLRequestContextGetter* Profile::default_request_context_; | 211 URLRequestContextGetter* Profile::default_request_context_; |
131 | 212 |
132 static void CleanupRequestContext(ChromeURLRequestContextGetter* context) { | 213 static void CleanupRequestContext(ChromeURLRequestContextGetter* context) { |
133 if (context) | 214 if (context) |
134 context->CleanupOnUIThread(); | 215 context->CleanupOnUIThread(); |
135 } | 216 } |
136 | 217 |
137 // static | 218 // static |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 | 288 |
208 virtual ~OffTheRecordProfileImpl() { | 289 virtual ~OffTheRecordProfileImpl() { |
209 CleanupRequestContext(request_context_); | 290 CleanupRequestContext(request_context_); |
210 CleanupRequestContext(extensions_request_context_); | 291 CleanupRequestContext(extensions_request_context_); |
211 } | 292 } |
212 | 293 |
213 virtual ProfileId GetRuntimeId() { | 294 virtual ProfileId GetRuntimeId() { |
214 return reinterpret_cast<ProfileId>(this); | 295 return reinterpret_cast<ProfileId>(this); |
215 } | 296 } |
216 | 297 |
217 virtual FilePath GetPath() { return profile_->GetPath(); } | 298 virtual FilePath GetPath() { |
| 299 return profile_->GetPath(); |
| 300 } |
218 | 301 |
219 virtual bool IsOffTheRecord() { | 302 virtual bool IsOffTheRecord() { |
220 return true; | 303 return true; |
221 } | 304 } |
222 | 305 |
223 virtual Profile* GetOffTheRecordProfile() { | 306 virtual Profile* GetOffTheRecordProfile() { |
224 return this; | 307 return this; |
225 } | 308 } |
226 | 309 |
227 virtual void DestroyOffTheRecordProfile() { | 310 virtual void DestroyOffTheRecordProfile() { |
(...skipping 10 matching lines...) Expand all Loading... |
238 db_tracker_ = new webkit_database::DatabaseTracker(FilePath()); | 321 db_tracker_ = new webkit_database::DatabaseTracker(FilePath()); |
239 return db_tracker_; | 322 return db_tracker_; |
240 } | 323 } |
241 | 324 |
242 virtual VisitedLinkMaster* GetVisitedLinkMaster() { | 325 virtual VisitedLinkMaster* GetVisitedLinkMaster() { |
243 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord | 326 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord |
244 // because we don't want to leak the sites that the user has visited before. | 327 // because we don't want to leak the sites that the user has visited before. |
245 return NULL; | 328 return NULL; |
246 } | 329 } |
247 | 330 |
| 331 virtual void PreloadVisitedLinkMaster() {} |
| 332 |
248 virtual ExtensionsService* GetExtensionsService() { | 333 virtual ExtensionsService* GetExtensionsService() { |
249 return NULL; | 334 return NULL; |
250 } | 335 } |
251 | 336 |
252 virtual UserScriptMaster* GetUserScriptMaster() { | 337 virtual UserScriptMaster* GetUserScriptMaster() { |
253 return profile_->GetUserScriptMaster(); | 338 return profile_->GetUserScriptMaster(); |
254 } | 339 } |
255 | 340 |
256 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() { | 341 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() { |
257 return NULL; | 342 return NULL; |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 | 645 |
561 // The main database tracker for this profile. | 646 // The main database tracker for this profile. |
562 // Should be used only on the file thread. | 647 // Should be used only on the file thread. |
563 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_; | 648 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_; |
564 | 649 |
565 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl); | 650 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl); |
566 }; | 651 }; |
567 | 652 |
568 ProfileImpl::ProfileImpl(const FilePath& path) | 653 ProfileImpl::ProfileImpl(const FilePath& path) |
569 : path_(path), | 654 : path_(path), |
570 visited_link_event_listener_(new VisitedLinkEventListener()), | |
571 extension_devtools_manager_(NULL), | 655 extension_devtools_manager_(NULL), |
572 request_context_(NULL), | 656 request_context_(NULL), |
573 media_request_context_(NULL), | 657 media_request_context_(NULL), |
574 extensions_request_context_(NULL), | 658 extensions_request_context_(NULL), |
575 host_zoom_map_(NULL), | 659 host_zoom_map_(NULL), |
576 blacklist_manager_(NULL), | 660 blacklist_manager_(NULL), |
577 blacklist_manager_created_(false), | 661 blacklist_manager_created_(false), |
578 history_service_created_(false), | 662 history_service_created_(false), |
579 favicon_service_created_(false), | 663 favicon_service_created_(false), |
580 created_web_data_service_(false), | 664 created_web_data_service_(false), |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 return this; | 891 return this; |
808 } | 892 } |
809 | 893 |
810 webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() { | 894 webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() { |
811 if (!db_tracker_) | 895 if (!db_tracker_) |
812 db_tracker_ = new webkit_database::DatabaseTracker(GetPath()); | 896 db_tracker_ = new webkit_database::DatabaseTracker(GetPath()); |
813 return db_tracker_; | 897 return db_tracker_; |
814 } | 898 } |
815 | 899 |
816 VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() { | 900 VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() { |
817 if (!visited_link_master_.get()) { | 901 if (!visited_link_creator_.get()) |
818 scoped_ptr<VisitedLinkMaster> visited_links( | 902 visited_link_creator_ = new VisitedLinkCreator(this); |
819 new VisitedLinkMaster(visited_link_event_listener_.get(), this)); | 903 return visited_link_creator_->GetMaster(); |
820 if (!visited_links->Init()) | 904 } |
821 return NULL; | 905 |
822 visited_link_master_.swap(visited_links); | 906 void ProfileImpl::PreloadVisitedLinkMaster() { |
| 907 if (!visited_link_creator_.get()) { |
| 908 visited_link_creator_ = new VisitedLinkCreator(this); |
| 909 visited_link_creator_->Preload(); |
823 } | 910 } |
824 | |
825 return visited_link_master_.get(); | |
826 } | 911 } |
827 | 912 |
828 ExtensionsService* ProfileImpl::GetExtensionsService() { | 913 ExtensionsService* ProfileImpl::GetExtensionsService() { |
829 return extensions_service_.get(); | 914 return extensions_service_.get(); |
830 } | 915 } |
831 | 916 |
832 UserScriptMaster* ProfileImpl::GetUserScriptMaster() { | 917 UserScriptMaster* ProfileImpl::GetUserScriptMaster() { |
833 return user_script_master_.get(); | 918 return user_script_master_.get(); |
834 } | 919 } |
835 | 920 |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1320 } | 1405 } |
1321 if (!sync_service_.get()) | 1406 if (!sync_service_.get()) |
1322 InitSyncService(); | 1407 InitSyncService(); |
1323 return sync_service_.get(); | 1408 return sync_service_.get(); |
1324 } | 1409 } |
1325 | 1410 |
1326 void ProfileImpl::InitSyncService() { | 1411 void ProfileImpl::InitSyncService() { |
1327 sync_service_.reset(new ProfileSyncService(this)); | 1412 sync_service_.reset(new ProfileSyncService(this)); |
1328 sync_service_->Initialize(); | 1413 sync_service_->Initialize(); |
1329 } | 1414 } |
OLD | NEW |