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

Side by Side Diff: chrome/browser/extensions/autoupdate_interceptor.cc

Issue 3872002: Thread IO safety: file_util annotated, IO thread blocked from doing IO (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 10 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « base/thread_restrictions.cc ('k') | chrome/browser/io_thread.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 (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 4
5 #include "chrome/browser/extensions/autoupdate_interceptor.h" 5 #include "chrome/browser/extensions/autoupdate_interceptor.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/thread_restrictions.h"
8 #include "chrome/browser/browser_thread.h" 9 #include "chrome/browser/browser_thread.h"
9 #include "net/url_request/url_request_test_job.h" 10 #include "net/url_request/url_request_test_job.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 // This is a specialized version of URLRequestTestJob that lets us specify 13 // This is a specialized version of URLRequestTestJob that lets us specify
13 // response data and make sure the response code is 200, which the autoupdate 14 // response data and make sure the response code is 200, which the autoupdate
14 // code relies on. 15 // code relies on.
15 class AutoUpdateTestRequestJob : public URLRequestTestJob { 16 class AutoUpdateTestRequestJob : public URLRequestTestJob {
16 public: 17 public:
17 AutoUpdateTestRequestJob(URLRequest* request, 18 AutoUpdateTestRequestJob(URLRequest* request,
(...skipping 15 matching lines...) Expand all
33 } 34 }
34 35
35 36
36 URLRequestJob* AutoUpdateInterceptor::MaybeIntercept(URLRequest* request) { 37 URLRequestJob* AutoUpdateInterceptor::MaybeIntercept(URLRequest* request) {
37 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 38 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
38 if (request->url().scheme() != "http" || 39 if (request->url().scheme() != "http" ||
39 request->url().host() != "localhost") { 40 request->url().host() != "localhost") {
40 return NULL; 41 return NULL;
41 } 42 }
42 43
44 // It's ok to do a blocking disk access on this thread; this class
45 // is just used for tests.
46 base::ThreadRestrictions::ScopedAllowIO allow_io;
47
43 // Search for this request's url, ignoring any query parameters. 48 // Search for this request's url, ignoring any query parameters.
44 GURL url = request->url(); 49 GURL url = request->url();
45 if (url.has_query()) { 50 if (url.has_query()) {
46 GURL::Replacements replacements; 51 GURL::Replacements replacements;
47 replacements.ClearQuery(); 52 replacements.ClearQuery();
48 url = url.ReplaceComponents(replacements); 53 url = url.ReplaceComponents(replacements);
49 } 54 }
50 std::map<GURL, FilePath>::iterator i = responses_.find(url); 55 std::map<GURL, FilePath>::iterator i = responses_.find(url);
51 if (i == responses_.end()) { 56 if (i == responses_.end()) {
52 return NULL; 57 return NULL;
53 } 58 }
54 std::string contents; 59 std::string contents;
55 EXPECT_TRUE(file_util::ReadFileToString(i->second, &contents)); 60 EXPECT_TRUE(file_util::ReadFileToString(i->second, &contents));
56 61
57 return new AutoUpdateTestRequestJob(request, contents); 62 return new AutoUpdateTestRequestJob(request, contents);
58 } 63 }
59 64
60 65
61 void AutoUpdateInterceptor::SetResponse(const std::string url, 66 void AutoUpdateInterceptor::SetResponse(const std::string url,
62 const FilePath& path) { 67 const FilePath& path) {
63 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 68 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
69 // It's ok to do a blocking disk access on this thread; this class
70 // is just used for tests.
71 base::ThreadRestrictions::ScopedAllowIO allow_io;
64 GURL gurl(url); 72 GURL gurl(url);
65 EXPECT_EQ("http", gurl.scheme()); 73 EXPECT_EQ("http", gurl.scheme());
66 EXPECT_EQ("localhost", gurl.host()); 74 EXPECT_EQ("localhost", gurl.host());
67 EXPECT_TRUE(file_util::PathExists(path)); 75 EXPECT_TRUE(file_util::PathExists(path));
68 responses_[gurl] = path; 76 responses_[gurl] = path;
69 } 77 }
70 78
71 79
72 void AutoUpdateInterceptor::SetResponseOnIOThread(const std::string url, 80 void AutoUpdateInterceptor::SetResponseOnIOThread(const std::string url,
73 const FilePath& path) { 81 const FilePath& path) {
74 BrowserThread::PostTask( 82 BrowserThread::PostTask(
75 BrowserThread::IO, FROM_HERE, 83 BrowserThread::IO, FROM_HERE,
76 NewRunnableMethod(this, &AutoUpdateInterceptor::SetResponse, url, path)); 84 NewRunnableMethod(this, &AutoUpdateInterceptor::SetResponse, url, path));
77 } 85 }
OLDNEW
« no previous file with comments | « base/thread_restrictions.cc ('k') | chrome/browser/io_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698