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 #include "chrome/browser/web_resource/web_resource_service.h" | 5 #include "chrome/browser/web_resource/web_resource_service.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/threading/thread_restrictions.h" | 11 #include "base/threading/thread_restrictions.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
17 #include "chrome/browser/profiles/profile.h" | |
18 #include "chrome/browser/sync/sync_ui_util.h" | 17 #include "chrome/browser/sync/sync_ui_util.h" |
19 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
21 #include "chrome/common/web_resource/web_resource_unpacker.h" | 20 #include "chrome/common/web_resource/web_resource_unpacker.h" |
22 #include "content/browser/browser_thread.h" | 21 #include "content/browser/browser_thread.h" |
23 #include "content/common/notification_service.h" | 22 #include "content/common/notification_service.h" |
24 #include "content/common/url_fetcher.h" | 23 #include "content/common/url_fetcher.h" |
25 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
26 #include "net/base/load_flags.h" | 25 #include "net/base/load_flags.h" |
27 #include "net/url_request/url_request_status.h" | 26 #include "net/url_request/url_request_status.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 std::string web_resource_server = | 59 std::string web_resource_server = |
61 web_resource_service_->web_resource_server_; | 60 web_resource_service_->web_resource_server_; |
62 if (web_resource_service_->apply_locale_to_url_) { | 61 if (web_resource_service_->apply_locale_to_url_) { |
63 std::string locale = g_browser_process->GetApplicationLocale(); | 62 std::string locale = g_browser_process->GetApplicationLocale(); |
64 web_resource_server.append(locale); | 63 web_resource_server.append(locale); |
65 } | 64 } |
66 | 65 |
67 url_fetcher_.reset(new URLFetcher(GURL( | 66 url_fetcher_.reset(new URLFetcher(GURL( |
68 web_resource_server), | 67 web_resource_server), |
69 URLFetcher::GET, this)); | 68 URLFetcher::GET, this)); |
70 // Do not let url fetcher affect existing state in profile (by setting | 69 // Use system request context and do not save state in cookies or cache. |
71 // cookies, for example. | |
72 url_fetcher_->set_load_flags(net::LOAD_DISABLE_CACHE | | 70 url_fetcher_->set_load_flags(net::LOAD_DISABLE_CACHE | |
73 net::LOAD_DO_NOT_SAVE_COOKIES); | 71 net::LOAD_DO_NOT_SAVE_COOKIES); |
74 net::URLRequestContextGetter* url_request_context_getter = | 72 net::URLRequestContextGetter* url_request_context_getter = |
75 web_resource_service_->profile_->GetRequestContext(); | 73 g_browser_process->system_request_context(); |
76 url_fetcher_->set_request_context(url_request_context_getter); | 74 url_fetcher_->set_request_context(url_request_context_getter); |
77 url_fetcher_->Start(); | 75 url_fetcher_->Start(); |
78 } | 76 } |
79 | 77 |
80 // From URLFetcher::Delegate. | 78 // From URLFetcher::Delegate. |
81 void OnURLFetchComplete(const URLFetcher* source, | 79 void OnURLFetchComplete(const URLFetcher* source, |
82 const GURL& url, | 80 const GURL& url, |
83 const net::URLRequestStatus& status, | 81 const net::URLRequestStatus& status, |
84 int response_code, | 82 int response_code, |
85 const net::ResponseCookies& cookies, | 83 const net::ResponseCookies& cookies, |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 188 |
191 // Holds raw JSON string. | 189 // Holds raw JSON string. |
192 const std::string& json_data_; | 190 const std::string& json_data_; |
193 | 191 |
194 // True if we got a response from the utility process and have cleaned up | 192 // True if we got a response from the utility process and have cleaned up |
195 // already. | 193 // already. |
196 bool got_response_; | 194 bool got_response_; |
197 }; | 195 }; |
198 | 196 |
199 WebResourceService::WebResourceService( | 197 WebResourceService::WebResourceService( |
200 Profile* profile, | |
201 PrefService* prefs, | 198 PrefService* prefs, |
202 const char* web_resource_server, | 199 const char* web_resource_server, |
203 bool apply_locale_to_url, | 200 bool apply_locale_to_url, |
204 NotificationType::Type notification_type, | 201 NotificationType::Type notification_type, |
205 const char* last_update_time_pref_name, | 202 const char* last_update_time_pref_name, |
206 int start_fetch_delay, | 203 int start_fetch_delay, |
207 int cache_update_delay) | 204 int cache_update_delay) |
208 : prefs_(prefs), | 205 : prefs_(prefs), |
209 profile_(profile), | |
210 ALLOW_THIS_IN_INITIALIZER_LIST(service_factory_(this)), | 206 ALLOW_THIS_IN_INITIALIZER_LIST(service_factory_(this)), |
211 in_fetch_(false), | 207 in_fetch_(false), |
212 web_resource_server_(web_resource_server), | 208 web_resource_server_(web_resource_server), |
213 apply_locale_to_url_(apply_locale_to_url), | 209 apply_locale_to_url_(apply_locale_to_url), |
214 notification_type_(notification_type), | 210 notification_type_(notification_type), |
215 last_update_time_pref_name_(last_update_time_pref_name), | 211 last_update_time_pref_name_(last_update_time_pref_name), |
216 start_fetch_delay_(start_fetch_delay), | 212 start_fetch_delay_(start_fetch_delay), |
217 cache_update_delay_(cache_update_delay), | 213 cache_update_delay_(cache_update_delay), |
218 web_resource_update_scheduled_(false) { | 214 web_resource_update_scheduled_(false) { |
219 DCHECK(prefs); | 215 DCHECK(prefs); |
220 DCHECK(profile); | |
221 prefs_->RegisterStringPref(last_update_time_pref_name, | 216 prefs_->RegisterStringPref(last_update_time_pref_name, |
222 "0", | 217 "0", |
223 PrefService::UNSYNCABLE_PREF); | 218 PrefService::UNSYNCABLE_PREF); |
224 resource_dispatcher_host_ = g_browser_process->resource_dispatcher_host(); | 219 resource_dispatcher_host_ = g_browser_process->resource_dispatcher_host(); |
225 web_resource_fetcher_.reset(new WebResourceFetcher(this)); | 220 web_resource_fetcher_.reset(new WebResourceFetcher(this)); |
226 } | 221 } |
227 | 222 |
228 WebResourceService::~WebResourceService() { } | 223 WebResourceService::~WebResourceService() { } |
229 | 224 |
230 void WebResourceService::PostNotification(int64 delay_ms) { | 225 void WebResourceService::PostNotification(int64 delay_ms) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 } | 278 } |
284 | 279 |
285 void WebResourceService::UpdateResourceCache(const std::string& json_data) { | 280 void WebResourceService::UpdateResourceCache(const std::string& json_data) { |
286 UnpackerClient* client = new UnpackerClient(this, json_data); | 281 UnpackerClient* client = new UnpackerClient(this, json_data); |
287 client->Start(); | 282 client->Start(); |
288 | 283 |
289 // Set cache update time in preferences. | 284 // Set cache update time in preferences. |
290 prefs_->SetString(last_update_time_pref_name_, | 285 prefs_->SetString(last_update_time_pref_name_, |
291 base::DoubleToString(base::Time::Now().ToDoubleT())); | 286 base::DoubleToString(base::Time::Now().ToDoubleT())); |
292 } | 287 } |
OLD | NEW |