Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: extensions/browser/content_hash_fetcher.cc

Issue 2815243002: Fix two ContentHashFetcherTest.* tests' flakiness. (Closed)
Patch Set: REWORK Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | extensions/browser/content_hash_fetcher_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <memory> 10 #include <memory>
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 134
135 // The url we'll need to use to fetch a verified_contents.json file. 135 // The url we'll need to use to fetch a verified_contents.json file.
136 GURL fetch_url_; 136 GURL fetch_url_;
137 137
138 bool force_; 138 bool force_;
139 139
140 CompletionCallback callback_; 140 CompletionCallback callback_;
141 content::BrowserThread::ID creation_thread_; 141 content::BrowserThread::ID creation_thread_;
142 142
143 // Used for fetching content signatures. 143 // Used for fetching content signatures.
144 // Created and destroyed on |creation_thread_|.
144 std::unique_ptr<net::URLFetcher> url_fetcher_; 145 std::unique_ptr<net::URLFetcher> url_fetcher_;
145 146
146 // The key used to validate verified_contents.json. 147 // The key used to validate verified_contents.json.
147 ContentVerifierKey key_; 148 ContentVerifierKey key_;
148 149
149 // The parsed contents of the verified_contents.json file, either read from 150 // The parsed contents of the verified_contents.json file, either read from
150 // disk or fetched from the network and then written to disk. 151 // disk or fetched from the network and then written to disk.
151 std::unique_ptr<VerifiedContents> verified_contents_; 152 std::unique_ptr<VerifiedContents> verified_contents_;
152 153
153 // Whether this job succeeded. 154 // Whether this job succeeded.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 cancelled_ = true; 212 cancelled_ = true;
212 } 213 }
213 214
214 bool ContentHashFetcherJob::IsCancelled() { 215 bool ContentHashFetcherJob::IsCancelled() {
215 base::AutoLock autolock(cancelled_lock_); 216 base::AutoLock autolock(cancelled_lock_);
216 bool result = cancelled_; 217 bool result = cancelled_;
217 return result; 218 return result;
218 } 219 }
219 220
220 ContentHashFetcherJob::~ContentHashFetcherJob() { 221 ContentHashFetcherJob::~ContentHashFetcherJob() {
222 // Destroy |url_fetcher_| on correct thread.
223 // It was possible for it to be deleted on blocking pool from
224 // MaybeCreateHashes(). See https://crbug.com/702300 for details.
225 if (url_fetcher_ && !content::BrowserThread::CurrentlyOn(creation_thread_)) {
226 content::BrowserThread::DeleteSoon(creation_thread_, FROM_HERE,
227 url_fetcher_.release());
228 }
221 } 229 }
222 230
223 bool ContentHashFetcherJob::LoadVerifiedContents(const base::FilePath& path) { 231 bool ContentHashFetcherJob::LoadVerifiedContents(const base::FilePath& path) {
224 if (!base::PathExists(path)) 232 if (!base::PathExists(path))
225 return false; 233 return false;
226 verified_contents_.reset(new VerifiedContents(key_.data, key_.size)); 234 verified_contents_.reset(new VerifiedContents(key_.data, key_.size));
227 if (!verified_contents_->InitFrom(path)) { 235 if (!verified_contents_->InitFrom(path)) {
228 verified_contents_.reset(); 236 verified_contents_.reset();
229 if (!base::DeleteFile(path, false)) 237 if (!base::DeleteFile(path, false))
230 LOG(WARNING) << "Failed to delete " << path.value(); 238 LOG(WARNING) << "Failed to delete " << path.value();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 base::FilePath dir = path.DirName(); 293 base::FilePath dir = path.DirName();
286 if (!base::CreateDirectoryAndGetError(dir, nullptr)) 294 if (!base::CreateDirectoryAndGetError(dir, nullptr))
287 return -1; 295 return -1;
288 return base::WriteFile(path, content->data(), content->size()); 296 return base::WriteFile(path, content->data(), content->size());
289 } 297 }
290 298
291 void ContentHashFetcherJob::OnURLFetchComplete(const net::URLFetcher* source) { 299 void ContentHashFetcherJob::OnURLFetchComplete(const net::URLFetcher* source) {
292 VLOG(1) << "URLFetchComplete for " << extension_id_ 300 VLOG(1) << "URLFetchComplete for " << extension_id_
293 << " is_success:" << url_fetcher_->GetStatus().is_success() << " " 301 << " is_success:" << url_fetcher_->GetStatus().is_success() << " "
294 << fetch_url_.possibly_invalid_spec(); 302 << fetch_url_.possibly_invalid_spec();
303 // Delete |url_fetcher_| once we no longer need it.
lazyboy 2017/04/19 00:19:33 As we discussed on vc, this is the deletion. Howev
304 std::unique_ptr<net::URLFetcher> url_fetcher = std::move(url_fetcher_);
305
295 if (IsCancelled()) 306 if (IsCancelled())
296 return; 307 return;
297 std::unique_ptr<std::string> response(new std::string); 308 std::unique_ptr<std::string> response(new std::string);
298 if (!url_fetcher_->GetStatus().is_success() || 309 if (!url_fetcher->GetStatus().is_success() ||
299 !url_fetcher_->GetResponseAsString(response.get())) { 310 !url_fetcher->GetResponseAsString(response.get())) {
300 DoneFetchingVerifiedContents(false); 311 DoneFetchingVerifiedContents(false);
301 return; 312 return;
302 } 313 }
303 314
304 // Parse the response to make sure it is valid json (on staging sometimes it 315 // Parse the response to make sure it is valid json (on staging sometimes it
305 // can be a login redirect html, xml file, etc. if you aren't logged in with 316 // can be a login redirect html, xml file, etc. if you aren't logged in with
306 // the right cookies). TODO(asargent) - It would be a nice enhancement to 317 // the right cookies). TODO(asargent) - It would be a nice enhancement to
307 // move to parsing this in a sandboxed helper (crbug.com/372878). 318 // move to parsing this in a sandboxed helper (crbug.com/372878).
308 std::unique_ptr<base::Value> parsed(base::JSONReader::Read(*response)); 319 std::unique_ptr<base::Value> parsed(base::JSONReader::Read(*response));
309 if (parsed) { 320 if (parsed) {
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 539
529 for (JobMap::iterator i = jobs_.begin(); i != jobs_.end(); ++i) { 540 for (JobMap::iterator i = jobs_.begin(); i != jobs_.end(); ++i) {
530 if (i->second.get() == job.get()) { 541 if (i->second.get() == job.get()) {
531 jobs_.erase(i); 542 jobs_.erase(i);
532 break; 543 break;
533 } 544 }
534 } 545 }
535 } 546 }
536 547
537 } // namespace extensions 548 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/browser/content_hash_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698