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 "android_webview/browser/aw_browser_context.h" | 5 #include "android_webview/browser/aw_browser_context.h" |
6 | 6 |
7 #include "android_webview/browser/aw_form_database_service.h" | 7 #include "android_webview/browser/aw_form_database_service.h" |
8 #include "android_webview/browser/aw_pref_store.h" | 8 #include "android_webview/browser/aw_pref_store.h" |
9 #include "android_webview/browser/aw_quota_manager_bridge.h" | 9 #include "android_webview/browser/aw_quota_manager_bridge.h" |
10 #include "android_webview/browser/aw_resource_context.h" | 10 #include "android_webview/browser/aw_resource_context.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 namespace { | 34 namespace { |
35 | 35 |
36 // Shows notifications which correspond to PersistentPrefStore's reading errors. | 36 // Shows notifications which correspond to PersistentPrefStore's reading errors. |
37 void HandleReadError(PersistentPrefStore::PrefReadError error) { | 37 void HandleReadError(PersistentPrefStore::PrefReadError error) { |
38 } | 38 } |
39 | 39 |
40 AwBrowserContext* g_browser_context = NULL; | 40 AwBrowserContext* g_browser_context = NULL; |
41 | 41 |
42 } // namespace | 42 } // namespace |
43 | 43 |
| 44 // Data reduction proxy is disabled by default. |
| 45 bool AwBrowserContext::data_reduction_proxy_enabled_ = false; |
| 46 |
44 AwBrowserContext::AwBrowserContext( | 47 AwBrowserContext::AwBrowserContext( |
45 const FilePath path, | 48 const FilePath path, |
46 JniDependencyFactory* native_factory) | 49 JniDependencyFactory* native_factory) |
47 : context_storage_path_(path), | 50 : context_storage_path_(path), |
48 native_factory_(native_factory) { | 51 native_factory_(native_factory) { |
49 DCHECK(g_browser_context == NULL); | 52 DCHECK(g_browser_context == NULL); |
50 g_browser_context = this; | 53 g_browser_context = this; |
51 | 54 |
52 // This constructor is entered during the creation of ContentBrowserClient, | 55 // This constructor is entered during the creation of ContentBrowserClient, |
53 // before browser threads are created. Therefore any checks to enforce | 56 // before browser threads are created. Therefore any checks to enforce |
(...skipping 12 matching lines...) Expand all Loading... |
66 return g_browser_context; | 69 return g_browser_context; |
67 } | 70 } |
68 | 71 |
69 // static | 72 // static |
70 AwBrowserContext* AwBrowserContext::FromWebContents( | 73 AwBrowserContext* AwBrowserContext::FromWebContents( |
71 content::WebContents* web_contents) { | 74 content::WebContents* web_contents) { |
72 // This is safe; this is the only implementation of the browser context. | 75 // This is safe; this is the only implementation of the browser context. |
73 return static_cast<AwBrowserContext*>(web_contents->GetBrowserContext()); | 76 return static_cast<AwBrowserContext*>(web_contents->GetBrowserContext()); |
74 } | 77 } |
75 | 78 |
| 79 // static |
| 80 void AwBrowserContext::SetDataReductionProxyEnabled(bool enabled) { |
| 81 // Cache the setting value. It is possible that data reduction proxy is |
| 82 // not created yet. |
| 83 data_reduction_proxy_enabled_ = enabled; |
| 84 AwBrowserContext* context = AwBrowserContext::GetDefault(); |
| 85 // Can't enable Data reduction proxy if user pref service is not ready. |
| 86 if (context == NULL || context->user_pref_service_.get() == NULL) |
| 87 return; |
| 88 DataReductionProxySettings* proxy_settings = |
| 89 context->GetDataReductionProxySettings(); |
| 90 if (proxy_settings == NULL) |
| 91 return; |
| 92 proxy_settings->SetDataReductionProxyEnabled(data_reduction_proxy_enabled_); |
| 93 } |
| 94 |
76 void AwBrowserContext::PreMainMessageLoopRun() { | 95 void AwBrowserContext::PreMainMessageLoopRun() { |
77 cookie_store_ = CreateCookieStore(this); | 96 cookie_store_ = CreateCookieStore(this); |
78 DataReductionProxySettings::SetAllowed(true); | 97 DataReductionProxySettings::SetAllowed(true); |
79 DataReductionProxySettings::SetPromoAllowed(false); | 98 DataReductionProxySettings::SetPromoAllowed(false); |
80 data_reduction_proxy_settings_.reset( | 99 data_reduction_proxy_settings_.reset( |
81 new DataReductionProxySettings()); | 100 new DataReductionProxySettings()); |
82 data_reduction_proxy_settings_->set_fallback_allowed(false); | 101 data_reduction_proxy_settings_->set_fallback_allowed(false); |
83 | 102 |
84 url_request_context_getter_ = | 103 url_request_context_getter_ = |
85 new AwURLRequestContextGetter(GetPath(), cookie_store_.get()); | 104 new AwURLRequestContextGetter(GetPath(), cookie_store_.get()); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); | 181 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); |
163 user_pref_service_ = pref_service_factory.Create(pref_registry).Pass(); | 182 user_pref_service_ = pref_service_factory.Create(pref_registry).Pass(); |
164 | 183 |
165 user_prefs::UserPrefs::Set(this, user_pref_service_.get()); | 184 user_prefs::UserPrefs::Set(this, user_pref_service_.get()); |
166 | 185 |
167 data_reduction_proxy_settings_->InitDataReductionProxySettings( | 186 data_reduction_proxy_settings_->InitDataReductionProxySettings( |
168 user_pref_service_.get(), | 187 user_pref_service_.get(), |
169 user_pref_service_.get(), | 188 user_pref_service_.get(), |
170 GetRequestContext()); | 189 GetRequestContext()); |
171 | 190 |
172 //TODO(sgurun): Attach this to the API. It is currently hard coded in a | 191 data_reduction_proxy_settings_->SetDataReductionProxyEnabled( |
173 // disabled state. | 192 data_reduction_proxy_enabled_); |
174 data_reduction_proxy_settings_->SetDataReductionProxyEnabled(false); | |
175 } | 193 } |
176 | 194 |
177 base::FilePath AwBrowserContext::GetPath() const { | 195 base::FilePath AwBrowserContext::GetPath() const { |
178 return context_storage_path_; | 196 return context_storage_path_; |
179 } | 197 } |
180 | 198 |
181 bool AwBrowserContext::IsOffTheRecord() const { | 199 bool AwBrowserContext::IsOffTheRecord() const { |
182 // Android WebView does not support off the record profile yet. | 200 // Android WebView does not support off the record profile yet. |
183 return false; | 201 return false; |
184 } | 202 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 | 298 |
281 void AwBrowserContext::RebuildTable( | 299 void AwBrowserContext::RebuildTable( |
282 const scoped_refptr<URLEnumerator>& enumerator) { | 300 const scoped_refptr<URLEnumerator>& enumerator) { |
283 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client | 301 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client |
284 // can change in the lifetime of this WebView and may not yet be set here. | 302 // can change in the lifetime of this WebView and may not yet be set here. |
285 // Therefore this initialization path is not used. | 303 // Therefore this initialization path is not used. |
286 enumerator->OnComplete(true); | 304 enumerator->OnComplete(true); |
287 } | 305 } |
288 | 306 |
289 } // namespace android_webview | 307 } // namespace android_webview |
OLD | NEW |