| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef IOS_CHROME_BROWSER_BROWSER_STATE_CHROME_BROWSER_STATE_IO_DATA_H_ | 5 #ifndef IOS_CHROME_BROWSER_BROWSER_STATE_CHROME_BROWSER_STATE_IO_DATA_H_ |
| 6 #define IOS_CHROME_BROWSER_BROWSER_STATE_CHROME_BROWSER_STATE_IO_DATA_H_ | 6 #define IOS_CHROME_BROWSER_BROWSER_STATE_CHROME_BROWSER_STATE_IO_DATA_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
| 13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/scoped_ptr.h" | |
| 17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "components/content_settings/core/common/content_settings_types.h" | 18 #include "components/content_settings/core/common/content_settings_types.h" |
| 19 #include "components/prefs/pref_member.h" | 19 #include "components/prefs/pref_member.h" |
| 20 #include "ios/chrome/browser/ios_chrome_io_thread.h" | 20 #include "ios/chrome/browser/ios_chrome_io_thread.h" |
| 21 #include "ios/chrome/browser/net/net_types.h" | 21 #include "ios/chrome/browser/net/net_types.h" |
| 22 #include "net/cert/ct_verifier.h" | 22 #include "net/cert/ct_verifier.h" |
| 23 #include "net/cookies/cookie_monster.h" | 23 #include "net/cookies/cookie_monster.h" |
| 24 #include "net/http/http_cache.h" | 24 #include "net/http/http_cache.h" |
| 25 #include "net/http/http_network_session.h" | 25 #include "net/http/http_network_session.h" |
| 26 #include "net/url_request/url_request_context.h" | 26 #include "net/url_request/url_request_context.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // methods other than GetResouceContext or GetMetricsEnabledStateOnIOThread. | 86 // methods other than GetResouceContext or GetMetricsEnabledStateOnIOThread. |
| 87 void Init(ProtocolHandlerMap* protocol_handlers) const; | 87 void Init(ProtocolHandlerMap* protocol_handlers) const; |
| 88 | 88 |
| 89 net::URLRequestContext* GetMainRequestContext() const; | 89 net::URLRequestContext* GetMainRequestContext() const; |
| 90 net::URLRequestContext* GetIsolatedAppRequestContext( | 90 net::URLRequestContext* GetIsolatedAppRequestContext( |
| 91 net::URLRequestContext* main_context, | 91 net::URLRequestContext* main_context, |
| 92 const base::FilePath& partition_path) const; | 92 const base::FilePath& partition_path) const; |
| 93 | 93 |
| 94 // Sets the cookie store associated with a partition path. | 94 // Sets the cookie store associated with a partition path. |
| 95 // The path must exist. If there is already a cookie store, it is deleted. | 95 // The path must exist. If there is already a cookie store, it is deleted. |
| 96 void SetCookieStoreForPartitionPath(scoped_ptr<net::CookieStore> cookie_store, | 96 void SetCookieStoreForPartitionPath( |
| 97 const base::FilePath& partition_path); | 97 std::unique_ptr<net::CookieStore> cookie_store, |
| 98 const base::FilePath& partition_path); |
| 98 | 99 |
| 99 // These are useful when the Chrome layer is called from the content layer | 100 // These are useful when the Chrome layer is called from the content layer |
| 100 // with a content::ResourceContext, and they want access to Chrome data for | 101 // with a content::ResourceContext, and they want access to Chrome data for |
| 101 // that browser state. | 102 // that browser state. |
| 102 content_settings::CookieSettings* GetCookieSettings() const; | 103 content_settings::CookieSettings* GetCookieSettings() const; |
| 103 HostContentSettingsMap* GetHostContentSettingsMap() const; | 104 HostContentSettingsMap* GetHostContentSettingsMap() const; |
| 104 | 105 |
| 105 StringPrefMember* google_services_account_id() const { | 106 StringPrefMember* google_services_account_id() const { |
| 106 return &google_services_user_account_id_; | 107 return &google_services_user_account_id_; |
| 107 } | 108 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 125 // thread, and should only be called from there. | 126 // thread, and should only be called from there. |
| 126 bool GetMetricsEnabledStateOnIOThread() const; | 127 bool GetMetricsEnabledStateOnIOThread() const; |
| 127 | 128 |
| 128 protected: | 129 protected: |
| 129 // A URLRequestContext for apps that owns its cookie store and HTTP factory, | 130 // A URLRequestContext for apps that owns its cookie store and HTTP factory, |
| 130 // to ensure they are deleted. | 131 // to ensure they are deleted. |
| 131 class AppRequestContext : public net::URLRequestContext { | 132 class AppRequestContext : public net::URLRequestContext { |
| 132 public: | 133 public: |
| 133 AppRequestContext(); | 134 AppRequestContext(); |
| 134 | 135 |
| 135 void SetCookieStore(scoped_ptr<net::CookieStore> cookie_store); | 136 void SetCookieStore(std::unique_ptr<net::CookieStore> cookie_store); |
| 136 void SetHttpTransactionFactory( | 137 void SetHttpTransactionFactory( |
| 137 scoped_ptr<net::HttpTransactionFactory> http_factory); | 138 std::unique_ptr<net::HttpTransactionFactory> http_factory); |
| 138 void SetJobFactory(scoped_ptr<net::URLRequestJobFactory> job_factory); | 139 void SetJobFactory(std::unique_ptr<net::URLRequestJobFactory> job_factory); |
| 139 | 140 |
| 140 ~AppRequestContext() override; | 141 ~AppRequestContext() override; |
| 141 | 142 |
| 142 private: | 143 private: |
| 143 scoped_ptr<net::CookieStore> cookie_store_; | 144 std::unique_ptr<net::CookieStore> cookie_store_; |
| 144 scoped_ptr<net::HttpTransactionFactory> http_factory_; | 145 std::unique_ptr<net::HttpTransactionFactory> http_factory_; |
| 145 scoped_ptr<net::URLRequestJobFactory> job_factory_; | 146 std::unique_ptr<net::URLRequestJobFactory> job_factory_; |
| 146 }; | 147 }; |
| 147 | 148 |
| 148 // Created on the UI thread, read on the IO thread during | 149 // Created on the UI thread, read on the IO thread during |
| 149 // ChromeBrowserStateIOData lazy initialization. | 150 // ChromeBrowserStateIOData lazy initialization. |
| 150 struct ProfileParams { | 151 struct ProfileParams { |
| 151 ProfileParams(); | 152 ProfileParams(); |
| 152 ~ProfileParams(); | 153 ~ProfileParams(); |
| 153 | 154 |
| 154 base::FilePath path; | 155 base::FilePath path; |
| 155 IOSChromeIOThread* io_thread; | 156 IOSChromeIOThread* io_thread; |
| 156 scoped_refptr<content_settings::CookieSettings> cookie_settings; | 157 scoped_refptr<content_settings::CookieSettings> cookie_settings; |
| 157 scoped_refptr<HostContentSettingsMap> host_content_settings_map; | 158 scoped_refptr<HostContentSettingsMap> host_content_settings_map; |
| 158 scoped_refptr<net::SSLConfigService> ssl_config_service; | 159 scoped_refptr<net::SSLConfigService> ssl_config_service; |
| 159 scoped_refptr<net::CookieMonsterDelegate> cookie_monster_delegate; | 160 scoped_refptr<net::CookieMonsterDelegate> cookie_monster_delegate; |
| 160 | 161 |
| 161 // We need to initialize the ProxyConfigService from the UI thread | 162 // We need to initialize the ProxyConfigService from the UI thread |
| 162 // because on linux it relies on initializing things through gconf, | 163 // because on linux it relies on initializing things through gconf, |
| 163 // and needs to be on the main thread. | 164 // and needs to be on the main thread. |
| 164 scoped_ptr<net::ProxyConfigService> proxy_config_service; | 165 std::unique_ptr<net::ProxyConfigService> proxy_config_service; |
| 165 | 166 |
| 166 // The browser state this struct was populated from. It's passed as a void* | 167 // The browser state this struct was populated from. It's passed as a void* |
| 167 // to ensure it's not accidently used on the IO thread. | 168 // to ensure it's not accidently used on the IO thread. |
| 168 void* browser_state; | 169 void* browser_state; |
| 169 }; | 170 }; |
| 170 | 171 |
| 171 explicit ChromeBrowserStateIOData( | 172 explicit ChromeBrowserStateIOData( |
| 172 ios::ChromeBrowserStateType browser_state_type); | 173 ios::ChromeBrowserStateType browser_state_type); |
| 173 | 174 |
| 174 void InitializeOnUIThread(ios::ChromeBrowserState* browser_state); | 175 void InitializeOnUIThread(ios::ChromeBrowserState* browser_state); |
| 175 void ApplyProfileParamsToContext(net::URLRequestContext* context) const; | 176 void ApplyProfileParamsToContext(net::URLRequestContext* context) const; |
| 176 | 177 |
| 177 scoped_ptr<net::URLRequestJobFactory> SetUpJobFactoryDefaults( | 178 std::unique_ptr<net::URLRequestJobFactory> SetUpJobFactoryDefaults( |
| 178 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory, | 179 std::unique_ptr<net::URLRequestJobFactoryImpl> job_factory, |
| 179 URLRequestInterceptorScopedVector request_interceptors, | 180 URLRequestInterceptorScopedVector request_interceptors, |
| 180 net::NetworkDelegate* network_delegate) const; | 181 net::NetworkDelegate* network_delegate) const; |
| 181 | 182 |
| 182 // Called when the ChromeBrowserState is destroyed. |context_getters| must | 183 // Called when the ChromeBrowserState is destroyed. |context_getters| must |
| 183 // include all URLRequestContextGetters that refer to the | 184 // include all URLRequestContextGetters that refer to the |
| 184 // ChromeBrowserStateIOData's URLRequestContexts. Triggers destruction of the | 185 // ChromeBrowserStateIOData's URLRequestContexts. Triggers destruction of the |
| 185 // ChromeBrowserStateIOData and shuts down |context_getters| safely on the IO | 186 // ChromeBrowserStateIOData and shuts down |context_getters| safely on the IO |
| 186 // thread. | 187 // thread. |
| 187 // TODO(mmenke): Passing all those URLRequestContextGetters around like this | 188 // TODO(mmenke): Passing all those URLRequestContextGetters around like this |
| 188 // is really silly. Can we do something cleaner? | 189 // is really silly. Can we do something cleaner? |
| 189 void ShutdownOnUIThread( | 190 void ShutdownOnUIThread( |
| 190 scoped_ptr<IOSChromeURLRequestContextGetterVector> context_getters); | 191 std::unique_ptr<IOSChromeURLRequestContextGetterVector> context_getters); |
| 191 | 192 |
| 192 // A ChannelIDService object is created by a derived class of | 193 // A ChannelIDService object is created by a derived class of |
| 193 // ChromeBrowserStateIOData, and the derived class calls this method to set | 194 // ChromeBrowserStateIOData, and the derived class calls this method to set |
| 194 // the channel_id_service_ member and transfers ownership to the base class. | 195 // the channel_id_service_ member and transfers ownership to the base class. |
| 195 void set_channel_id_service(net::ChannelIDService* channel_id_service) const; | 196 void set_channel_id_service(net::ChannelIDService* channel_id_service) const; |
| 196 | 197 |
| 197 net::ProxyService* proxy_service() const { return proxy_service_.get(); } | 198 net::ProxyService* proxy_service() const { return proxy_service_.get(); } |
| 198 | 199 |
| 199 base::WeakPtr<net::HttpServerProperties> http_server_properties() const; | 200 base::WeakPtr<net::HttpServerProperties> http_server_properties() const; |
| 200 | 201 |
| 201 void set_http_server_properties( | 202 void set_http_server_properties( |
| 202 scoped_ptr<net::HttpServerProperties> http_server_properties) const; | 203 std::unique_ptr<net::HttpServerProperties> http_server_properties) const; |
| 203 | 204 |
| 204 net::URLRequestContext* main_request_context() const { | 205 net::URLRequestContext* main_request_context() const { |
| 205 return main_request_context_.get(); | 206 return main_request_context_.get(); |
| 206 } | 207 } |
| 207 | 208 |
| 208 bool initialized() const { return initialized_; } | 209 bool initialized() const { return initialized_; } |
| 209 | 210 |
| 210 scoped_ptr<net::HttpNetworkSession> CreateHttpNetworkSession( | 211 std::unique_ptr<net::HttpNetworkSession> CreateHttpNetworkSession( |
| 211 const ProfileParams& profile_params) const; | 212 const ProfileParams& profile_params) const; |
| 212 | 213 |
| 213 // Creates main network transaction factory. | 214 // Creates main network transaction factory. |
| 214 scoped_ptr<net::HttpCache> CreateMainHttpFactory( | 215 std::unique_ptr<net::HttpCache> CreateMainHttpFactory( |
| 215 net::HttpNetworkSession* session, | 216 net::HttpNetworkSession* session, |
| 216 scoped_ptr<net::HttpCache::BackendFactory> main_backend) const; | 217 std::unique_ptr<net::HttpCache::BackendFactory> main_backend) const; |
| 217 | 218 |
| 218 // Creates network transaction factory. | 219 // Creates network transaction factory. |
| 219 scoped_ptr<net::HttpCache> CreateHttpFactory( | 220 std::unique_ptr<net::HttpCache> CreateHttpFactory( |
| 220 net::HttpNetworkSession* shared_session, | 221 net::HttpNetworkSession* shared_session, |
| 221 scoped_ptr<net::HttpCache::BackendFactory> backend) const; | 222 std::unique_ptr<net::HttpCache::BackendFactory> backend) const; |
| 222 | 223 |
| 223 private: | 224 private: |
| 224 typedef std::map<base::FilePath, AppRequestContext*> URLRequestContextMap; | 225 typedef std::map<base::FilePath, AppRequestContext*> URLRequestContextMap; |
| 225 | 226 |
| 226 // -------------------------------------------- | 227 // -------------------------------------------- |
| 227 // Virtual interface for subtypes to implement: | 228 // Virtual interface for subtypes to implement: |
| 228 // -------------------------------------------- | 229 // -------------------------------------------- |
| 229 | 230 |
| 230 // Does the actual initialization of the ChromeBrowserStateIOData subtype. | 231 // Does the actual initialization of the ChromeBrowserStateIOData subtype. |
| 231 // Subtypes should use the static helper functions above to implement this. | 232 // Subtypes should use the static helper functions above to implement this. |
| 232 virtual void InitializeInternal( | 233 virtual void InitializeInternal( |
| 233 scoped_ptr<IOSChromeNetworkDelegate> chrome_network_delegate, | 234 std::unique_ptr<IOSChromeNetworkDelegate> chrome_network_delegate, |
| 234 ProfileParams* profile_params, | 235 ProfileParams* profile_params, |
| 235 ProtocolHandlerMap* protocol_handlers) const = 0; | 236 ProtocolHandlerMap* protocol_handlers) const = 0; |
| 236 | 237 |
| 237 // Does an on-demand initialization of a RequestContext for the given | 238 // Does an on-demand initialization of a RequestContext for the given |
| 238 // isolated app. | 239 // isolated app. |
| 239 virtual AppRequestContext* InitializeAppRequestContext( | 240 virtual AppRequestContext* InitializeAppRequestContext( |
| 240 net::URLRequestContext* main_context) const = 0; | 241 net::URLRequestContext* main_context) const = 0; |
| 241 | 242 |
| 242 // These functions are used to transfer ownership of the lazily initialized | 243 // These functions are used to transfer ownership of the lazily initialized |
| 243 // context from ChromeBrowserStateIOData to the URLRequestContextGetter. | 244 // context from ChromeBrowserStateIOData to the URLRequestContextGetter. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 255 // * Therefore, ResourceContext should be listed last, and then the | 256 // * Therefore, ResourceContext should be listed last, and then the |
| 256 // URLRequestContexts, and then the URLRequestContext members. | 257 // URLRequestContexts, and then the URLRequestContext members. |
| 257 // * Note that URLRequestContext members have a directed dependency graph | 258 // * Note that URLRequestContext members have a directed dependency graph |
| 258 // too, so they must themselves be ordered correctly. | 259 // too, so they must themselves be ordered correctly. |
| 259 | 260 |
| 260 // Tracks whether or not we've been lazily initialized. | 261 // Tracks whether or not we've been lazily initialized. |
| 261 mutable bool initialized_; | 262 mutable bool initialized_; |
| 262 | 263 |
| 263 // Data from the UI thread from the ChromeBrowserState, used to initialize | 264 // Data from the UI thread from the ChromeBrowserState, used to initialize |
| 264 // ChromeBrowserStateIOData. Deleted after lazy initialization. | 265 // ChromeBrowserStateIOData. Deleted after lazy initialization. |
| 265 mutable scoped_ptr<ProfileParams> profile_params_; | 266 mutable std::unique_ptr<ProfileParams> profile_params_; |
| 266 | 267 |
| 267 mutable StringPrefMember google_services_user_account_id_; | 268 mutable StringPrefMember google_services_user_account_id_; |
| 268 | 269 |
| 269 // Member variables which are pointed to by the various context objects. | 270 // Member variables which are pointed to by the various context objects. |
| 270 mutable BooleanPrefMember enable_referrers_; | 271 mutable BooleanPrefMember enable_referrers_; |
| 271 mutable BooleanPrefMember enable_do_not_track_; | 272 mutable BooleanPrefMember enable_do_not_track_; |
| 272 mutable BooleanPrefMember sync_disabled_; | 273 mutable BooleanPrefMember sync_disabled_; |
| 273 mutable BooleanPrefMember signin_allowed_; | 274 mutable BooleanPrefMember signin_allowed_; |
| 274 | 275 |
| 275 BooleanPrefMember enable_metrics_; | 276 BooleanPrefMember enable_metrics_; |
| 276 | 277 |
| 277 // Pointed to by URLRequestContext. | 278 // Pointed to by URLRequestContext. |
| 278 mutable scoped_ptr<net::ChannelIDService> channel_id_service_; | 279 mutable std::unique_ptr<net::ChannelIDService> channel_id_service_; |
| 279 | 280 |
| 280 mutable scoped_ptr<net::ProxyService> proxy_service_; | 281 mutable std::unique_ptr<net::ProxyService> proxy_service_; |
| 281 mutable scoped_ptr<net::TransportSecurityState> transport_security_state_; | 282 mutable std::unique_ptr<net::TransportSecurityState> |
| 282 mutable scoped_ptr<net::CTVerifier> cert_transparency_verifier_; | 283 transport_security_state_; |
| 283 mutable scoped_ptr<net::HttpServerProperties> http_server_properties_; | 284 mutable std::unique_ptr<net::CTVerifier> cert_transparency_verifier_; |
| 284 mutable scoped_ptr<net::TransportSecurityPersister> | 285 mutable std::unique_ptr<net::HttpServerProperties> http_server_properties_; |
| 286 mutable std::unique_ptr<net::TransportSecurityPersister> |
| 285 transport_security_persister_; | 287 transport_security_persister_; |
| 286 mutable scoped_ptr<net::CertificateReportSender> certificate_report_sender_; | 288 mutable std::unique_ptr<net::CertificateReportSender> |
| 289 certificate_report_sender_; |
| 287 | 290 |
| 288 // These are only valid in between LazyInitialize() and their accessor being | 291 // These are only valid in between LazyInitialize() and their accessor being |
| 289 // called. | 292 // called. |
| 290 mutable scoped_ptr<net::URLRequestContext> main_request_context_; | 293 mutable std::unique_ptr<net::URLRequestContext> main_request_context_; |
| 291 // One URLRequestContext per isolated app for main and media requests. | 294 // One URLRequestContext per isolated app for main and media requests. |
| 292 mutable URLRequestContextMap app_request_context_map_; | 295 mutable URLRequestContextMap app_request_context_map_; |
| 293 | 296 |
| 294 mutable scoped_refptr<content_settings::CookieSettings> cookie_settings_; | 297 mutable scoped_refptr<content_settings::CookieSettings> cookie_settings_; |
| 295 | 298 |
| 296 mutable scoped_refptr<HostContentSettingsMap> host_content_settings_map_; | 299 mutable scoped_refptr<HostContentSettingsMap> host_content_settings_map_; |
| 297 | 300 |
| 298 mutable scoped_ptr<IOSChromeHttpUserAgentSettings> | 301 mutable std::unique_ptr<IOSChromeHttpUserAgentSettings> |
| 299 chrome_http_user_agent_settings_; | 302 chrome_http_user_agent_settings_; |
| 300 | 303 |
| 301 // TODO(jhawkins): Remove once crbug.com/102004 is fixed. | 304 // TODO(jhawkins): Remove once crbug.com/102004 is fixed. |
| 302 bool initialized_on_UI_thread_; | 305 bool initialized_on_UI_thread_; |
| 303 | 306 |
| 304 const ios::ChromeBrowserStateType browser_state_type_; | 307 const ios::ChromeBrowserStateType browser_state_type_; |
| 305 | 308 |
| 306 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserStateIOData); | 309 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserStateIOData); |
| 307 }; | 310 }; |
| 308 | 311 |
| 309 #endif // IOS_CHROME_BROWSER_BROWSER_STATE_CHROME_BROWSER_STATE_IO_DATA_H_ | 312 #endif // IOS_CHROME_BROWSER_BROWSER_STATE_CHROME_BROWSER_STATE_IO_DATA_H_ |
| OLD | NEW |