| 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/browser/profiles/profile.h" | 5 #include "chrome/browser/profiles/profile.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #endif | 33 #endif |
| 34 | 34 |
| 35 #if !defined(OS_ANDROID) | 35 #if !defined(OS_ANDROID) |
| 36 #include "content/public/browser/host_zoom_map.h" | 36 #include "content/public/browser/host_zoom_map.h" |
| 37 #endif | 37 #endif |
| 38 | 38 |
| 39 #if BUILDFLAG(ENABLE_EXTENSIONS) | 39 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 40 #include "extensions/browser/pref_names.h" | 40 #include "extensions/browser/pref_names.h" |
| 41 #endif | 41 #endif |
| 42 | 42 |
| 43 #if DCHECK_IS_ON() |
| 44 |
| 45 #include <set> |
| 46 #include "base/lazy_instance.h" |
| 47 #include "base/logging.h" |
| 48 #include "base/synchronization/lock.h" |
| 49 |
| 50 namespace { |
| 51 |
| 52 base::LazyInstance<base::Lock>::Leaky g_instances_lock = |
| 53 LAZY_INSTANCE_INITIALIZER; |
| 54 base::LazyInstance<std::set<content::BrowserContext*>>::Leaky g_instances = |
| 55 LAZY_INSTANCE_INITIALIZER; |
| 56 |
| 57 } // namespace |
| 58 |
| 59 #endif // DCHECK_IS_ON() |
| 60 |
| 43 Profile::Profile() | 61 Profile::Profile() |
| 44 : restored_last_session_(false), | 62 : restored_last_session_(false), |
| 45 sent_destroyed_notification_(false), | 63 sent_destroyed_notification_(false), |
| 46 accessibility_pause_level_(0), | 64 accessibility_pause_level_(0), |
| 47 is_guest_profile_(false), | 65 is_guest_profile_(false), |
| 48 is_system_profile_(false) { | 66 is_system_profile_(false) { |
| 67 #if DCHECK_IS_ON() |
| 68 base::AutoLock lock(g_instances_lock.Get()); |
| 69 g_instances.Get().insert(this); |
| 70 #endif // DCHECK_IS_ON() |
| 49 } | 71 } |
| 50 | 72 |
| 51 Profile::~Profile() { | 73 Profile::~Profile() { |
| 74 #if DCHECK_IS_ON() |
| 75 base::AutoLock lock(g_instances_lock.Get()); |
| 76 g_instances.Get().erase(this); |
| 77 #endif // DCHECK_IS_ON() |
| 52 } | 78 } |
| 53 | 79 |
| 54 // static | 80 // static |
| 55 Profile* Profile::FromBrowserContext(content::BrowserContext* browser_context) { | 81 Profile* Profile::FromBrowserContext(content::BrowserContext* browser_context) { |
| 56 // This is safe; this is the only implementation of the browser context. | 82 if (!browser_context) |
| 83 return nullptr; |
| 84 |
| 85 // For code running in a chrome/ environment, it is safe to cast to Profile* |
| 86 // because Profile is the only implementation of BrowserContext used. In |
| 87 // testing, however, there are several BrowserContext subclasses that are not |
| 88 // Profile subclasses, and we can catch them. http://crbug.com/725276 |
| 89 #if DCHECK_IS_ON() |
| 90 base::AutoLock lock(g_instances_lock.Get()); |
| 91 if (!g_instances.Get().count(browser_context)) { |
| 92 DCHECK(false) |
| 93 << "Non-Profile BrowserContext passed to Profile::FromBrowserContext! " |
| 94 "If you have a test linked in chrome/ you need a chrome/ based test " |
| 95 "class such as TestingProfile in chrome/test/base/testing_profile.h " |
| 96 "or you need to subclass your test class from Profile, not from " |
| 97 "BrowserContext."; |
| 98 } |
| 99 #endif // DCHECK_IS_ON() |
| 57 return static_cast<Profile*>(browser_context); | 100 return static_cast<Profile*>(browser_context); |
| 58 } | 101 } |
| 59 | 102 |
| 60 // static | 103 // static |
| 61 Profile* Profile::FromWebUI(content::WebUI* web_ui) { | 104 Profile* Profile::FromWebUI(content::WebUI* web_ui) { |
| 62 return FromBrowserContext(web_ui->GetWebContents()->GetBrowserContext()); | 105 return FromBrowserContext(web_ui->GetWebContents()->GetBrowserContext()); |
| 63 } | 106 } |
| 64 | 107 |
| 65 TestingProfile* Profile::AsTestingProfile() { | 108 TestingProfile* Profile::AsTestingProfile() { |
| 66 return NULL; | 109 return nullptr; |
| 67 } | 110 } |
| 68 | 111 |
| 69 #if !defined(OS_ANDROID) | 112 #if !defined(OS_ANDROID) |
| 70 ChromeZoomLevelPrefs* Profile::GetZoomLevelPrefs() { | 113 ChromeZoomLevelPrefs* Profile::GetZoomLevelPrefs() { |
| 71 return NULL; | 114 return nullptr; |
| 72 } | 115 } |
| 73 #endif // !defined(OS_ANDROID) | 116 #endif // !defined(OS_ANDROID) |
| 74 | 117 |
| 75 Profile::Delegate::~Delegate() { | 118 Profile::Delegate::~Delegate() { |
| 76 } | 119 } |
| 77 | 120 |
| 78 // static | 121 // static |
| 79 const char Profile::kProfileKey[] = "__PROFILE__"; | 122 const char Profile::kProfileKey[] = "__PROFILE__"; |
| 80 // This must be a string which can never be a valid domain. | 123 // This must be a string which can never be a valid domain. |
| 81 const char Profile::kNoHostedDomainFound[] = "NO_HOSTED_DOMAIN"; | 124 const char Profile::kNoHostedDomainFound[] = "NO_HOSTED_DOMAIN"; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 return a->GetOriginalProfile() < b->GetOriginalProfile(); | 296 return a->GetOriginalProfile() < b->GetOriginalProfile(); |
| 254 } | 297 } |
| 255 | 298 |
| 256 #if !defined(OS_ANDROID) | 299 #if !defined(OS_ANDROID) |
| 257 double Profile::GetDefaultZoomLevelForProfile() { | 300 double Profile::GetDefaultZoomLevelForProfile() { |
| 258 return GetDefaultStoragePartition(this) | 301 return GetDefaultStoragePartition(this) |
| 259 ->GetHostZoomMap() | 302 ->GetHostZoomMap() |
| 260 ->GetDefaultZoomLevel(); | 303 ->GetDefaultZoomLevel(); |
| 261 } | 304 } |
| 262 #endif // !defined(OS_ANDROID) | 305 #endif // !defined(OS_ANDROID) |
| OLD | NEW |