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/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 void ApplicationUpdater::OnLoadComplete(mojo::URLResponsePtr response) { | 118 void ApplicationUpdater::OnLoadComplete(mojo::URLResponsePtr response) { |
119 url_response_disk_cache_->Update(response.Pass()); | 119 url_response_disk_cache_->Update(response.Pass()); |
120 delete this; | 120 delete this; |
121 } | 121 } |
122 | 122 |
123 } // namespace | 123 } // namespace |
124 | 124 |
125 NetworkFetcher::NetworkFetcher( | 125 NetworkFetcher::NetworkFetcher( |
126 bool disable_cache, | 126 bool disable_cache, |
| 127 bool force_offline_by_default, |
127 const GURL& url, | 128 const GURL& url, |
128 mojo::URLResponseDiskCache* url_response_disk_cache, | 129 mojo::URLResponseDiskCache* url_response_disk_cache, |
129 mojo::NetworkService* network_service, | 130 mojo::NetworkService* network_service, |
130 const FetchCallback& loader_callback) | 131 const FetchCallback& loader_callback) |
131 : Fetcher(loader_callback), | 132 : Fetcher(loader_callback), |
132 disable_cache_(disable_cache), | 133 disable_cache_(disable_cache), |
| 134 force_offline_by_default_(force_offline_by_default), |
133 url_(url), | 135 url_(url), |
134 url_response_disk_cache_(url_response_disk_cache), | 136 url_response_disk_cache_(url_response_disk_cache), |
135 network_service_(network_service), | 137 network_service_(network_service), |
136 weak_ptr_factory_(this) { | 138 weak_ptr_factory_(this) { |
137 if (CanLoadDirectlyFromCache()) { | 139 if (CanLoadDirectlyFromCache()) { |
138 LoadFromCache(true); | 140 LoadFromCache(true); |
139 } else { | 141 } else { |
140 StartNetworkRequest(); | 142 StartNetworkRequest(); |
141 } | 143 } |
142 } | 144 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } | 193 } |
192 | 194 |
193 bool NetworkFetcher::PeekFirstLine(std::string* line) { | 195 bool NetworkFetcher::PeekFirstLine(std::string* line) { |
194 return Fetcher::PeekFirstLine(path_, line); | 196 return Fetcher::PeekFirstLine(path_, line); |
195 } | 197 } |
196 | 198 |
197 bool NetworkFetcher::CanLoadDirectlyFromCache() { | 199 bool NetworkFetcher::CanLoadDirectlyFromCache() { |
198 if (disable_cache_) | 200 if (disable_cache_) |
199 return false; | 201 return false; |
200 | 202 |
| 203 if (force_offline_by_default_) |
| 204 return true; |
| 205 |
201 const std::string& host = url_.host(); | 206 const std::string& host = url_.host(); |
202 return !(host == "localhost" || host == "127.0.0.1" || host == "[::1]"); | 207 return !(host == "localhost" || host == "127.0.0.1" || host == "[::1]"); |
203 } | 208 } |
204 | 209 |
205 void NetworkFetcher::LoadFromCache(bool schedule_update) { | 210 void NetworkFetcher::LoadFromCache(bool schedule_update) { |
206 url_response_disk_cache_->Get( | 211 url_response_disk_cache_->Get( |
207 mojo::String::From(url_), | 212 mojo::String::From(url_), |
208 base::Bind(&NetworkFetcher::OnCachedResponseReceived, | 213 base::Bind(&NetworkFetcher::OnCachedResponseReceived, |
209 base::Unretained(this), schedule_update)); | 214 base::Unretained(this), schedule_update)); |
210 } | 215 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 base::StringPrintf("%s %s\n", path.value().c_str(), url.spec().c_str()); | 305 base::StringPrintf("%s %s\n", path.value().c_str(), url.spec().c_str()); |
301 // TODO(eseidel): AppendToFile is missing O_CREAT, crbug.com/450696 | 306 // TODO(eseidel): AppendToFile is missing O_CREAT, crbug.com/450696 |
302 if (!PathExists(map_path)) { | 307 if (!PathExists(map_path)) { |
303 base::WriteFile(map_path, map_entry.data(), map_entry.length()); | 308 base::WriteFile(map_path, map_entry.data(), map_entry.length()); |
304 } else { | 309 } else { |
305 base::AppendToFile(map_path, map_entry.data(), map_entry.length()); | 310 base::AppendToFile(map_path, map_entry.data(), map_entry.length()); |
306 } | 311 } |
307 } | 312 } |
308 | 313 |
309 } // namespace shell | 314 } // namespace shell |
OLD | NEW |