OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/content_hash_fetcher.h" | 5 #include "extensions/browser/content_hash_fetcher.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 132 |
133 // The url we'll need to use to fetch a verified_contents.json file. | 133 // The url we'll need to use to fetch a verified_contents.json file. |
134 GURL fetch_url_; | 134 GURL fetch_url_; |
135 | 135 |
136 bool force_; | 136 bool force_; |
137 | 137 |
138 CompletionCallback callback_; | 138 CompletionCallback callback_; |
139 content::BrowserThread::ID creation_thread_; | 139 content::BrowserThread::ID creation_thread_; |
140 | 140 |
141 // Used for fetching content signatures. | 141 // Used for fetching content signatures. |
142 scoped_ptr<net::URLFetcher> url_fetcher_; | 142 std::unique_ptr<net::URLFetcher> url_fetcher_; |
143 | 143 |
144 // The key used to validate verified_contents.json. | 144 // The key used to validate verified_contents.json. |
145 ContentVerifierKey key_; | 145 ContentVerifierKey key_; |
146 | 146 |
147 // The parsed contents of the verified_contents.json file, either read from | 147 // The parsed contents of the verified_contents.json file, either read from |
148 // disk or fetched from the network and then written to disk. | 148 // disk or fetched from the network and then written to disk. |
149 scoped_ptr<VerifiedContents> verified_contents_; | 149 std::unique_ptr<VerifiedContents> verified_contents_; |
150 | 150 |
151 // Whether this job succeeded. | 151 // Whether this job succeeded. |
152 bool success_; | 152 bool success_; |
153 | 153 |
154 // Paths that were found to have a mismatching hash. | 154 // Paths that were found to have a mismatching hash. |
155 std::set<base::FilePath> hash_mismatch_paths_; | 155 std::set<base::FilePath> hash_mismatch_paths_; |
156 | 156 |
157 // The block size to use for hashing. | 157 // The block size to use for hashing. |
158 int block_size_; | 158 int block_size_; |
159 | 159 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 net::LOAD_DISABLE_CACHE); | 249 net::LOAD_DISABLE_CACHE); |
250 url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(3); | 250 url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(3); |
251 url_fetcher_->Start(); | 251 url_fetcher_->Start(); |
252 } | 252 } |
253 } | 253 } |
254 | 254 |
255 // Helper function to let us pass ownership of a string via base::Bind with the | 255 // Helper function to let us pass ownership of a string via base::Bind with the |
256 // contents to be written into a file. Also ensures that the directory for | 256 // contents to be written into a file. Also ensures that the directory for |
257 // |path| exists, creating it if needed. | 257 // |path| exists, creating it if needed. |
258 static int WriteFileHelper(const base::FilePath& path, | 258 static int WriteFileHelper(const base::FilePath& path, |
259 scoped_ptr<std::string> content) { | 259 std::unique_ptr<std::string> content) { |
260 base::FilePath dir = path.DirName(); | 260 base::FilePath dir = path.DirName(); |
261 return (base::CreateDirectoryAndGetError(dir, NULL) && | 261 return (base::CreateDirectoryAndGetError(dir, NULL) && |
262 base::WriteFile(path, content->data(), content->size())); | 262 base::WriteFile(path, content->data(), content->size())); |
263 } | 263 } |
264 | 264 |
265 void ContentHashFetcherJob::OnURLFetchComplete(const net::URLFetcher* source) { | 265 void ContentHashFetcherJob::OnURLFetchComplete(const net::URLFetcher* source) { |
266 VLOG(1) << "URLFetchComplete for " << extension_id_ | 266 VLOG(1) << "URLFetchComplete for " << extension_id_ |
267 << " is_success:" << url_fetcher_->GetStatus().is_success() << " " | 267 << " is_success:" << url_fetcher_->GetStatus().is_success() << " " |
268 << fetch_url_.possibly_invalid_spec(); | 268 << fetch_url_.possibly_invalid_spec(); |
269 if (IsCancelled()) | 269 if (IsCancelled()) |
270 return; | 270 return; |
271 scoped_ptr<std::string> response(new std::string); | 271 std::unique_ptr<std::string> response(new std::string); |
272 if (!url_fetcher_->GetStatus().is_success() || | 272 if (!url_fetcher_->GetStatus().is_success() || |
273 !url_fetcher_->GetResponseAsString(response.get())) { | 273 !url_fetcher_->GetResponseAsString(response.get())) { |
274 DoneFetchingVerifiedContents(false); | 274 DoneFetchingVerifiedContents(false); |
275 return; | 275 return; |
276 } | 276 } |
277 | 277 |
278 // Parse the response to make sure it is valid json (on staging sometimes it | 278 // Parse the response to make sure it is valid json (on staging sometimes it |
279 // can be a login redirect html, xml file, etc. if you aren't logged in with | 279 // can be a login redirect html, xml file, etc. if you aren't logged in with |
280 // the right cookies). TODO(asargent) - It would be a nice enhancement to | 280 // the right cookies). TODO(asargent) - It would be a nice enhancement to |
281 // move to parsing this in a sandboxed helper (crbug.com/372878). | 281 // move to parsing this in a sandboxed helper (crbug.com/372878). |
282 scoped_ptr<base::Value> parsed(base::JSONReader::Read(*response)); | 282 std::unique_ptr<base::Value> parsed(base::JSONReader::Read(*response)); |
283 if (parsed) { | 283 if (parsed) { |
284 VLOG(1) << "JSON parsed ok for " << extension_id_; | 284 VLOG(1) << "JSON parsed ok for " << extension_id_; |
285 | 285 |
286 parsed.reset(); // no longer needed | 286 parsed.reset(); // no longer needed |
287 base::FilePath destination = | 287 base::FilePath destination = |
288 file_util::GetVerifiedContentsPath(extension_path_); | 288 file_util::GetVerifiedContentsPath(extension_path_); |
289 size_t size = response->size(); | 289 size_t size = response->size(); |
290 base::PostTaskAndReplyWithResult( | 290 base::PostTaskAndReplyWithResult( |
291 content::BrowserThread::GetBlockingPool(), | 291 content::BrowserThread::GetBlockingPool(), |
292 FROM_HERE, | 292 FROM_HERE, |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 | 498 |
499 for (JobMap::iterator i = jobs_.begin(); i != jobs_.end(); ++i) { | 499 for (JobMap::iterator i = jobs_.begin(); i != jobs_.end(); ++i) { |
500 if (i->second.get() == job) { | 500 if (i->second.get() == job) { |
501 jobs_.erase(i); | 501 jobs_.erase(i); |
502 break; | 502 break; |
503 } | 503 } |
504 } | 504 } |
505 } | 505 } |
506 | 506 |
507 } // namespace extensions | 507 } // namespace extensions |
OLD | NEW |