9751628547e7f78b4eb3c7ef1ba7c1ec769ece44
[platform/framework/web/crosswalk.git] / src / chrome / browser / profiles / profile_impl.h
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
3 // found in the LICENSE file.
4
5 // This class gathers state related to a single user profile.
6
7 #ifndef CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_
8 #define CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_
9
10 #include <string>
11
12 #include "base/files/file_path.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/prefs/pref_change_registrar.h"
17 #include "base/timer/timer.h"
18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/profiles/profile_impl_io_data.h"
20 #include "content/public/browser/content_browser_client.h"
21 #include "content/public/browser/host_zoom_map.h"
22
23 class NetPrefObserver;
24 class PrefService;
25 class PrefServiceSyncable;
26 class SSLConfigServiceManager;
27
28 #if defined(OS_CHROMEOS)
29 namespace chromeos {
30 class LocaleChangeGuard;
31 class Preferences;
32 }
33 #endif
34
35 namespace base {
36 class SequencedTaskRunner;
37 }
38
39 namespace extensions {
40 class ExtensionSystem;
41 }
42
43 namespace policy {
44 class CloudPolicyManager;
45 class ProfilePolicyConnector;
46 class SchemaRegistryService;
47 }
48
49 namespace user_prefs {
50 class refRegistrySyncable;
51 }
52
53 // The default profile implementation.
54 class ProfileImpl : public Profile {
55  public:
56   // Value written to prefs when the exit type is EXIT_NORMAL. Public for tests.
57   static const char* const kPrefExitTypeNormal;
58
59   virtual ~ProfileImpl();
60
61   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
62
63   // Ensures that the preference hash store has been initialized for the profile
64   // at |profile_path|.
65   static void InitializePrefHashStoreIfRequired(
66       const base::FilePath& profile_path);
67
68   // Resets the contents of the preference hash store for the profile at
69   // |profile_path|.
70   static void ResetPrefHashStore(const base::FilePath& profile_path);
71
72   // content::BrowserContext implementation:
73   virtual base::FilePath GetPath() const OVERRIDE;
74   virtual content::DownloadManagerDelegate*
75       GetDownloadManagerDelegate() OVERRIDE;
76   virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
77   virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
78       int renderer_child_id) OVERRIDE;
79   virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE;
80   virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
81       int renderer_child_id) OVERRIDE;
82   virtual net::URLRequestContextGetter*
83       GetMediaRequestContextForStoragePartition(
84           const base::FilePath& partition_path,
85           bool in_memory) OVERRIDE;
86   virtual void RequestMIDISysExPermission(
87       int render_process_id,
88       int render_view_id,
89       int bridge_id,
90       const GURL& requesting_frame,
91       const MIDISysExPermissionCallback& callback) OVERRIDE;
92   virtual void CancelMIDISysExPermissionRequest(
93       int render_process_id,
94       int render_view_id,
95       int bridge_id,
96       const GURL& requesting_frame) OVERRIDE;
97   virtual void RequestProtectedMediaIdentifierPermission(
98       int render_process_id,
99       int render_view_id,
100       int bridge_id,
101       int group_id,
102       const GURL& requesting_frame,
103       const ProtectedMediaIdentifierPermissionCallback& callback) OVERRIDE;
104   virtual void CancelProtectedMediaIdentifierPermissionRequests(
105       int group_id) OVERRIDE;
106   virtual content::ResourceContext* GetResourceContext() OVERRIDE;
107   virtual content::GeolocationPermissionContext*
108       GetGeolocationPermissionContext() OVERRIDE;
109   virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
110
111   // Profile implementation:
112   virtual scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() OVERRIDE;
113   // Note that this implementation returns the Google-services username, if any,
114   // not the Chrome user's display name.
115   virtual std::string GetProfileName() OVERRIDE;
116   virtual bool IsOffTheRecord() const OVERRIDE;
117   virtual Profile* GetOffTheRecordProfile() OVERRIDE;
118   virtual void DestroyOffTheRecordProfile() OVERRIDE;
119   virtual bool HasOffTheRecordProfile() OVERRIDE;
120   virtual Profile* GetOriginalProfile() OVERRIDE;
121   virtual bool IsManaged() OVERRIDE;
122   virtual history::TopSites* GetTopSites() OVERRIDE;
123   virtual history::TopSites* GetTopSitesWithoutCreating() OVERRIDE;
124   virtual ExtensionService* GetExtensionService() OVERRIDE;
125   virtual ExtensionSpecialStoragePolicy*
126       GetExtensionSpecialStoragePolicy() OVERRIDE;
127   virtual PrefService* GetPrefs() OVERRIDE;
128   virtual PrefService* GetOffTheRecordPrefs() OVERRIDE;
129   virtual net::URLRequestContextGetter*
130       GetRequestContextForExtensions() OVERRIDE;
131   virtual net::SSLConfigService* GetSSLConfigService() OVERRIDE;
132   virtual HostContentSettingsMap* GetHostContentSettingsMap() OVERRIDE;
133   virtual bool IsSameProfile(Profile* profile) OVERRIDE;
134   virtual base::Time GetStartTime() const OVERRIDE;
135   virtual net::URLRequestContextGetter* CreateRequestContext(
136       content::ProtocolHandlerMap* protocol_handlers) OVERRIDE;
137   virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
138       const base::FilePath& partition_path,
139       bool in_memory,
140       content::ProtocolHandlerMap* protocol_handlers) OVERRIDE;
141   virtual base::FilePath last_selected_directory() OVERRIDE;
142   virtual void set_last_selected_directory(const base::FilePath& path) OVERRIDE;
143   virtual chrome_browser_net::Predictor* GetNetworkPredictor() OVERRIDE;
144   virtual void ClearNetworkingHistorySince(
145       base::Time time,
146       const base::Closure& completion) OVERRIDE;
147   virtual GURL GetHomePage() OVERRIDE;
148   virtual bool WasCreatedByVersionOrLater(const std::string& version) OVERRIDE;
149   virtual void SetExitType(ExitType exit_type) OVERRIDE;
150   virtual ExitType GetLastSessionExitType() OVERRIDE;
151
152 #if defined(OS_CHROMEOS)
153   virtual void ChangeAppLocale(const std::string& locale,
154                                AppLocaleChangedVia) OVERRIDE;
155   virtual void OnLogin() OVERRIDE;
156   virtual void InitChromeOSPreferences() OVERRIDE;
157 #endif  // defined(OS_CHROMEOS)
158
159   virtual PrefProxyConfigTracker* GetProxyConfigTracker() OVERRIDE;
160
161  private:
162   friend class Profile;
163   friend class BetterSessionRestoreCrashTest;
164   FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
165                            ProfilesLaunchedAfterCrash);
166   FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest, ProfileReadmeCreated);
167   FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest,
168                            ProfileDeletedBeforeReadmeCreated);
169
170   // Delay, in milliseconds, before README file is created for a new profile.
171   // This is non-const for testing purposes.
172   static int create_readme_delay_ms;
173
174   ProfileImpl(const base::FilePath& path,
175               Delegate* delegate,
176               CreateMode create_mode,
177               base::SequencedTaskRunner* sequenced_task_runner);
178
179   // Does final initialization. Should be called after prefs were loaded.
180   void DoFinalInit();
181
182   void InitHostZoomMap();
183
184   void OnDefaultZoomLevelChanged();
185   void OnZoomLevelChanged(
186       const content::HostZoomMap::ZoomLevelChange& change);
187
188   // Does final prefs initialization and calls Init().
189   void OnPrefsLoaded(bool success);
190
191   base::FilePath GetPrefFilePath();
192
193 #if defined(ENABLE_SESSION_SERVICE)
194   void StopCreateSessionServiceTimer();
195
196   void EnsureSessionServiceCreated();
197 #endif
198
199
200   void EnsureRequestContextCreated() {
201     GetRequestContext();
202   }
203
204   void UpdateProfileUserNameCache();
205
206   // Updates the ProfileInfoCache with data from this profile.
207   void UpdateProfileNameCache();
208   void UpdateProfileAvatarCache();
209   void UpdateProfileIsEphemeralCache();
210
211   void GetCacheParameters(bool is_media_context,
212                           base::FilePath* cache_path,
213                           int* max_size);
214
215   PrefProxyConfigTracker* CreateProxyConfigTracker();
216
217   scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_;
218   PrefChangeRegistrar pref_change_registrar_;
219
220   base::FilePath path_;
221   base::FilePath base_cache_path_;
222
223   // !!! BIG HONKING WARNING !!!
224   //  The order of the members below is important. Do not change it unless
225   //  you know what you're doing. Also, if adding a new member here make sure
226   //  that the declaration occurs AFTER things it depends on as destruction
227   //  happens in reverse order of declaration.
228
229   // TODO(mnissler, joaodasilva): The |profile_policy_connector_| provides the
230   // PolicyService that the |prefs_| depend on, and must outlive |prefs_|.
231   // This can be removed once |prefs_| becomes a BrowserContextKeyedService too.
232   // |profile_policy_connector_| in turn depends on |cloud_policy_manager_|,
233   // which depends on |schema_registry_service_|.
234 #if defined(ENABLE_CONFIGURATION_POLICY)
235   scoped_ptr<policy::SchemaRegistryService> schema_registry_service_;
236   scoped_ptr<policy::CloudPolicyManager> cloud_policy_manager_;
237 #endif
238   scoped_ptr<policy::ProfilePolicyConnector> profile_policy_connector_;
239
240   // Keep |prefs_| on top for destruction order because |extension_prefs_|,
241   // |net_pref_observer_|, |io_data_| and others store pointers to |prefs_| and
242   // shall be destructed first.
243   scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_;
244   scoped_ptr<PrefServiceSyncable> prefs_;
245   scoped_ptr<PrefServiceSyncable> otr_prefs_;
246   ProfileImplIOData::Handle io_data_;
247   scoped_refptr<ExtensionSpecialStoragePolicy>
248       extension_special_storage_policy_;
249   scoped_ptr<NetPrefObserver> net_pref_observer_;
250   scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_;
251   scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
252   scoped_refptr<history::ShortcutsBackend> shortcuts_backend_;
253
254   // Exit type the last time the profile was opened. This is set only once from
255   // prefs.
256   ExitType last_session_exit_type_;
257
258 #if defined(ENABLE_SESSION_SERVICE)
259   base::OneShotTimer<ProfileImpl> create_session_service_timer_;
260 #endif
261
262   scoped_ptr<Profile> off_the_record_profile_;
263
264   // See GetStartTime for details.
265   base::Time start_time_;
266
267   scoped_refptr<history::TopSites> top_sites_;  // For history and thumbnails.
268
269 #if defined(OS_CHROMEOS)
270   scoped_ptr<chromeos::Preferences> chromeos_preferences_;
271
272   scoped_ptr<chromeos::LocaleChangeGuard> locale_change_guard_;
273
274   bool is_login_profile_;
275 #endif
276
277   scoped_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
278
279   // STOP!!!! DO NOT ADD ANY MORE ITEMS HERE!!!!
280   //
281   // Instead, make your Service/Manager/whatever object you're hanging off the
282   // Profile use our new BrowserContextKeyedServiceFactory system instead.
283   // You can find the design document here:
284   //
285   //   https://sites.google.com/a/chromium.org/dev/developers/design-documents/profile-architecture
286   //
287   // and you can read the raw headers here:
288   //
289   //   components/browser_context_keyed_service/browser_context_dependency_manager.{h,cc}
290   //   components/browser_context_keyed_service/browser_context_keyed_service.h
291   //   components/browser_context_keyed_service/browser_context_keyed_service_factory.{h,cc}
292
293   Profile::Delegate* delegate_;
294
295   chrome_browser_net::Predictor* predictor_;
296
297   DISALLOW_COPY_AND_ASSIGN(ProfileImpl);
298 };
299
300 #endif  // CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_