OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_io_data.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/time/time.h" | |
9 #include "chrome/browser/net/chrome_net_log.h" | |
10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator. h" | |
11 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | |
12 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" | |
13 #include "chrome/browser/prefs/pref_service_syncable.h" | |
14 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d ata.h" | |
15 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_stat istics_prefs.h" | |
16 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event _store.h" | |
17 | |
18 scoped_ptr<data_reduction_proxy::DataReductionProxyIOData> | |
19 CreateDataReductionProxyChromeIOData( | |
20 ChromeNetLog* net_log, | |
21 content::BrowserContext* browser_context, | |
22 PrefServiceSyncable* prefs, | |
23 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | |
24 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, | |
25 DataReductionProxyChromeConfigurator** configurator) { | |
mmenke
2014/12/17 21:37:22
This still seems like too much code hooking togeth
bengr
2014/12/19 20:05:58
After my next CL, the event store and the configur
| |
26 DCHECK(net_log); | |
27 DCHECK(prefs); | |
28 DCHECK(browser_context); | |
29 DataReductionProxyChromeSettings* data_reduction_proxy_chrome_settings = | |
30 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | |
31 browser_context); | |
32 | |
33 #if defined(OS_ANDROID) || defined(OS_IOS) | |
34 // On mobile we write data reduction proxy prefs directly to the pref service. | |
35 // On desktop we store data reduction proxy prefs in memory, writing to disk | |
36 // every 60 minutes and on termination. Shutdown hooks must be added for | |
37 // Android and iOS in order for non-zero delays to be supported. | |
38 // (http://crbug.com/408264) | |
39 base::TimeDelta commit_delay = base::TimeDelta(); | |
40 #else | |
41 base::TimeDelta commit_delay = base::TimeDelta::FromMinutes(60); | |
42 #endif | |
43 | |
44 // The event_store is used by DataReductionProxyChromeSettings, configurator, | |
45 // and ProfileIOData. Ownership is passed to the latter via | |
46 // ProfileIOData::Handle, which is only destroyed after | |
47 // BrowserContextKeyedServices, including DataReductionProxyChromeSettings. | |
48 data_reduction_proxy::DataReductionProxyEventStore* | |
49 data_reduction_proxy_event_store = | |
50 new data_reduction_proxy::DataReductionProxyEventStore( | |
51 ui_task_runner); | |
52 | |
53 // The configurator is used by DataReductionProxyChromeSettings and | |
54 // ProfileIOData. Ownership is passed to the latter via ProfileIOData::Handle, | |
55 // which is only destroyed after BrowserContextKeyedServices, | |
56 // including DataReductionProxyChromeSettings. | |
57 // Retain a raw pointer to use for initialization of data reduction proxy | |
58 // settings after ownership is passed. | |
59 DataReductionProxyChromeConfigurator* | |
60 data_reduction_proxy_chrome_configurator = | |
61 new DataReductionProxyChromeConfigurator( | |
62 prefs, | |
63 io_task_runner, | |
64 net_log, data_reduction_proxy_event_store); | |
65 | |
66 data_reduction_proxy::DataReductionProxyStatisticsPrefs* | |
67 data_reduction_proxy_statistics_prefs = | |
68 new data_reduction_proxy::DataReductionProxyStatisticsPrefs( | |
69 prefs, ui_task_runner, | |
70 commit_delay); | |
71 | |
72 scoped_ptr<data_reduction_proxy::DataReductionProxyIOData> | |
73 data_reduction_proxy_data_io_data( | |
74 new data_reduction_proxy::DataReductionProxyIOData( | |
75 DataReductionProxyChromeSettings::GetClient(), | |
76 data_reduction_proxy_chrome_settings->params()->Clone(), | |
77 make_scoped_ptr(data_reduction_proxy_chrome_configurator), | |
78 make_scoped_ptr(data_reduction_proxy_statistics_prefs), | |
79 make_scoped_ptr(data_reduction_proxy_event_store), | |
80 base::Bind( | |
81 &DataReductionProxyChromeConfigurator:: | |
82 GetProxyConfigOnIOThread, | |
83 base::Unretained(data_reduction_proxy_chrome_configurator)), | |
mmenke
2014/12/17 21:37:22
Passing a DataReductionProxyConfigurator and a bou
bengr
2014/12/19 20:05:57
Done.
| |
84 base::Bind( | |
85 &data_reduction_proxy::DataReductionProxySettings:: | |
86 SetUnreachable, | |
87 base::Unretained(data_reduction_proxy_chrome_settings)), | |
mmenke
2014/12/17 21:37:22
+4 indent
mmenke
2014/12/17 21:37:22
Again, should just pass in the settings, and have
bengr
2014/12/19 20:05:57
Done.
bengr
2014/12/19 20:05:57
Done.
| |
88 io_task_runner, | |
89 ui_task_runner)); | |
90 data_reduction_proxy_chrome_settings->SetDataReductionProxyStatisticsPrefs( | |
91 data_reduction_proxy_statistics_prefs); | |
92 | |
93 *configurator = data_reduction_proxy_chrome_configurator; | |
94 return data_reduction_proxy_data_io_data.Pass(); | |
95 } | |
96 | |
97 scoped_ptr<data_reduction_proxy::DataReductionProxyIOData> | |
98 CreateDataReductionProxyChromeIODataForSystem( | |
99 ChromeNetLog* net_log, | |
100 PrefServiceSyncable* prefs, | |
101 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | |
102 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) { | |
103 // TODO(kundaji): Move flags initialization to DataReductionProxyParams and | |
104 // merge with flag initialization in | |
105 // data_reduction_proxy_chrome_settings_factory.cc. | |
106 int flags = data_reduction_proxy::DataReductionProxyParams::kAllowed | | |
107 data_reduction_proxy::DataReductionProxyParams::kFallbackAllowed | | |
108 data_reduction_proxy::DataReductionProxyParams::kAlternativeAllowed; | |
109 if (data_reduction_proxy::DataReductionProxyParams:: | |
110 IsIncludedInPromoFieldTrial()) { | |
111 flags |= data_reduction_proxy::DataReductionProxyParams::kPromoAllowed; | |
112 } | |
113 if (data_reduction_proxy::DataReductionProxyParams:: | |
114 IsIncludedInHoldbackFieldTrial()) { | |
115 flags |= data_reduction_proxy::DataReductionProxyParams::kHoldback; | |
116 } | |
117 scoped_ptr<data_reduction_proxy::DataReductionProxyIOData> | |
118 data_reduction_proxy_data_io_data( | |
119 new data_reduction_proxy::DataReductionProxyIOData( | |
120 DataReductionProxyChromeSettings::GetClient(), | |
121 make_scoped_ptr( | |
122 new data_reduction_proxy::DataReductionProxyParams(flags)), | |
123 scoped_ptr< | |
124 data_reduction_proxy::DataReductionProxyConfigurator>(), | |
125 scoped_ptr< | |
126 data_reduction_proxy::DataReductionProxyStatisticsPrefs>(), | |
127 scoped_ptr<data_reduction_proxy::DataReductionProxyEventStore>(), | |
128 data_reduction_proxy::DataReductionProxyNetworkDelegate:: | |
129 ProxyConfigGetter(), | |
130 base::Callback<void(bool)>(), | |
131 io_task_runner, | |
132 ui_task_runner)); | |
133 return data_reduction_proxy_data_io_data.Pass(); | |
134 } | |
OLD | NEW |