| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "shell/application_manager/network_fetcher.h" | 5 #include "shell/application_manager/network_fetcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/process/process.h" | 12 #include "base/process/process.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "crypto/secure_hash.h" | 17 #include "crypto/secure_hash.h" |
| 18 #include "crypto/sha2.h" | 18 #include "crypto/sha2.h" |
| 19 #include "mojo/common/common_type_converters.h" | 19 #include "mojo/common/common_type_converters.h" |
| 20 #include "mojo/common/data_pipe_utils.h" | 20 #include "mojo/common/data_pipe_utils.h" |
| 21 #include "mojo/services/network/public/interfaces/network_service.mojom.h" | 21 #include "mojo/services/network/public/interfaces/network_service.mojom.h" |
| 22 #include "shell/application_manager/data_pipe_peek.h" | 22 #include "shell/application_manager/data_pipe_peek.h" |
| 23 | 23 |
| 24 namespace mojo { | 24 namespace mojo { |
| 25 namespace shell { |
| 25 | 26 |
| 26 NetworkFetcher::NetworkFetcher(bool disable_cache, | 27 NetworkFetcher::NetworkFetcher(bool disable_cache, |
| 27 const GURL& url, | 28 const GURL& url, |
| 28 NetworkService* network_service, | 29 NetworkService* network_service, |
| 29 const FetchCallback& loader_callback) | 30 const FetchCallback& loader_callback) |
| 30 : Fetcher(loader_callback), | 31 : Fetcher(loader_callback), |
| 31 disable_cache_(false), | 32 disable_cache_(false), |
| 32 url_(url), | 33 url_(url), |
| 33 weak_ptr_factory_(this) { | 34 weak_ptr_factory_(this) { |
| 34 StartNetworkRequest(url, network_service); | 35 StartNetworkRequest(url, network_service); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 base::Bind(&NetworkFetcher::CopyCompleted, | 161 base::Bind(&NetworkFetcher::CopyCompleted, |
| 161 weak_ptr_factory_.GetWeakPtr(), callback)); | 162 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 162 } | 163 } |
| 163 | 164 |
| 164 std::string NetworkFetcher::MimeType() { | 165 std::string NetworkFetcher::MimeType() { |
| 165 return response_->mime_type; | 166 return response_->mime_type; |
| 166 } | 167 } |
| 167 | 168 |
| 168 bool NetworkFetcher::HasMojoMagic() { | 169 bool NetworkFetcher::HasMojoMagic() { |
| 169 std::string magic; | 170 std::string magic; |
| 170 return shell::BlockingPeekNBytes(response_->body.get(), &magic, | 171 return BlockingPeekNBytes(response_->body.get(), &magic, strlen(kMojoMagic), |
| 171 strlen(kMojoMagic), kPeekTimeout) && | 172 kPeekTimeout) && |
| 172 magic == kMojoMagic; | 173 magic == kMojoMagic; |
| 173 } | 174 } |
| 174 | 175 |
| 175 bool NetworkFetcher::PeekFirstLine(std::string* line) { | 176 bool NetworkFetcher::PeekFirstLine(std::string* line) { |
| 176 return shell::BlockingPeekLine(response_->body.get(), line, kMaxShebangLength, | 177 return BlockingPeekLine(response_->body.get(), line, kMaxShebangLength, |
| 177 kPeekTimeout); | 178 kPeekTimeout); |
| 178 } | 179 } |
| 179 | 180 |
| 180 void NetworkFetcher::StartNetworkRequest(const GURL& url, | 181 void NetworkFetcher::StartNetworkRequest(const GURL& url, |
| 181 NetworkService* network_service) { | 182 NetworkService* network_service) { |
| 182 URLRequestPtr request(URLRequest::New()); | 183 URLRequestPtr request(URLRequest::New()); |
| 183 request->url = String::From(url); | 184 request->url = String::From(url); |
| 184 request->auto_follow_redirects = false; | 185 request->auto_follow_redirects = false; |
| 185 request->bypass_cache = disable_cache_; | 186 request->bypass_cache = disable_cache_; |
| 186 | 187 |
| 187 network_service->CreateURLLoader(GetProxy(&url_loader_)); | 188 network_service->CreateURLLoader(GetProxy(&url_loader_)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 204 << response->status_line << "): " | 205 << response->status_line << "): " |
| 205 << "while fetching " << response->url; | 206 << "while fetching " << response->url; |
| 206 loader_callback_.Run(make_scoped_ptr<Fetcher>(NULL)); | 207 loader_callback_.Run(make_scoped_ptr<Fetcher>(NULL)); |
| 207 return; | 208 return; |
| 208 } | 209 } |
| 209 | 210 |
| 210 response_ = response.Pass(); | 211 response_ = response.Pass(); |
| 211 loader_callback_.Run(make_scoped_ptr(this)); | 212 loader_callback_.Run(make_scoped_ptr(this)); |
| 212 } | 213 } |
| 213 | 214 |
| 215 } // namespace shell |
| 214 } // namespace mojo | 216 } // namespace mojo |
| OLD | NEW |