diff options
-rw-r--r-- | base/platform_thread.h | 18 | ||||
-rw-r--r-- | base/thread.h | 4 | ||||
-rw-r--r-- | base/thread_checker.cc | 13 | ||||
-rw-r--r-- | base/thread_checker.h | 8 | ||||
-rw-r--r-- | chrome/common/net/test_url_fetcher_factory.cc | 1 | ||||
-rw-r--r-- | chrome/common/service_process_util.h | 2 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_url_fetcher.h | 1 | ||||
-rw-r--r-- | chrome/service/cloud_print/print_system_cups.cc | 1 | ||||
-rw-r--r-- | net/proxy/proxy_script_fetcher_impl.h | 1 | ||||
-rw-r--r-- | net/proxy/proxy_script_fetcher_impl_unittest.cc | 68 | ||||
-rw-r--r-- | net/socket/dns_cert_provenance_check.cc | 1 | ||||
-rw-r--r-- | remoting/host/capturer_linux.h | 2 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_plugin_module.h | 1 |
13 files changed, 65 insertions, 56 deletions
diff --git a/base/platform_thread.h b/base/platform_thread.h index e330422..43bf298 100644 --- a/base/platform_thread.h +++ b/base/platform_thread.h @@ -34,9 +34,19 @@ typedef pid_t PlatformThreadId; #endif #endif +const PlatformThreadId kInvalidThreadId = 0; + // A namespace for low-level thread functions. class PlatformThread { public: + // Implement this interface to run code on a background thread. Your + // ThreadMain method will be called on the newly created thread. + class Delegate { + public: + virtual ~Delegate() {} + virtual void ThreadMain() = 0; + }; + // Gets the current thread id, which may be useful for logging purposes. static PlatformThreadId CurrentId(); @@ -49,14 +59,6 @@ class PlatformThread { // Sets the thread name visible to a debugger. This has no effect otherwise. static void SetName(const char* name); - // Implement this interface to run code on a background thread. Your - // ThreadMain method will be called on the newly created thread. - class Delegate { - public: - virtual ~Delegate() {} - virtual void ThreadMain() = 0; - }; - // Creates a new thread. The |stack_size| parameter can be 0 to indicate // that the default stack size should be used. Upon success, // |*thread_handle| will be assigned a handle to the newly created thread, diff --git a/base/thread.h b/base/thread.h index 572eb8a..fc542f0 100644 --- a/base/thread.h +++ b/base/thread.h @@ -126,8 +126,8 @@ class Thread : PlatformThread::Delegate { PlatformThreadId thread_id() const { return thread_id_; } // Returns true if the thread has been started, and not yet stopped. - // When a thread is running, the thread_id_ is non-zero. - bool IsRunning() const { return thread_id_ != 0; } + // When a thread is running, |thread_id_| is a valid id. + bool IsRunning() const { return thread_id_ != kInvalidThreadId; } protected: // Called just prior to starting the message loop diff --git a/base/thread_checker.cc b/base/thread_checker.cc index 394a90a..52f9847 100644 --- a/base/thread_checker.cc +++ b/base/thread_checker.cc @@ -7,7 +7,7 @@ // This code is only done in debug builds. #ifndef NDEBUG -ThreadChecker::ThreadChecker() { +ThreadChecker::ThreadChecker() : valid_thread_id_(kInvalidThreadId) { EnsureThreadIdAssigned(); } @@ -15,17 +15,20 @@ ThreadChecker::~ThreadChecker() {} bool ThreadChecker::CalledOnValidThread() const { EnsureThreadIdAssigned(); - return *valid_thread_id_ == PlatformThread::CurrentId(); + AutoLock auto_lock(lock_); + return valid_thread_id_ == PlatformThread::CurrentId(); } void ThreadChecker::DetachFromThread() { - valid_thread_id_.reset(); + AutoLock auto_lock(lock_); + valid_thread_id_ = kInvalidThreadId; } void ThreadChecker::EnsureThreadIdAssigned() const { - if (valid_thread_id_.get()) + AutoLock auto_lock(lock_); + if (valid_thread_id_ != kInvalidThreadId) return; - valid_thread_id_.reset(new PlatformThreadId(PlatformThread::CurrentId())); + valid_thread_id_ = PlatformThread::CurrentId(); } #endif // NDEBUG diff --git a/base/thread_checker.h b/base/thread_checker.h index 5d5445e..c09bcbe 100644 --- a/base/thread_checker.h +++ b/base/thread_checker.h @@ -6,8 +6,10 @@ #define BASE_THREAD_CHECKER_H_ #pragma once +#ifndef NDEBUG +#include "base/lock.h" #include "base/platform_thread.h" -#include "base/scoped_ptr.h" +#endif // NDEBUG // Before using this class, please consider using NonThreadSafe as it // makes it much easier to determine the nature of your class. @@ -47,8 +49,10 @@ class ThreadChecker { private: void EnsureThreadIdAssigned() const; + mutable Lock lock_; // This is mutable so that CalledOnValidThread can set it. - mutable scoped_ptr<PlatformThreadId> valid_thread_id_; + // It's guarded by |lock_|. + mutable PlatformThreadId valid_thread_id_; }; #else // Do nothing in release mode. diff --git a/chrome/common/net/test_url_fetcher_factory.cc b/chrome/common/net/test_url_fetcher_factory.cc index 48fb314..8336dfd 100644 --- a/chrome/common/net/test_url_fetcher_factory.cc +++ b/chrome/common/net/test_url_fetcher_factory.cc @@ -5,6 +5,7 @@ #include "chrome/common/net/test_url_fetcher_factory.h" #include <string> +#include "base/compiler_specific.h" #include "base/message_loop.h" #include "net/url_request/url_request_status.h" diff --git a/chrome/common/service_process_util.h b/chrome/common/service_process_util.h index 5227dc91..28304e1 100644 --- a/chrome/common/service_process_util.h +++ b/chrome/common/service_process_util.h @@ -8,6 +8,7 @@ #include <string> #include "base/process.h" +#include "base/scoped_ptr.h" #include "base/shared_memory.h" #include "base/task.h" @@ -97,4 +98,3 @@ class ServiceProcessState { }; #endif // CHROME_COMMON_SERVICE_PROCESS_UTIL_H_ - diff --git a/chrome/service/cloud_print/cloud_print_url_fetcher.h b/chrome/service/cloud_print/cloud_print_url_fetcher.h index 5ed69fc..cbf9bf2 100644 --- a/chrome/service/cloud_print/cloud_print_url_fetcher.h +++ b/chrome/service/cloud_print/cloud_print_url_fetcher.h @@ -8,6 +8,7 @@ #include <string> +#include "base/scoped_ptr.h" #include "chrome/common/net/url_fetcher.h" class DictionaryValue; diff --git a/chrome/service/cloud_print/print_system_cups.cc b/chrome/service/cloud_print/print_system_cups.cc index fe734b0..a985d79 100644 --- a/chrome/service/cloud_print/print_system_cups.cc +++ b/chrome/service/cloud_print/print_system_cups.cc @@ -20,6 +20,7 @@ #include "base/md5.h" #include "base/message_loop.h" #include "base/rand_util.h" +#include "base/scoped_ptr.h" #include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/task.h" diff --git a/net/proxy/proxy_script_fetcher_impl.h b/net/proxy/proxy_script_fetcher_impl.h index b952eeb..b671f6d 100644 --- a/net/proxy/proxy_script_fetcher_impl.h +++ b/net/proxy/proxy_script_fetcher_impl.h @@ -8,6 +8,7 @@ #include "base/basictypes.h" #include "base/ref_counted.h" +#include "base/scoped_ptr.h" #include "base/string16.h" #include "base/task.h" #include "base/time.h" diff --git a/net/proxy/proxy_script_fetcher_impl_unittest.cc b/net/proxy/proxy_script_fetcher_impl_unittest.cc index 4734997..710849c 100644 --- a/net/proxy/proxy_script_fetcher_impl_unittest.cc +++ b/net/proxy/proxy_script_fetcher_impl_unittest.cc @@ -85,14 +85,13 @@ class ProxyScriptFetcherImplTest : public PlatformTest { TEST_F(ProxyScriptFetcherImplTest, FileUrl) { scoped_refptr<URLRequestContext> context(new RequestContext); - scoped_ptr<ProxyScriptFetcher> pac_fetcher( - new ProxyScriptFetcherImpl(context)); + ProxyScriptFetcherImpl pac_fetcher(context); { // Fetch a non-existent file. string16 text; TestCompletionCallback callback; - int result = pac_fetcher->Fetch(GetTestFileUrl("does-not-exist"), - &text, &callback); + int result = pac_fetcher.Fetch(GetTestFileUrl("does-not-exist"), + &text, &callback); EXPECT_EQ(ERR_IO_PENDING, result); EXPECT_EQ(ERR_FILE_NOT_FOUND, callback.WaitForResult()); EXPECT_TRUE(text.empty()); @@ -100,8 +99,8 @@ TEST_F(ProxyScriptFetcherImplTest, FileUrl) { { // Fetch a file that exists. string16 text; TestCompletionCallback callback; - int result = pac_fetcher->Fetch(GetTestFileUrl("pac.txt"), - &text, &callback); + int result = pac_fetcher.Fetch(GetTestFileUrl("pac.txt"), + &text, &callback); EXPECT_EQ(ERR_IO_PENDING, result); EXPECT_EQ(OK, callback.WaitForResult()); EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text); @@ -114,14 +113,13 @@ TEST_F(ProxyScriptFetcherImplTest, HttpMimeType) { ASSERT_TRUE(test_server_.Start()); scoped_refptr<URLRequestContext> context(new RequestContext); - scoped_ptr<ProxyScriptFetcher> pac_fetcher( - new ProxyScriptFetcherImpl(context)); + ProxyScriptFetcherImpl pac_fetcher(context); { // Fetch a PAC with mime type "text/plain" GURL url(test_server_.GetURL("files/pac.txt")); string16 text; TestCompletionCallback callback; - int result = pac_fetcher->Fetch(url, &text, &callback); + int result = pac_fetcher.Fetch(url, &text, &callback); EXPECT_EQ(ERR_IO_PENDING, result); EXPECT_EQ(OK, callback.WaitForResult()); EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text); @@ -130,7 +128,7 @@ TEST_F(ProxyScriptFetcherImplTest, HttpMimeType) { GURL url(test_server_.GetURL("files/pac.html")); string16 text; TestCompletionCallback callback; - int result = pac_fetcher->Fetch(url, &text, &callback); + int result = pac_fetcher.Fetch(url, &text, &callback); EXPECT_EQ(ERR_IO_PENDING, result); EXPECT_EQ(OK, callback.WaitForResult()); EXPECT_EQ(ASCIIToUTF16("-pac.html-\n"), text); @@ -139,7 +137,7 @@ TEST_F(ProxyScriptFetcherImplTest, HttpMimeType) { GURL url(test_server_.GetURL("files/pac.nsproxy")); string16 text; TestCompletionCallback callback; - int result = pac_fetcher->Fetch(url, &text, &callback); + int result = pac_fetcher.Fetch(url, &text, &callback); EXPECT_EQ(ERR_IO_PENDING, result); EXPECT_EQ(OK, callback.WaitForResult()); EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); @@ -150,14 +148,13 @@ TEST_F(ProxyScriptFetcherImplTest, HttpStatusCode) { ASSERT_TRUE(test_server_.Start()); scoped_refptr<URLRequestContext> context(new RequestContext); - scoped_ptr<ProxyScriptFetcher> pac_fetcher( - new ProxyScriptFetcherImpl(context)); + ProxyScriptFetcherImpl pac_fetcher(context); { // Fetch a PAC which gives a 500 -- FAIL GURL url(test_server_.GetURL("files/500.pac")); string16 text; TestCompletionCallback callback; - int result = pac_fetcher->Fetch(url, &text, &callback); + int result = pac_fetcher.Fetch(url, &text, &callback); EXPECT_EQ(ERR_IO_PENDING, result); EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); EXPECT_TRUE(text.empty()); @@ -166,7 +163,7 @@ TEST_F(ProxyScriptFetcherImplTest, HttpStatusCode) { GURL url(test_server_.GetURL("files/404.pac")); string16 text; TestCompletionCallback callback; - int result = pac_fetcher->Fetch(url, &text, &callback); + int result = pac_fetcher.Fetch(url, &text, &callback); EXPECT_EQ(ERR_IO_PENDING, result); EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); EXPECT_TRUE(text.empty()); @@ -177,15 +174,14 @@ TEST_F(ProxyScriptFetcherImplTest, ContentDisposition) { ASSERT_TRUE(test_server_.Start()); scoped_refptr<URLRequestContext> context(new RequestContext); - scoped_ptr<ProxyScriptFetcher> pac_fetcher( - new ProxyScriptFetcherImpl(context)); + ProxyScriptFetcherImpl pac_fetcher(context); // Fetch PAC scripts via HTTP with a Content-Disposition header -- should // have no effect. GURL url(test_server_.GetURL("files/downloadable.pac")); string16 text; TestCompletionCallback callback; - int result = pac_fetcher->Fetch(url, &text, &callback); + int result = pac_fetcher.Fetch(url, &text, &callback); EXPECT_EQ(ERR_IO_PENDING, result); EXPECT_EQ(OK, callback.WaitForResult()); EXPECT_EQ(ASCIIToUTF16("-downloadable.pac-\n"), text); @@ -195,15 +191,14 @@ TEST_F(ProxyScriptFetcherImplTest, NoCache) { ASSERT_TRUE(test_server_.Start()); scoped_refptr<URLRequestContext> context(new RequestContext); - scoped_ptr<ProxyScriptFetcher> pac_fetcher( - new ProxyScriptFetcherImpl(context)); + ProxyScriptFetcherImpl pac_fetcher(context); // Fetch a PAC script whose HTTP headers make it cacheable for 1 hour. GURL url(test_server_.GetURL("files/cacheable_1hr.pac")); { string16 text; TestCompletionCallback callback; - int result = pac_fetcher->Fetch(url, &text, &callback); + int result = pac_fetcher.Fetch(url, &text, &callback); EXPECT_EQ(ERR_IO_PENDING, result); EXPECT_EQ(OK, callback.WaitForResult()); EXPECT_EQ(ASCIIToUTF16("-cacheable_1hr.pac-\n"), text); @@ -218,7 +213,7 @@ TEST_F(ProxyScriptFetcherImplTest, NoCache) { { string16 text; TestCompletionCallback callback; - int result = pac_fetcher->Fetch(url, &text, &callback); + int result = pac_fetcher.Fetch(url, &text, &callback); EXPECT_EQ(ERR_IO_PENDING, result); EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); } @@ -228,11 +223,10 @@ TEST_F(ProxyScriptFetcherImplTest, TooLarge) { ASSERT_TRUE(test_server_.Start()); scoped_refptr<URLRequestContext> context(new RequestContext); - scoped_ptr<ProxyScriptFetcherImpl> pac_fetcher( - new ProxyScriptFetcherImpl(context)); + ProxyScriptFetcherImpl pac_fetcher(context); // Set the maximum response size to 50 bytes. - int prev_size = pac_fetcher->SetSizeConstraint(50); + int prev_size = pac_fetcher.SetSizeConstraint(50); // These two URLs are the same file, but are http:// vs file:// GURL urls[] = { @@ -246,20 +240,20 @@ TEST_F(ProxyScriptFetcherImplTest, TooLarge) { const GURL& url = urls[i]; string16 text; TestCompletionCallback callback; - int result = pac_fetcher->Fetch(url, &text, &callback); + int result = pac_fetcher.Fetch(url, &text, &callback); EXPECT_EQ(ERR_IO_PENDING, result); EXPECT_EQ(ERR_FILE_TOO_BIG, callback.WaitForResult()); EXPECT_TRUE(text.empty()); } // Restore the original size bound. - pac_fetcher->SetSizeConstraint(prev_size); + pac_fetcher.SetSizeConstraint(prev_size); { // Make sure we can still fetch regular URLs. GURL url(test_server_.GetURL("files/pac.nsproxy")); string16 text; TestCompletionCallback callback; - int result = pac_fetcher->Fetch(url, &text, &callback); + int result = pac_fetcher.Fetch(url, &text, &callback); EXPECT_EQ(ERR_IO_PENDING, result); EXPECT_EQ(OK, callback.WaitForResult()); EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); @@ -270,11 +264,10 @@ TEST_F(ProxyScriptFetcherImplTest, Hang) { ASSERT_TRUE(test_server_.Start()); scoped_refptr<URLRequestContext> context(new RequestContext); - scoped_ptr<ProxyScriptFetcherImpl> pac_fetcher( - new ProxyScriptFetcherImpl(context)); + ProxyScriptFetcherImpl pac_fetcher(context); // Set the timeout period to 0.5 seconds. - base::TimeDelta prev_timeout = pac_fetcher->SetTimeoutConstraint( + base::TimeDelta prev_timeout = pac_fetcher.SetTimeoutConstraint( base::TimeDelta::FromMilliseconds(500)); // Try fetching a URL which takes 1.2 seconds. We should abort the request @@ -282,20 +275,20 @@ TEST_F(ProxyScriptFetcherImplTest, Hang) { { GURL url(test_server_.GetURL("slow/proxy.pac?1.2")); string16 text; TestCompletionCallback callback; - int result = pac_fetcher->Fetch(url, &text, &callback); + int result = pac_fetcher.Fetch(url, &text, &callback); EXPECT_EQ(ERR_IO_PENDING, result); EXPECT_EQ(ERR_TIMED_OUT, callback.WaitForResult()); EXPECT_TRUE(text.empty()); } // Restore the original timeout period. - pac_fetcher->SetTimeoutConstraint(prev_timeout); + pac_fetcher.SetTimeoutConstraint(prev_timeout); { // Make sure we can still fetch regular URLs. GURL url(test_server_.GetURL("files/pac.nsproxy")); string16 text; TestCompletionCallback callback; - int result = pac_fetcher->Fetch(url, &text, &callback); + int result = pac_fetcher.Fetch(url, &text, &callback); EXPECT_EQ(ERR_IO_PENDING, result); EXPECT_EQ(OK, callback.WaitForResult()); EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); @@ -309,15 +302,14 @@ TEST_F(ProxyScriptFetcherImplTest, Encodings) { ASSERT_TRUE(test_server_.Start()); scoped_refptr<URLRequestContext> context(new RequestContext); - scoped_ptr<ProxyScriptFetcher> pac_fetcher( - new ProxyScriptFetcherImpl(context)); + ProxyScriptFetcherImpl pac_fetcher(context); // Test a response that is gzip-encoded -- should get inflated. { GURL url(test_server_.GetURL("files/gzipped_pac")); string16 text; TestCompletionCallback callback; - int result = pac_fetcher->Fetch(url, &text, &callback); + int result = pac_fetcher.Fetch(url, &text, &callback); EXPECT_EQ(ERR_IO_PENDING, result); EXPECT_EQ(OK, callback.WaitForResult()); EXPECT_EQ(ASCIIToUTF16("This data was gzipped.\n"), text); @@ -329,7 +321,7 @@ TEST_F(ProxyScriptFetcherImplTest, Encodings) { GURL url(test_server_.GetURL("files/utf16be_pac")); string16 text; TestCompletionCallback callback; - int result = pac_fetcher->Fetch(url, &text, &callback); + int result = pac_fetcher.Fetch(url, &text, &callback); EXPECT_EQ(ERR_IO_PENDING, result); EXPECT_EQ(OK, callback.WaitForResult()); EXPECT_EQ(ASCIIToUTF16("This was encoded as UTF-16BE.\n"), text); diff --git a/net/socket/dns_cert_provenance_check.cc b/net/socket/dns_cert_provenance_check.cc index 61b9a04..a478820 100644 --- a/net/socket/dns_cert_provenance_check.cc +++ b/net/socket/dns_cert_provenance_check.cc @@ -17,6 +17,7 @@ #include "base/crypto/symmetric_key.h" #include "base/non_thread_safe.h" #include "base/pickle.h" +#include "base/scoped_ptr.h" #include "net/base/completion_callback.h" #include "net/base/dns_util.h" #include "net/base/dnsrr_resolver.h" diff --git a/remoting/host/capturer_linux.h b/remoting/host/capturer_linux.h index 6f854fc..8e8fcb3 100644 --- a/remoting/host/capturer_linux.h +++ b/remoting/host/capturer_linux.h @@ -5,6 +5,8 @@ #ifndef REMOTING_HOST_CAPTURER_LINUX_H_ #define REMOTING_HOST_CAPTURER_LINUX_H_ +#include "base/basictypes.h" +#include "base/scoped_ptr.h" #include "remoting/host/capturer.h" namespace remoting { diff --git a/webkit/glue/plugins/pepper_plugin_module.h b/webkit/glue/plugins/pepper_plugin_module.h index 6ba3146..80eccda 100644 --- a/webkit/glue/plugins/pepper_plugin_module.h +++ b/webkit/glue/plugins/pepper_plugin_module.h @@ -11,6 +11,7 @@ #include "base/basictypes.h" #include "base/native_library.h" #include "base/ref_counted.h" +#include "base/scoped_ptr.h" #include "base/weak_ptr.h" #include "ppapi/c/pp_module.h" #include "ppapi/c/ppb.h" |