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