| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CHROME_BROWSER_PROFILES_PROFILE_IMPL_IO_DATA_H_ | 5 #ifndef CHROME_BROWSER_PROFILES_PROFILE_IMPL_IO_DATA_H_ |
| 6 #define CHROME_BROWSER_PROFILES_PROFILE_IMPL_IO_DATA_H_ | 6 #define CHROME_BROWSER_PROFILES_PROFILE_IMPL_IO_DATA_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/hash_tables.h" |
| 10 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
| 11 #include "chrome/browser/profiles/profile_io_data.h" | 12 #include "chrome/browser/profiles/profile_io_data.h" |
| 12 | 13 |
| 13 namespace net { | 14 namespace net { |
| 14 class NetworkDelegate; | 15 class NetworkDelegate; |
| 15 class DnsCertProvenanceChecker; | 16 class DnsCertProvenanceChecker; |
| 16 class HttpTransactionFactory; | 17 class HttpTransactionFactory; |
| 17 } // namespace net | 18 } // namespace net |
| 18 | 19 |
| 19 class ProfileImplIOData : public ProfileIOData { | 20 class ProfileImplIOData : public ProfileIOData { |
| 20 public: | 21 public: |
| 21 class Handle { | 22 class Handle { |
| 22 public: | 23 public: |
| 23 explicit Handle(Profile* profile); | 24 explicit Handle(Profile* profile); |
| 24 ~Handle(); | 25 ~Handle(); |
| 25 | 26 |
| 26 bool HasMainRequestContext() const { | 27 bool HasMainRequestContext() const { |
| 27 return main_request_context_getter_ != NULL; | 28 return main_request_context_getter_ != NULL; |
| 28 } | 29 } |
| 29 | 30 |
| 30 // Init() must be called before ~Handle(). It records all the necessary | 31 // Init() must be called before ~Handle(). It records all the necessary |
| 31 // parameters needed to construct a ChromeURLRequestContextGetter. | 32 // parameters needed to construct a ChromeURLRequestContextGetter. |
| 32 void Init(const FilePath& cookie_path, | 33 void Init(const FilePath& cookie_path, |
| 33 const FilePath& cache_path, | 34 const FilePath& cache_path, |
| 34 int cache_max_size, | 35 int cache_max_size, |
| 35 const FilePath& media_cache_path, | 36 const FilePath& media_cache_path, |
| 36 int media_cache_max_size, | 37 int media_cache_max_size, |
| 37 const FilePath& extensions_cookie_path); | 38 const FilePath& extensions_cookie_path, |
| 39 const FilePath& app_path); |
| 38 | 40 |
| 39 scoped_refptr<ChromeURLRequestContextGetter> | 41 scoped_refptr<ChromeURLRequestContextGetter> |
| 40 GetMainRequestContextGetter() const; | 42 GetMainRequestContextGetter() const; |
| 41 scoped_refptr<ChromeURLRequestContextGetter> | 43 scoped_refptr<ChromeURLRequestContextGetter> |
| 42 GetMediaRequestContextGetter() const; | 44 GetMediaRequestContextGetter() const; |
| 43 scoped_refptr<ChromeURLRequestContextGetter> | 45 scoped_refptr<ChromeURLRequestContextGetter> |
| 44 GetExtensionsRequestContextGetter() const; | 46 GetExtensionsRequestContextGetter() const; |
| 47 scoped_refptr<ChromeURLRequestContextGetter> |
| 48 GetIsolatedAppRequestContextGetter( |
| 49 const Extension* installed_app) const; |
| 45 | 50 |
| 46 private: | 51 private: |
| 52 typedef base::hash_map<std::string, |
| 53 scoped_refptr<ChromeURLRequestContextGetter> > |
| 54 ChromeURLRequestContextGetterMap; |
| 55 |
| 47 // Lazily initialize ProfileParams. We do this on the calls to | 56 // Lazily initialize ProfileParams. We do this on the calls to |
| 48 // Get*RequestContextGetter(), so we only initialize ProfileParams right | 57 // Get*RequestContextGetter(), so we only initialize ProfileParams right |
| 49 // before posting a task to the IO thread to start using them. This prevents | 58 // before posting a task to the IO thread to start using them. This prevents |
| 50 // objects that are supposed to be deleted on the IO thread, but are created | 59 // objects that are supposed to be deleted on the IO thread, but are created |
| 51 // on the UI thread from being unnecessarily initialized. | 60 // on the UI thread from being unnecessarily initialized. |
| 52 void LazyInitialize() const; | 61 void LazyInitialize() const; |
| 53 | 62 |
| 54 // Ordering is important here. Do not reorder unless you know what you're | 63 // Ordering is important here. Do not reorder unless you know what you're |
| 55 // doing. We need to release |io_data_| *before* the getters, because we | 64 // doing. We need to release |io_data_| *before* the getters, because we |
| 56 // want to make sure that the last reference for |io_data_| is on the IO | 65 // want to make sure that the last reference for |io_data_| is on the IO |
| 57 // thread. The getters will be deleted on the IO thread, so they will | 66 // thread. The getters will be deleted on the IO thread, so they will |
| 58 // release their refs to their contexts, which will release the last refs to | 67 // release their refs to their contexts, which will release the last refs to |
| 59 // the ProfileIOData on the IO thread. | 68 // the ProfileIOData on the IO thread. |
| 60 mutable scoped_refptr<ChromeURLRequestContextGetter> | 69 mutable scoped_refptr<ChromeURLRequestContextGetter> |
| 61 main_request_context_getter_; | 70 main_request_context_getter_; |
| 62 mutable scoped_refptr<ChromeURLRequestContextGetter> | 71 mutable scoped_refptr<ChromeURLRequestContextGetter> |
| 63 media_request_context_getter_; | 72 media_request_context_getter_; |
| 64 mutable scoped_refptr<ChromeURLRequestContextGetter> | 73 mutable scoped_refptr<ChromeURLRequestContextGetter> |
| 65 extensions_request_context_getter_; | 74 extensions_request_context_getter_; |
| 75 mutable ChromeURLRequestContextGetterMap app_request_context_getter_map_; |
| 66 const scoped_refptr<ProfileImplIOData> io_data_; | 76 const scoped_refptr<ProfileImplIOData> io_data_; |
| 67 | 77 |
| 68 Profile* const profile_; | 78 Profile* const profile_; |
| 69 | 79 |
| 70 mutable bool initialized_; | 80 mutable bool initialized_; |
| 71 | 81 |
| 72 DISALLOW_COPY_AND_ASSIGN(Handle); | 82 DISALLOW_COPY_AND_ASSIGN(Handle); |
| 73 }; | 83 }; |
| 74 | 84 |
| 75 private: | 85 private: |
| 76 friend class base::RefCountedThreadSafe<ProfileImplIOData>; | 86 friend class base::RefCountedThreadSafe<ProfileImplIOData>; |
| 77 | 87 |
| 78 struct LazyParams { | 88 struct LazyParams { |
| 79 LazyParams(); | 89 LazyParams(); |
| 80 ~LazyParams(); | 90 ~LazyParams(); |
| 81 | 91 |
| 82 // All of these parameters are intended to be read on the IO thread. | 92 // All of these parameters are intended to be read on the IO thread. |
| 83 FilePath cookie_path; | 93 FilePath cookie_path; |
| 84 FilePath cache_path; | 94 FilePath cache_path; |
| 85 int cache_max_size; | 95 int cache_max_size; |
| 86 FilePath media_cache_path; | 96 FilePath media_cache_path; |
| 87 int media_cache_max_size; | 97 int media_cache_max_size; |
| 88 FilePath extensions_cookie_path; | 98 FilePath extensions_cookie_path; |
| 89 IOThread* io_thread; | 99 IOThread* io_thread; |
| 90 | 100 |
| 91 ProfileParams profile_params; | 101 ProfileParams profile_params; |
| 92 }; | 102 }; |
| 93 | 103 |
| 104 typedef base::hash_map<std::string, net::HttpTransactionFactory* > |
| 105 HttpTransactionFactoryMap; |
| 106 |
| 94 ProfileImplIOData(); | 107 ProfileImplIOData(); |
| 95 virtual ~ProfileImplIOData(); | 108 virtual ~ProfileImplIOData(); |
| 96 | 109 |
| 97 // Lazily initializes ProfileImplIOData. | 110 // Lazily initializes ProfileImplIOData. |
| 98 virtual void LazyInitializeInternal() const; | 111 virtual void LazyInitializeInternal() const; |
| 112 virtual scoped_refptr<RequestContext> InitializeAppRequestContext( |
| 113 scoped_refptr<ChromeURLRequestContext> main_context, |
| 114 const Extension *installed_app) const; |
| 99 virtual scoped_refptr<ChromeURLRequestContext> | 115 virtual scoped_refptr<ChromeURLRequestContext> |
| 100 AcquireMainRequestContext() const; | 116 AcquireMainRequestContext() const; |
| 101 virtual scoped_refptr<ChromeURLRequestContext> | 117 virtual scoped_refptr<ChromeURLRequestContext> |
| 102 AcquireMediaRequestContext() const; | 118 AcquireMediaRequestContext() const; |
| 103 virtual scoped_refptr<ChromeURLRequestContext> | 119 virtual scoped_refptr<ChromeURLRequestContext> |
| 104 AcquireExtensionsRequestContext() const; | 120 AcquireExtensionsRequestContext() const; |
| 121 virtual scoped_refptr<ChromeURLRequestContext> |
| 122 AcquireIsolatedAppRequestContext( |
| 123 scoped_refptr<ChromeURLRequestContext> main_context, |
| 124 const Extension* installed_app) const; |
| 105 | 125 |
| 106 // Lazy initialization params. | 126 // Lazy initialization params. |
| 107 mutable scoped_ptr<LazyParams> lazy_params_; | 127 mutable scoped_ptr<LazyParams> lazy_params_; |
| 108 | 128 |
| 109 mutable scoped_refptr<RequestContext> main_request_context_; | 129 mutable scoped_refptr<RequestContext> main_request_context_; |
| 110 mutable scoped_refptr<RequestContext> media_request_context_; | 130 mutable scoped_refptr<RequestContext> media_request_context_; |
| 111 mutable scoped_refptr<RequestContext> extensions_request_context_; | 131 mutable scoped_refptr<RequestContext> extensions_request_context_; |
| 112 | 132 |
| 113 mutable scoped_ptr<net::NetworkDelegate> network_delegate_; | 133 mutable scoped_ptr<net::NetworkDelegate> network_delegate_; |
| 114 mutable scoped_ptr<net::DnsCertProvenanceChecker> dns_cert_checker_; | 134 mutable scoped_ptr<net::DnsCertProvenanceChecker> dns_cert_checker_; |
| 115 mutable scoped_ptr<net::HttpTransactionFactory> main_http_factory_; | 135 mutable scoped_ptr<net::HttpTransactionFactory> main_http_factory_; |
| 116 mutable scoped_ptr<net::HttpTransactionFactory> media_http_factory_; | 136 mutable scoped_ptr<net::HttpTransactionFactory> media_http_factory_; |
| 117 | 137 |
| 138 // One HttpTransactionFactory per isolated app. |
| 139 mutable HttpTransactionFactoryMap app_http_factory_map_; |
| 140 |
| 141 // Parameters needed for isolated apps. |
| 142 FilePath app_path_; |
| 143 bool clear_local_state_on_exit_; |
| 144 |
| 118 DISALLOW_COPY_AND_ASSIGN(ProfileImplIOData); | 145 DISALLOW_COPY_AND_ASSIGN(ProfileImplIOData); |
| 119 }; | 146 }; |
| 120 | 147 |
| 121 #endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_IO_DATA_H_ | 148 #endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_IO_DATA_H_ |
| OLD | NEW |