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 "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "chrome/browser/prefs/pref_registry_syncable.h" | |
12 #include "chrome/browser/sync/profile_sync_service.h" | 11 #include "chrome/browser/sync/profile_sync_service.h" |
13 #include "chrome/browser/sync/sync_prefs.h" | 12 #include "chrome/browser/sync/sync_prefs.h" |
14 #include "chrome/common/chrome_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
15 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
15 #include "components/user_prefs/pref_registry_syncable.h" | |
16 #include "components/user_prefs/user_prefs.h" | |
17 #include "components/user_prefs/user_prefs_delegate.h" | |
16 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
17 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
18 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
19 #include "content/public/browser/web_ui.h" | 21 #include "content/public/browser/web_ui.h" |
20 | 22 |
21 #if defined(OS_CHROMEOS) | 23 #if defined(OS_CHROMEOS) |
22 #include "base/command_line.h" | 24 #include "base/command_line.h" |
23 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
24 #endif | 26 #endif |
25 | 27 |
28 namespace { | |
29 | |
30 // Used to initialize the UserPrefs component. | |
31 class ChromeUserPrefsDelegate : public components::UserPrefsDelegate { | |
32 public: | |
33 ChromeUserPrefsDelegate() {} | |
34 virtual ~ChromeUserPrefsDelegate() {} | |
35 | |
36 virtual PrefService* PrefServiceFromBrowserContext( | |
37 content::BrowserContext* context) OVERRIDE { | |
38 return static_cast<Profile*>(context)->GetPrefs(); | |
39 } | |
40 | |
41 private: | |
42 DISALLOW_COPY_AND_ASSIGN(ChromeUserPrefsDelegate); | |
43 }; | |
44 | |
45 } // namespace | |
46 | |
26 Profile::Profile() | 47 Profile::Profile() |
27 : restored_last_session_(false), | 48 : restored_last_session_(false), |
28 sent_destroyed_notification_(false), | 49 sent_destroyed_notification_(false), |
29 accessibility_pause_level_(0) { | 50 accessibility_pause_level_(0) { |
51 // One-time initialization of UserPrefs. This is the safest to do | |
52 // it, since there can be no PrefService for user preferences unless | |
53 // there is a Profile, and even test code will create a Profile | |
54 // object if it uses a Profile at all, although it may bypass | |
55 // e.g. BrowserProcess or ProfileManager or | |
56 // chrome_prefs::CreateProfilePrefs. | |
57 components::UserPrefs* user_prefs = components::UserPrefs::GetInstance(); | |
Elliot Glaysher
2013/02/28 21:58:57
You mentioned ContetnClient. If this is supposed t
| |
58 if (!user_prefs->IsInitialized()) { | |
59 user_prefs->Initialize(scoped_ptr<components::UserPrefsDelegate>( | |
60 new ChromeUserPrefsDelegate).Pass()); | |
61 } | |
30 } | 62 } |
31 | 63 |
32 // static | 64 // static |
33 Profile* Profile::FromBrowserContext(content::BrowserContext* browser_context) { | 65 Profile* Profile::FromBrowserContext(content::BrowserContext* browser_context) { |
34 // This is safe; this is the only implementation of the browser context. | 66 // This is safe; this is the only implementation of the browser context. |
35 return static_cast<Profile*>(browser_context); | 67 return static_cast<Profile*>(browser_context); |
36 } | 68 } |
37 | 69 |
38 // static | 70 // static |
39 Profile* Profile::FromWebUI(content::WebUI* web_ui) { | 71 Profile* Profile::FromWebUI(content::WebUI* web_ui) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 | 168 |
137 void Profile::MaybeSendDestroyedNotification() { | 169 void Profile::MaybeSendDestroyedNotification() { |
138 if (!sent_destroyed_notification_) { | 170 if (!sent_destroyed_notification_) { |
139 sent_destroyed_notification_ = true; | 171 sent_destroyed_notification_ = true; |
140 content::NotificationService::current()->Notify( | 172 content::NotificationService::current()->Notify( |
141 chrome::NOTIFICATION_PROFILE_DESTROYED, | 173 chrome::NOTIFICATION_PROFILE_DESTROYED, |
142 content::Source<Profile>(this), | 174 content::Source<Profile>(this), |
143 content::NotificationService::NoDetails()); | 175 content::NotificationService::NoDetails()); |
144 } | 176 } |
145 } | 177 } |
OLD | NEW |