| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.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/time.h" | 11 #include "base/time.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/chrome_utility_messages.h" | 17 #include "chrome/common/chrome_utility_messages.h" |
| 18 #include "chrome/common/web_resource/web_resource_unpacker.h" | 18 #include "chrome/common/web_resource/web_resource_unpacker.h" |
| 19 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 19 #include "content/browser/utility_process_host.h" | 20 #include "content/browser/utility_process_host.h" |
| 20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/common/url_fetcher.h" | 22 #include "content/public/common/url_fetcher.h" |
| 22 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
| 23 #include "net/base/load_flags.h" | 24 #include "net/base/load_flags.h" |
| 24 #include "net/url_request/url_request_status.h" | 25 #include "net/url_request/url_request_status.h" |
| 25 | 26 |
| 26 using content::BrowserThread; | 27 using content::BrowserThread; |
| 27 | 28 |
| 28 // This class coordinates a web resource unpack and parse task which is run in | 29 // This class coordinates a web resource unpack and parse task which is run in |
| 29 // a separate process. Results are sent back to this class and routed to | 30 // a separate process. Results are sent back to this class and routed to |
| 30 // the WebResourceService. | 31 // the WebResourceService. |
| 31 class WebResourceService::UnpackerClient : public UtilityProcessHost::Client { | 32 class WebResourceService::UnpackerClient : public UtilityProcessHost::Client { |
| 32 public: | 33 public: |
| 33 explicit UnpackerClient(WebResourceService* web_resource_service) | 34 explicit UnpackerClient(WebResourceService* web_resource_service) |
| 34 : web_resource_service_(web_resource_service), | 35 : web_resource_service_(web_resource_service), |
| 35 resource_dispatcher_host_(g_browser_process->resource_dispatcher_host()), | 36 resource_dispatcher_host_(ResourceDispatcherHost::Get()), |
| 36 got_response_(false) { | 37 got_response_(false) { |
| 37 } | 38 } |
| 38 | 39 |
| 39 void Start(const std::string& json_data) { | 40 void Start(const std::string& json_data) { |
| 40 AddRef(); // balanced in Cleanup. | 41 AddRef(); // balanced in Cleanup. |
| 41 | 42 |
| 42 // TODO(willchan): Look for a better signal of whether we're in a unit test | 43 // TODO(willchan): Look for a better signal of whether we're in a unit test |
| 43 // or not. Using |resource_dispatcher_host_| for this is pretty lame. | 44 // or not. Using |resource_dispatcher_host_| for this is pretty lame. |
| 44 // If we don't have a resource_dispatcher_host_, assume we're in | 45 // If we don't have a resource_dispatcher_host_, assume we're in |
| 45 // a test and run the unpacker directly in-process. | 46 // a test and run the unpacker directly in-process. |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 230 |
| 230 std::string data; | 231 std::string data; |
| 231 source->GetResponseAsString(&data); | 232 source->GetResponseAsString(&data); |
| 232 | 233 |
| 233 // UnpackerClient releases itself. | 234 // UnpackerClient releases itself. |
| 234 UnpackerClient* client = new UnpackerClient(this); | 235 UnpackerClient* client = new UnpackerClient(this); |
| 235 client->Start(data); | 236 client->Start(data); |
| 236 | 237 |
| 237 Release(); | 238 Release(); |
| 238 } | 239 } |
| OLD | NEW |