Skip to content

Commit

Permalink
Convert //cc from scoped_ptr to std::unique_ptr.
Browse files Browse the repository at this point in the history
R=enne, vmpstr
TBR=piman,sky, skyostil
BUG=554298
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel

Review URL: https://codereview.chromium.org/1866203004

Cr-Commit-Position: refs/heads/master@{#386260}
  • Loading branch information
danakj authored and Commit bot committed Apr 9, 2016
1 parent 646e362 commit 60bc3bc
Show file tree
Hide file tree
Showing 530 changed files with 4,795 additions and 4,231 deletions.
24 changes: 12 additions & 12 deletions cc/PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def CheckDoubleAngles(input_api, output_api, white_list=CC_SOURCE_FILES,
return [output_api.PresubmitError('Use >> instead of > >:', items=errors)]
return []

def CheckScopedPtr(input_api, output_api,
def CheckUniquePtr(input_api, output_api,
white_list=CC_SOURCE_FILES, black_list=None):
black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST)
source_file_filter = lambda x: input_api.FilterSourceFile(x,
Expand All @@ -162,20 +162,20 @@ def CheckScopedPtr(input_api, output_api,
for f in input_api.AffectedSourceFiles(source_file_filter):
for line_number, line in f.ChangedContents():
# Disallow:
# return scoped_ptr<T>(foo);
# bar = scoped_ptr<T>(foo);
# return std::unique_ptr<T>(foo);
# bar = std::unique_ptr<T>(foo);
# But allow:
# return scoped_ptr<T[]>(foo);
# bar = scoped_ptr<T[]>(foo);
if re.search(r'(=|\breturn)\s*scoped_ptr<.*?(?<!])>\([^)]+\)', line):
# return std::unique_ptr<T[]>(foo);
# bar = std::unique_ptr<T[]>(foo);
if re.search(r'(=|\breturn)\s*std::unique_ptr<.*?(?<!])>\([^)]+\)', line):
errors.append(output_api.PresubmitError(
('%s:%d uses explicit scoped_ptr constructor. ' +
'Use make_scoped_ptr() instead.') % (f.LocalPath(), line_number)))
('%s:%d uses explicit std::unique_ptr constructor. ' +
'Use base::WrapUnique() instead.') % (f.LocalPath(), line_number)))
# Disallow:
# scoped_ptr<T>()
if re.search(r'\bscoped_ptr<.*?>\(\)', line):
# std::unique_ptr<T>()
if re.search(r'\bstd::unique_ptr<.*?>\(\)', line):
errors.append(output_api.PresubmitError(
'%s:%d uses scoped_ptr<T>(). Use nullptr instead.' %
'%s:%d uses std::unique_ptr<T>(). Use nullptr instead.' %
(f.LocalPath(), line_number)))
return errors

Expand Down Expand Up @@ -318,7 +318,7 @@ def CheckChangeOnUpload(input_api, output_api):
results += CheckChangeLintsClean(input_api, output_api)
results += CheckTodos(input_api, output_api)
results += CheckDoubleAngles(input_api, output_api)
results += CheckScopedPtr(input_api, output_api)
results += CheckUniquePtr(input_api, output_api)
results += CheckNamespace(input_api, output_api)
results += CheckForUseOfWrongClock(input_api, output_api)
results += FindUselessIfdefs(input_api, output_api)
Expand Down
18 changes: 10 additions & 8 deletions cc/animation/animation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <cmath>

#include "base/memory/ptr_util.h"
#include "base/strings/string_util.h"
#include "base/trace_event/trace_event.h"
#include "cc/animation/animation_curve.h"
Expand All @@ -32,15 +33,16 @@ static_assert(static_cast<int>(cc::Animation::LAST_RUN_STATE) + 1 ==

namespace cc {

scoped_ptr<Animation> Animation::Create(scoped_ptr<AnimationCurve> curve,
int animation_id,
int group_id,
TargetProperty::Type target_property) {
return make_scoped_ptr(
std::unique_ptr<Animation> Animation::Create(
std::unique_ptr<AnimationCurve> curve,
int animation_id,
int group_id,
TargetProperty::Type target_property) {
return base::WrapUnique(
new Animation(std::move(curve), animation_id, group_id, target_property));
}

Animation::Animation(scoped_ptr<AnimationCurve> curve,
Animation::Animation(std::unique_ptr<AnimationCurve> curve,
int animation_id,
int group_id,
TargetProperty::Type target_property)
Expand Down Expand Up @@ -238,9 +240,9 @@ base::TimeDelta Animation::TrimTimeToCurrentIteration(
return iteration_time;
}

scoped_ptr<Animation> Animation::CloneAndInitialize(
std::unique_ptr<Animation> Animation::CloneAndInitialize(
RunState initial_run_state) const {
scoped_ptr<Animation> to_return(
std::unique_ptr<Animation> to_return(
new Animation(curve_->Clone(), id_, group_, target_property_));
to_return->run_state_ = initial_run_state;
to_return->iterations_ = iterations_;
Expand Down
19 changes: 11 additions & 8 deletions cc/animation/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#ifndef CC_ANIMATION_ANIMATION_H_
#define CC_ANIMATION_ANIMATION_H_

#include <memory>

#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "cc/animation/target_property.h"
#include "cc/base/cc_export.h"
Expand Down Expand Up @@ -58,10 +59,11 @@ class CC_EXPORT Animation {
FILL_MODE_BOTH
};

static scoped_ptr<Animation> Create(scoped_ptr<AnimationCurve> curve,
int animation_id,
int group_id,
TargetProperty::Type target_property);
static std::unique_ptr<Animation> Create(
std::unique_ptr<AnimationCurve> curve,
int animation_id,
int group_id,
TargetProperty::Type target_property);

virtual ~Animation();

Expand Down Expand Up @@ -144,7 +146,8 @@ class CC_EXPORT Animation {
base::TimeDelta TrimTimeToCurrentIteration(
base::TimeTicks monotonic_time) const;

scoped_ptr<Animation> CloneAndInitialize(RunState initial_run_state) const;
std::unique_ptr<Animation> CloneAndInitialize(
RunState initial_run_state) const;

void set_is_controlling_instance_for_test(bool is_controlling_instance) {
is_controlling_instance_ = is_controlling_instance;
Expand All @@ -167,14 +170,14 @@ class CC_EXPORT Animation {
bool affects_pending_observers() const { return affects_pending_observers_; }

private:
Animation(scoped_ptr<AnimationCurve> curve,
Animation(std::unique_ptr<AnimationCurve> curve,
int animation_id,
int group_id,
TargetProperty::Type target_property);

base::TimeDelta ConvertToActiveTime(base::TimeTicks monotonic_time) const;

scoped_ptr<AnimationCurve> curve_;
std::unique_ptr<AnimationCurve> curve_;

// IDs must be unique.
int id_;
Expand Down
5 changes: 3 additions & 2 deletions cc/animation/animation_curve.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#ifndef CC_ANIMATION_ANIMATION_CURVE_H_
#define CC_ANIMATION_ANIMATION_CURVE_H_

#include "base/memory/scoped_ptr.h"
#include <memory>

#include "base/time/time.h"
#include "cc/base/cc_export.h"
#include "cc/output/filter_operations.h"
Expand Down Expand Up @@ -33,7 +34,7 @@ class CC_EXPORT AnimationCurve {

virtual base::TimeDelta Duration() const = 0;
virtual CurveType Type() const = 0;
virtual scoped_ptr<AnimationCurve> Clone() const = 0;
virtual std::unique_ptr<AnimationCurve> Clone() const = 0;

const ColorAnimationCurve* ToColorAnimationCurve() const;
const FloatAnimationCurve* ToFloatAnimationCurve() const;
Expand Down
9 changes: 5 additions & 4 deletions cc/animation/animation_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ class CC_EXPORT AnimationDelegate {
TargetProperty::Type target_property,
int group) = 0;

virtual void NotifyAnimationTakeover(base::TimeTicks monotonic_time,
TargetProperty::Type target_property,
double animation_start_time,
scoped_ptr<AnimationCurve> curve) = 0;
virtual void NotifyAnimationTakeover(
base::TimeTicks monotonic_time,
TargetProperty::Type target_property,
double animation_start_time,
std::unique_ptr<AnimationCurve> curve) = 0;

protected:
virtual ~AnimationDelegate() {}
Expand Down
4 changes: 2 additions & 2 deletions cc/animation/animation_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#ifndef CC_ANIMATION_ANIMATION_EVENTS_H_
#define CC_ANIMATION_ANIMATION_EVENTS_H_

#include <memory>
#include <vector>

#include "base/memory/scoped_ptr.h"
#include "cc/animation/animation.h"
#include "cc/animation/animation_curve.h"
#include "cc/base/cc_export.h"
Expand Down Expand Up @@ -42,7 +42,7 @@ struct CC_EXPORT AnimationEvent {

// For continuing a scroll offset animation on the main thread.
double animation_start_time;
scoped_ptr<AnimationCurve> curve;
std::unique_ptr<AnimationCurve> curve;
};

class CC_EXPORT AnimationEvents {
Expand Down
19 changes: 11 additions & 8 deletions cc/animation/animation_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <algorithm>

#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "cc/animation/animation_delegate.h"
#include "cc/animation/animation_events.h"
#include "cc/animation/animation_id_provider.h"
Expand Down Expand Up @@ -46,13 +47,13 @@ class AnimationHost::ScrollOffsetAnimations : public AnimationDelegate {
void ScrollAnimationCreate(int layer_id,
const gfx::ScrollOffset& target_offset,
const gfx::ScrollOffset& current_offset) {
scoped_ptr<ScrollOffsetAnimationCurve> curve =
std::unique_ptr<ScrollOffsetAnimationCurve> curve =
ScrollOffsetAnimationCurve::Create(
target_offset, EaseInOutTimingFunction::Create(),
ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA);
curve->SetInitialValue(current_offset);

scoped_ptr<Animation> animation = Animation::Create(
std::unique_ptr<Animation> animation = Animation::Create(
std::move(curve), AnimationIdProvider::NextAnimationId(),
AnimationIdProvider::NextGroupId(), TargetProperty::SCROLL_OFFSET);
animation->set_is_impl_only(true);
Expand Down Expand Up @@ -121,7 +122,8 @@ class AnimationHost::ScrollOffsetAnimations : public AnimationDelegate {
void NotifyAnimationTakeover(base::TimeTicks monotonic_time,
TargetProperty::Type target_property,
double animation_start_time,
scoped_ptr<AnimationCurve> curve) override {}
std::unique_ptr<AnimationCurve> curve) override {
}

private:
void ReattachScrollOffsetPlayerIfNeeded(int layer_id) {
Expand All @@ -144,9 +146,9 @@ class AnimationHost::ScrollOffsetAnimations : public AnimationDelegate {
DISALLOW_COPY_AND_ASSIGN(ScrollOffsetAnimations);
};

scoped_ptr<AnimationHost> AnimationHost::Create(
std::unique_ptr<AnimationHost> AnimationHost::Create(
ThreadInstance thread_instance) {
return make_scoped_ptr(new AnimationHost(thread_instance));
return base::WrapUnique(new AnimationHost(thread_instance));
}

AnimationHost::AnimationHost(ThreadInstance thread_instance)
Expand All @@ -155,7 +157,7 @@ AnimationHost::AnimationHost(ThreadInstance thread_instance)
thread_instance_(thread_instance) {
if (thread_instance_ == ThreadInstance::IMPL)
scroll_offset_animations_ =
make_scoped_ptr(new ScrollOffsetAnimations(this));
base::WrapUnique(new ScrollOffsetAnimations(this));
}

AnimationHost::~AnimationHost() {
Expand Down Expand Up @@ -367,11 +369,12 @@ bool AnimationHost::UpdateAnimationState(bool start_ready_animations,
events);
}

scoped_ptr<AnimationEvents> AnimationHost::CreateEvents() {
std::unique_ptr<AnimationEvents> AnimationHost::CreateEvents() {
return animation_registrar_->CreateEvents();
}

void AnimationHost::SetAnimationEvents(scoped_ptr<AnimationEvents> events) {
void AnimationHost::SetAnimationEvents(
std::unique_ptr<AnimationEvents> events) {
return animation_registrar_->SetAnimationEvents(std::move(events));
}

Expand Down
14 changes: 7 additions & 7 deletions cc/animation/animation_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#ifndef CC_ANIMATION_ANIMATION_HOST_H_
#define CC_ANIMATION_ANIMATION_HOST_H_

#include <memory>
#include <unordered_map>

#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "cc/animation/animation.h"
#include "cc/base/cc_export.h"
Expand Down Expand Up @@ -45,7 +45,7 @@ enum class ThreadInstance { MAIN, IMPL };
// we want to merge AnimationRegistrar into AnimationHost.
class CC_EXPORT AnimationHost {
public:
static scoped_ptr<AnimationHost> Create(ThreadInstance thread_instance);
static std::unique_ptr<AnimationHost> Create(ThreadInstance thread_instance);
virtual ~AnimationHost();

void AddAnimationTimeline(scoped_refptr<AnimationTimeline> timeline);
Expand Down Expand Up @@ -90,8 +90,8 @@ class CC_EXPORT AnimationHost {
bool UpdateAnimationState(bool start_ready_animations,
AnimationEvents* events);

scoped_ptr<AnimationEvents> CreateEvents();
void SetAnimationEvents(scoped_ptr<AnimationEvents> events);
std::unique_ptr<AnimationEvents> CreateEvents();
void SetAnimationEvents(std::unique_ptr<AnimationEvents> events);

bool ScrollOffsetAnimationWasInterrupted(int layer_id) const;

Expand Down Expand Up @@ -164,19 +164,19 @@ class CC_EXPORT AnimationHost {
// if they are attached to the same element(layer). Note that Element can
// contain many Layers.
using LayerToElementAnimationsMap =
std::unordered_map<int, scoped_ptr<ElementAnimations>>;
std::unordered_map<int, std::unique_ptr<ElementAnimations>>;
LayerToElementAnimationsMap layer_to_element_animations_map_;

// A list of all timelines which this host owns.
using IdToTimelineMap =
std::unordered_map<int, scoped_refptr<AnimationTimeline>>;
IdToTimelineMap id_to_timeline_map_;

scoped_ptr<AnimationRegistrar> animation_registrar_;
std::unique_ptr<AnimationRegistrar> animation_registrar_;
MutatorHostClient* mutator_host_client_;

class ScrollOffsetAnimations;
scoped_ptr<ScrollOffsetAnimations> scroll_offset_animations_;
std::unique_ptr<ScrollOffsetAnimations> scroll_offset_animations_;

const ThreadInstance thread_instance_;

Expand Down
2 changes: 1 addition & 1 deletion cc/animation/animation_host_perftest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class AnimationHostPerfTest : public testing::Test {
}

protected:
scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
std::unique_ptr<FakeLayerTreeHost> layer_tree_host_;
scoped_refptr<Layer> root_layer_;
LayerImpl* root_layer_impl_;

Expand Down
10 changes: 6 additions & 4 deletions cc/animation/animation_host_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ class AnimationHostTest : public AnimationTimelinesTest {
// animation_player_unittest.cc.

TEST_F(AnimationHostTest, SyncTimelinesAddRemove) {
scoped_ptr<AnimationHost> host(AnimationHost::Create(ThreadInstance::MAIN));
scoped_ptr<AnimationHost> host_impl(
std::unique_ptr<AnimationHost> host(
AnimationHost::Create(ThreadInstance::MAIN));
std::unique_ptr<AnimationHost> host_impl(
AnimationHost::Create(ThreadInstance::IMPL));

const int timeline_id = AnimationIdProvider::NextTimelineId();
Expand Down Expand Up @@ -56,8 +57,9 @@ TEST_F(AnimationHostTest, SyncTimelinesAddRemove) {
}

TEST_F(AnimationHostTest, ImplOnlyTimeline) {
scoped_ptr<AnimationHost> host(AnimationHost::Create(ThreadInstance::MAIN));
scoped_ptr<AnimationHost> host_impl(
std::unique_ptr<AnimationHost> host(
AnimationHost::Create(ThreadInstance::MAIN));
std::unique_ptr<AnimationHost> host_impl(
AnimationHost::Create(ThreadInstance::IMPL));

const int timeline_id1 = AnimationIdProvider::NextTimelineId();
Expand Down
Loading

0 comments on commit 60bc3bc

Please sign in to comment.