diff options
16 files changed, 110 insertions, 47 deletions
diff --git a/base/memory/scoped_ptr.h b/base/memory/scoped_ptr.h index e5d5e22..b14287c 100644 --- a/base/memory/scoped_ptr.h +++ b/base/memory/scoped_ptr.h @@ -103,14 +103,10 @@ #include "base/macros.h" #include "base/move.h" #include "base/template_util.h" +#include "build/build_config.h" namespace base { -namespace subtle { -class RefCountedBase; -class RefCountedThreadSafeBase; -} // namespace subtle - // Function object which invokes 'free' on its parameter, which must be // a pointer. Can be used to store malloc-allocated pointers in scoped_ptr: // @@ -122,6 +118,63 @@ struct FreeDeleter { } }; +} // namespace base + +// Now that scoped_ptr is almost 100% compatible with std::unique_ptr, we're +// incrementally migrating scoped_ptr to just be a type alias for +// std::unique_ptr. The eventual goal is to delete scoped_ptr altogether. +#if defined(OS_LINUX) +template <typename T, typename D = std::default_delete<T>> +using scoped_ptr = std::unique_ptr<T, D>; + +// Versions of libstdc++ 4.8 lack overloads for <, <=, >, and >= when comparing +// a std::unique_ptr and nullptr_t. +#if defined(__GLIBCXX__) && __GLIBCXX__ < 20150426 +template <class T, class D> +bool operator<(const scoped_ptr<T, D>& p, std::nullptr_t) { + return p.get() < nullptr; +} +template <class T, class D> +bool operator<(std::nullptr_t, const scoped_ptr<T, D>& p) { + return nullptr < p.get(); +} + +template <class T, class D> +bool operator>(const scoped_ptr<T, D>& p, std::nullptr_t) { + return nullptr < p; +} +template <class T, class D> +bool operator>(std::nullptr_t, const scoped_ptr<T, D>& p) { + return p < nullptr; +} + +template <class T, class D> +bool operator<=(const scoped_ptr<T, D>& p, std::nullptr_t) { + return !(p > nullptr); +} +template <class T, class D> +bool operator<=(std::nullptr_t, const scoped_ptr<T, D>& p) { + return !(nullptr > p); +} + +template <class T, class D> +bool operator>=(const scoped_ptr<T, D>& p, std::nullptr_t) { + return !(p < nullptr); +} +template <class T, class D> +bool operator>=(std::nullptr_t, const scoped_ptr<T, D>& p) { + return !(nullptr < p); +} +#endif // defined(__GLIBCXX__) && __GLIBCX__ < 20150426 + +#else +namespace base { + +namespace subtle { +class RefCountedBase; +class RefCountedThreadSafeBase; +} // namespace subtle + namespace internal { template <typename T> struct IsNotRefCounted { @@ -610,6 +663,12 @@ bool operator>=(std::nullptr_t, const scoped_ptr<T, D>& p) { return !(nullptr < p); } +template <typename T> +std::ostream& operator<<(std::ostream& out, const scoped_ptr<T>& p) { + return out << p.get(); +} +#endif // defined(OS_LINUX) + // A function to convert T* into scoped_ptr<T> // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) @@ -618,9 +677,4 @@ scoped_ptr<T> make_scoped_ptr(T* ptr) { return scoped_ptr<T>(ptr); } -template <typename T> -std::ostream& operator<<(std::ostream& out, const scoped_ptr<T>& p) { - return out << p.get(); -} - #endif // BASE_MEMORY_SCOPED_PTR_H_ diff --git a/base/memory/scoped_ptr_unittest.cc b/base/memory/scoped_ptr_unittest.cc index ba977c7..0e4f979 100644 --- a/base/memory/scoped_ptr_unittest.cc +++ b/base/memory/scoped_ptr_unittest.cc @@ -6,8 +6,6 @@ #include <stddef.h> -#include <sstream> - #include "base/bind.h" #include "base/callback.h" #include "base/macros.h" @@ -650,19 +648,6 @@ TEST(ScopedPtrTest, Conversion) { super2 = SubClassReturn(); } -// Logging a scoped_ptr<T> to an ostream shouldn't convert it to a boolean -// value first. -TEST(ScopedPtrTest, LoggingDoesntConvertToBoolean) { - scoped_ptr<int> x(new int); - std::stringstream s1; - s1 << x; - - std::stringstream s2; - s2 << x.get(); - - EXPECT_EQ(s2.str(), s1.str()); -} - TEST(ScopedPtrTest, ReferenceCycle) { struct StructB; struct StructA { diff --git a/chrome/browser/chromeos/display/display_preferences_unittest.cc b/chrome/browser/chromeos/display/display_preferences_unittest.cc index bd6edd1..71c56db 100644 --- a/chrome/browser/chromeos/display/display_preferences_unittest.cc +++ b/chrome/browser/chromeos/display/display_preferences_unittest.cc @@ -141,7 +141,7 @@ class DisplayPreferencesTest : public ash::test::AshTestBase { } else { scoped_ptr<base::DictionaryValue> layout_value( new base::DictionaryValue()); - layout_value->SetBoolean(key, value); + layout_value->SetBoolean(key, value != nullptr); pref_data->Set(name, layout_value.release()); } } diff --git a/chrome/browser/chromeos/extensions/device_local_account_external_policy_loader.cc b/chrome/browser/chromeos/extensions/device_local_account_external_policy_loader.cc index 49b67d0..3e4508f 100644 --- a/chrome/browser/chromeos/extensions/device_local_account_external_policy_loader.cc +++ b/chrome/browser/chromeos/extensions/device_local_account_external_policy_loader.cc @@ -26,7 +26,7 @@ DeviceLocalAccountExternalPolicyLoader:: } bool DeviceLocalAccountExternalPolicyLoader::IsCacheRunning() const { - return external_cache_; + return external_cache_ != nullptr; } void DeviceLocalAccountExternalPolicyLoader::StartCache( diff --git a/chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.cc b/chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.cc index ddd681e..430f28b 100644 --- a/chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.cc +++ b/chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.cc @@ -149,11 +149,11 @@ bool FileSystemProviderMountFunction::RunSync() { MountOptions options; options.file_system_id = params->options.file_system_id; options.display_name = params->options.display_name; - options.writable = params->options.writable; + options.writable = params->options.writable != nullptr; options.opened_files_limit = params->options.opened_files_limit.get() ? *params->options.opened_files_limit.get() : 0; - options.supports_notify_tag = params->options.supports_notify_tag; + options.supports_notify_tag = params->options.supports_notify_tag != nullptr; const base::File::Error result = service->MountFileSystem(extension_id(), options); diff --git a/chrome/browser/chromeos/login/auth/cryptohome_authenticator_unittest.cc b/chrome/browser/chromeos/login/auth/cryptohome_authenticator_unittest.cc index 13fe01e..606ca65 100644 --- a/chrome/browser/chromeos/login/auth/cryptohome_authenticator_unittest.cc +++ b/chrome/browser/chromeos/login/auth/cryptohome_authenticator_unittest.cc @@ -124,8 +124,8 @@ std::vector<uint8_t> GetOwnerPublicKey() { bool CreateOwnerKeyInSlot(PK11SlotInfo* slot) { const std::vector<uint8_t> key( kOwnerPrivateKey, kOwnerPrivateKey + arraysize(kOwnerPrivateKey)); - return crypto::ImportNSSKeyFromPrivateKeyInfo(slot, key, - true /* permanent */); + return crypto::ImportNSSKeyFromPrivateKeyInfo( + slot, key, true /* permanent */) != nullptr; } } // namespace diff --git a/chrome/browser/chromeos/policy/device_local_account_policy_service.cc b/chrome/browser/chromeos/policy/device_local_account_policy_service.cc index 5463d6e..6eed578 100644 --- a/chrome/browser/chromeos/policy/device_local_account_policy_service.cc +++ b/chrome/browser/chromeos/policy/device_local_account_policy_service.cc @@ -165,7 +165,7 @@ void DeviceLocalAccountPolicyBroker::Initialize() { } bool DeviceLocalAccountPolicyBroker::HasInvalidatorForTest() const { - return invalidator_; + return invalidator_ != nullptr; } void DeviceLocalAccountPolicyBroker::ConnectIfPossible( diff --git a/chrome/browser/extensions/api/braille_display_private/brlapi_connection.cc b/chrome/browser/extensions/api/braille_display_private/brlapi_connection.cc index 081b571..db10631 100644 --- a/chrome/browser/extensions/api/braille_display_private/brlapi_connection.cc +++ b/chrome/browser/extensions/api/braille_display_private/brlapi_connection.cc @@ -39,7 +39,7 @@ class BrlapiConnectionImpl : public BrlapiConnection, ConnectResult Connect(const OnDataReadyCallback& on_data_ready) override; void Disconnect() override; - bool Connected() override { return handle_; } + bool Connected() override { return handle_ != nullptr; } brlapi_error_t* BrlapiError() override; std::string BrlapiStrError() override; bool GetDisplaySize(size_t* size) override; diff --git a/chromecast/base/bind_to_task_runner_unittest.cc b/chromecast/base/bind_to_task_runner_unittest.cc index 240c8f9..20f21c2 100644 --- a/chromecast/base/bind_to_task_runner_unittest.cc +++ b/chromecast/base/bind_to_task_runner_unittest.cc @@ -23,7 +23,7 @@ void BoundBoolSetFromScopedPtr(bool* var, scoped_ptr<bool> val) { void BoundBoolSetFromScopedPtrFreeDeleter( bool* var, scoped_ptr<bool, base::FreeDeleter> val) { - *var = val; + *var = *val; } void BoundBoolSetFromScopedArray(bool* var, scoped_ptr<bool[]> val) { diff --git a/chromeos/cryptohome/cryptohome_parameters.cc b/chromeos/cryptohome/cryptohome_parameters.cc index 8b65a71..c484947 100644 --- a/chromeos/cryptohome/cryptohome_parameters.cc +++ b/chromeos/cryptohome/cryptohome_parameters.cc @@ -109,10 +109,10 @@ KeyDefinition::ProviderData::~ProviderData() { } bool KeyDefinition::ProviderData::operator==(const ProviderData& other) const { - const bool has_number = number; - const bool other_has_number = other.number; - const bool has_bytes = bytes; - const bool other_has_bytes = other.bytes; + const bool has_number = number != nullptr; + const bool other_has_number = other.number != nullptr; + const bool has_bytes = bytes != nullptr; + const bool other_has_bytes = other.bytes != nullptr; return name == other.name && has_number == other_has_number && has_bytes == other_has_bytes && diff --git a/components/drive/file_system_unittest.cc b/components/drive/file_system_unittest.cc index 271dba1..f32ebcb 100644 --- a/components/drive/file_system_unittest.cc +++ b/components/drive/file_system_unittest.cc @@ -206,7 +206,7 @@ class FileSystemTest : public testing::Test { // Returns true if an entry exists at |file_path|. bool EntryExists(const base::FilePath& file_path) { - return GetResourceEntrySync(file_path); + return GetResourceEntrySync(file_path) != nullptr; } // Flag for specifying the timestamp of the test filesystem cache. diff --git a/content/browser/renderer_host/input/mouse_wheel_event_queue.h b/content/browser/renderer_host/input/mouse_wheel_event_queue.h index 3c9802e..b5ad7f2 100644 --- a/content/browser/renderer_host/input/mouse_wheel_event_queue.h +++ b/content/browser/renderer_host/input/mouse_wheel_event_queue.h @@ -70,7 +70,9 @@ class CONTENT_EXPORT MouseWheelEventQueue { } size_t queued_size() const { return wheel_queue_.size(); } - bool event_in_flight() const { return event_sent_for_gesture_ack_; } + bool event_in_flight() const { + return event_sent_for_gesture_ack_ != nullptr; + } private: void TryForwardNextEventToRenderer(); diff --git a/extensions/browser/api/hid/hid_api.cc b/extensions/browser/api/hid/hid_api.cc index 59e2bfb..77972ea 100644 --- a/extensions/browser/api/hid/hid_api.cc +++ b/extensions/browser/api/hid/hid_api.cc @@ -20,6 +20,27 @@ #include "extensions/common/api/hid.h" #include "net/base/io_buffer.h" +// The normal EXTENSION_FUNCTION_VALIDATE macro doesn't work well here. It's +// used in functions that returns a bool. However, EXTENSION_FUNCTION_VALIDATE +// returns a smart pointer on failure. +// +// With C++11, this is problematic since a smart pointer that uses explicit +// operator bool won't allow this conversion, since it's not in a context (such +// as a conditional) where a contextual conversion to bool would be allowed. +// TODO(rdevlin.cronin): restructure this code to remove the need for the +// additional macro. +#ifdef NDEBUG +#define EXTENSION_FUNCTION_VALIDATE_RETURN_FALSE_ON_ERROR(test) \ + do { \ + if (!(test)) { \ + this->bad_message_ = true; \ + return false; \ + } \ + } while (0) +#else // NDEBUG +#define EXTENSION_FUNCTION_VALIDATE_RETURN_FALSE_ON_ERROR(test) CHECK(test) +#endif // NDEBUG + namespace hid = extensions::api::hid; using device::HidConnection; @@ -250,7 +271,7 @@ HidReceiveFunction::~HidReceiveFunction() {} bool HidReceiveFunction::ValidateParameters() { parameters_ = hid::Receive::Params::Create(*args_); - EXTENSION_FUNCTION_VALIDATE(parameters_); + EXTENSION_FUNCTION_VALIDATE_RETURN_FALSE_ON_ERROR(parameters_); set_connection_id(parameters_->connection_id); return true; } @@ -280,7 +301,7 @@ HidSendFunction::~HidSendFunction() {} bool HidSendFunction::ValidateParameters() { parameters_ = hid::Send::Params::Create(*args_); - EXTENSION_FUNCTION_VALIDATE(parameters_); + EXTENSION_FUNCTION_VALIDATE_RETURN_FALSE_ON_ERROR(parameters_); set_connection_id(parameters_->connection_id); return true; } @@ -309,7 +330,7 @@ HidReceiveFeatureReportFunction::~HidReceiveFeatureReportFunction() {} bool HidReceiveFeatureReportFunction::ValidateParameters() { parameters_ = hid::ReceiveFeatureReport::Params::Create(*args_); - EXTENSION_FUNCTION_VALIDATE(parameters_); + EXTENSION_FUNCTION_VALIDATE_RETURN_FALSE_ON_ERROR(parameters_); set_connection_id(parameters_->connection_id); return true; } @@ -338,7 +359,7 @@ HidSendFeatureReportFunction::~HidSendFeatureReportFunction() {} bool HidSendFeatureReportFunction::ValidateParameters() { parameters_ = hid::SendFeatureReport::Params::Create(*args_); - EXTENSION_FUNCTION_VALIDATE(parameters_); + EXTENSION_FUNCTION_VALIDATE_RETURN_FALSE_ON_ERROR(parameters_); set_connection_id(parameters_->connection_id); return true; } diff --git a/extensions/browser/api/webcam_private/webcam_private_api_chromeos.cc b/extensions/browser/api/webcam_private/webcam_private_api_chromeos.cc index 02edcfa..31e381b 100644 --- a/extensions/browser/api/webcam_private/webcam_private_api_chromeos.cc +++ b/extensions/browser/api/webcam_private/webcam_private_api_chromeos.cc @@ -408,7 +408,8 @@ bool WebcamPrivateResetFunction::RunAsync() { return false; } - webcam->Reset(params->config.pan, params->config.tilt, params->config.zoom, + webcam->Reset(params->config.pan != nullptr, params->config.tilt != nullptr, + params->config.zoom != nullptr, base::Bind(&WebcamPrivateResetFunction::OnResetWebcam, this)); return true; diff --git a/media/blink/resource_multibuffer_data_provider_unittest.cc b/media/blink/resource_multibuffer_data_provider_unittest.cc index 91975c1..1055a2b 100644 --- a/media/blink/resource_multibuffer_data_provider_unittest.cc +++ b/media/blink/resource_multibuffer_data_provider_unittest.cc @@ -207,7 +207,7 @@ class ResourceMultiBufferDataProviderTest : public testing::Test { EXPECT_EQ(0, memcmp(buffer, data_ + pos, size)); } - bool HasActiveLoader() { return loader_->active_loader_; } + bool HasActiveLoader() { return loader_->active_loader_ != nullptr; } MOCK_METHOD1(RedirectCallback, void(const scoped_refptr<UrlData>&)); void SetUrlData(const scoped_refptr<UrlData>& new_url_data) { diff --git a/ui/keyboard/keyboard_controller.h b/ui/keyboard/keyboard_controller.h index 09d0a21..3c0765e5 100644 --- a/ui/keyboard/keyboard_controller.h +++ b/ui/keyboard/keyboard_controller.h @@ -65,7 +65,7 @@ class KEYBOARD_EXPORT KeyboardController : public ui::InputMethodObserver, aura::Window* GetContainerWindow(); // Whether the container window for the keyboard has been initialized. - bool keyboard_container_initialized() const { return container_; } + bool keyboard_container_initialized() const { return container_ != nullptr; } // Reloads the content of the keyboard. No-op if the keyboard content is not // loaded yet. |