| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "chrome/browser/web_resource/web_resource_service.h" | 4 #include "chrome/browser/web_resource/web_resource_service.h" |
| 5 | 5 |
| 6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
| 7 #include "base/time.h" | 7 #include "base/time.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/chrome_thread.h" | 10 #include "chrome/browser/chrome_thread.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 public: | 96 public: |
| 97 UnpackerClient(WebResourceService* web_resource_service, | 97 UnpackerClient(WebResourceService* web_resource_service, |
| 98 const std::string& json_data) | 98 const std::string& json_data) |
| 99 : web_resource_service_(web_resource_service), | 99 : web_resource_service_(web_resource_service), |
| 100 json_data_(json_data), got_response_(false) { | 100 json_data_(json_data), got_response_(false) { |
| 101 } | 101 } |
| 102 | 102 |
| 103 void Start() { | 103 void Start() { |
| 104 AddRef(); // balanced in Cleanup. | 104 AddRef(); // balanced in Cleanup. |
| 105 | 105 |
| 106 if (web_resource_service_->resource_dispatcher_host_) { | 106 // If we don't have a resource_dispatcher_host_, assume we're in |
| 107 // a test and run the unpacker directly in-process. |
| 108 bool use_utility_process = |
| 109 web_resource_service_->resource_dispatcher_host_ != NULL; |
| 110 |
| 111 #if defined(OS_POSIX) |
| 112 // TODO(port): Don't use a utility process on linux (crbug.com/22703) or |
| 113 // MacOS (crbug.com/8102) until problems related to autoupdate are fixed. |
| 114 use_utility_process = false; |
| 115 #endif |
| 116 |
| 117 if (use_utility_process) { |
| 107 ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask(FROM_HERE, | 118 ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask(FROM_HERE, |
| 108 NewRunnableMethod(this, &UnpackerClient::StartProcessOnIOThread, | 119 NewRunnableMethod(this, &UnpackerClient::StartProcessOnIOThread, |
| 109 web_resource_service_->resource_dispatcher_host_, | 120 web_resource_service_->resource_dispatcher_host_, |
| 110 MessageLoop::current())); | 121 MessageLoop::current())); |
| 111 } else { | 122 } else { |
| 112 // If we don't have a resource_dispatcher_host_, assume we're in | |
| 113 // a test and run the unpacker directly in-process. | |
| 114 WebResourceUnpacker unpacker(json_data_); | 123 WebResourceUnpacker unpacker(json_data_); |
| 115 if (unpacker.Run()) { | 124 if (unpacker.Run()) { |
| 116 OnUnpackWebResourceSucceeded(*unpacker.parsed_json()); | 125 OnUnpackWebResourceSucceeded(*unpacker.parsed_json()); |
| 117 } else { | 126 } else { |
| 118 OnUnpackWebResourceFailed(unpacker.error_message()); | 127 OnUnpackWebResourceFailed(unpacker.error_message()); |
| 119 } | 128 } |
| 120 } | 129 } |
| 121 } | 130 } |
| 122 | 131 |
| 123 private: | 132 private: |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 289 |
| 281 void WebResourceService::UpdateResourceCache(const std::string& json_data) { | 290 void WebResourceService::UpdateResourceCache(const std::string& json_data) { |
| 282 UnpackerClient* client = new UnpackerClient(this, json_data); | 291 UnpackerClient* client = new UnpackerClient(this, json_data); |
| 283 client->Start(); | 292 client->Start(); |
| 284 | 293 |
| 285 // Update resource server and cache update time in preferences. | 294 // Update resource server and cache update time in preferences. |
| 286 prefs_->SetString(prefs::kNTPTipsCacheUpdate, | 295 prefs_->SetString(prefs::kNTPTipsCacheUpdate, |
| 287 DoubleToWString(base::Time::Now().ToDoubleT())); | 296 DoubleToWString(base::Time::Now().ToDoubleT())); |
| 288 prefs_->SetString(prefs::kNTPTipsServer, web_resource_server_); | 297 prefs_->SetString(prefs::kNTPTipsServer, web_resource_server_); |
| 289 } | 298 } |
| 290 | |
| OLD | NEW |