Skip to content

Commit

Permalink
Deprecate scoped_ptr part 4.
Browse files Browse the repository at this point in the history
With this CL, scoped_ptr is replaced with std::unique_ptr in the
following directories.
 - src/android/
 - src/base/
 - src/config/
 - src/data_manager/
 - src/dictionary/
 - src/ipc/
 - src/testing/

This is just a mechanical refactoring.  No behavior change is intended.

BUG=#219
TEST=unittest
REF_BUG=9164610
REF_CL=85302962,85303257,85303597,85305350,85305985,85306371,85309721,85312175,85315394
  • Loading branch information
Noriyuki Takahashi authored and yukawa committed Nov 3, 2015
1 parent 78faab4 commit ff953f4
Show file tree
Hide file tree
Showing 65 changed files with 332 additions and 293 deletions.
7 changes: 4 additions & 3 deletions src/android/jni/mozcjni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@

#include <jni.h>

#include <memory>

#include "base/android_jni_proxy.h"
#include "base/android_util.h"
#include "base/scheduler.h"
#include "base/scoped_ptr.h"
#include "base/singleton.h"
#include "base/system_util.h"
#include "base/version.h"
Expand Down Expand Up @@ -69,8 +70,8 @@ class SessionHandlerSingletonAdapter {

private:
// Must be defined earlier than session_handler_, which depends on this.
scoped_ptr<EngineInterface> engine_;
scoped_ptr<SessionHandlerInterface> session_handler_;
std::unique_ptr<EngineInterface> engine_;
std::unique_ptr<SessionHandlerInterface> session_handler_;

DISALLOW_COPY_AND_ASSIGN(SessionHandlerSingletonAdapter);
};
Expand Down
4 changes: 2 additions & 2 deletions src/base/android_jni_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
// An utility to mock JNI releated stuff for testing purpose.
#include <jni.h>
#include <map>
#include <memory>
#include <utility>

#include "base/port.h"
#include "base/scoped_ptr.h"

namespace mozc {
namespace jni {
Expand Down Expand Up @@ -108,7 +108,7 @@ class MockJNIEnv {
map<jbyteArray, pair<jsize, jbyte*> > byte_array_map_;

// Http client's mock injecting point.
scoped_ptr<MockJavaHttpClient> mock_http_client_;
std::unique_ptr<MockJavaHttpClient> mock_http_client_;
_jclass mock_http_client_class_;
MockJMethodId mock_request_;

Expand Down
12 changes: 8 additions & 4 deletions src/base/android_jni_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@

#include <jni.h>

#include <memory>

#include "base/logging.h"
#include "base/mutex.h"
#include "base/scoped_ptr.h"
#include "net/http_client_common.h"

namespace {
Expand Down Expand Up @@ -129,7 +130,7 @@ bool CopyJByteArrayToBuf(JNIEnv *env, const jbyteArray &source,
void AssignJByteArrayToString(JNIEnv *env, const jbyteArray &source,
string *dest) {
size_t size = env->GetArrayLength(source);
scoped_ptr<char[]> buf(new char[size]);
std::unique_ptr<char[]> buf(new char[size]);
CHECK(CopyJByteArrayToBuf(env, source, buf.get(), &size));
dest->assign(buf.get(), size);
}
Expand All @@ -148,7 +149,8 @@ const char *HTTPMethodTypeToChars(mozc::HTTPMethodType type) {
}
}

// Utility to enlarge the java's local frame, as RAII idiom, like scoped_ptr.
// Utility to enlarge the java's local frame, as RAII idiom, like
// std::unique_ptr.
class ScopedJavaLocalFrame {
public:
ScopedJavaLocalFrame(JNIEnv *env, jint capacity) : env_(env) {
Expand Down Expand Up @@ -228,7 +230,9 @@ class JavaHttpClientDescriptor {

DISALLOW_COPY_AND_ASSIGN(JavaHttpClientDescriptor);
};
scoped_ptr<JavaHttpClientDescriptor> http_client_descriptor;

std::unique_ptr<JavaHttpClientDescriptor> http_client_descriptor;

} // namespace

namespace mozc {
Expand Down
5 changes: 3 additions & 2 deletions src/base/android_jni_proxy_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@

#include "base/android_jni_proxy.h"

#include <memory>

#include "base/android_jni_mock.h"
#include "base/logging.h"
#include "testing/base/public/gmock.h"
#include "testing/base/public/gunit.h"

namespace mozc {
namespace jni {

namespace {

class MockJavaHttpClientImpl : public MockJavaHttpClient {
Expand All @@ -61,7 +62,7 @@ class AndroidJniProxyTest : public ::testing::Test {
jvm_.reset(NULL);
}

scoped_ptr<MockJavaVM> jvm_;
std::unique_ptr<MockJavaVM> jvm_;
};

bool IsEqualByteArray(MockJNIEnv *env,
Expand Down
4 changes: 2 additions & 2 deletions src/base/bitarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
#define MOZC_BASE_BITARRAY_H_

#include <cstring> // memset
#include <memory>

#include "base/port.h"
#include "base/scoped_ptr.h"

namespace mozc {

Expand Down Expand Up @@ -86,7 +86,7 @@ class BitArray {
}

private:
scoped_ptr<uint32[]> array_;
std::unique_ptr<uint32[]> array_;
const size_t size_;

DISALLOW_COPY_AND_ASSIGN(BitArray);
Expand Down
4 changes: 2 additions & 2 deletions src/base/codegen_bytearray_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
#define MOZC_BASE_CODEGEN_BYTEARRAY_STREAM_H_

#include <algorithm>
#include <memory>
#include <ostream>
#include <streambuf>
#include <string>

#include "base/port.h"
#include "base/scoped_ptr.h"

#ifdef OS_ANDROID
// This is used only for code generation, so shouldn't be used from android
Expand Down Expand Up @@ -282,7 +282,7 @@ class BasicCodeGenByteArrayStreamBuf : public std::streambuf {
#endif

size_t internal_output_buffer_size_;
scoped_ptr<char[]> internal_output_buffer_;
std::unique_ptr<char[]> internal_output_buffer_;

std::basic_ostream<char> *output_stream_;
codegenstream::StreamOwner own_output_stream_;
Expand Down
5 changes: 3 additions & 2 deletions src/base/codegen_bytearray_stream_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include "base/codegen_bytearray_stream.h"

#include <memory>
#include <sstream>

#include "base/port.h"
Expand Down Expand Up @@ -83,8 +84,8 @@ class CodeGenByteArrayStreamTest : public testing::Test {
return result_stream_->str();
}

scoped_ptr<mozc::CodeGenByteArrayOutputStream> codegen_stream_;
scoped_ptr<ostringstream> result_stream_;
std::unique_ptr<mozc::CodeGenByteArrayOutputStream> codegen_stream_;
std::unique_ptr<ostringstream> result_stream_;
};

TEST_F(CodeGenByteArrayStreamTest, NoInput) {
Expand Down
19 changes: 9 additions & 10 deletions src/base/config_file_stream_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,17 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <stddef.h>
#include <cstddef>
#include <ios>
#include <istream>
#include <memory>

#include "base/config_file_stream.h"
#include "base/file_util.h"
#include "base/scoped_ptr.h"
#include "base/system_util.h"
#include "testing/base/public/googletest.h"
#include "testing/base/public/gunit.h"

DECLARE_string(test_tmpdir);

namespace mozc {

namespace {
Expand Down Expand Up @@ -91,9 +90,9 @@ TEST_F(ConfigFileStreamTest, OnMemoryFiles) {
ConfigFileStream::AtomicUpdate(kPath, kData);

{
scoped_ptr<istream> ifs(ConfigFileStream::LegacyOpen(kPath));
std::unique_ptr<istream> ifs(ConfigFileStream::LegacyOpen(kPath));
ASSERT_NE(nullptr, ifs.get());
scoped_ptr<char[]> buf(new char[kData.size() + 1]);
std::unique_ptr<char[]> buf(new char[kData.size() + 1]);
ifs->read(buf.get(), kData.size());
buf.get()[kData.size()] = '\0';
EXPECT_EQ(kData, buf.get());
Expand All @@ -103,7 +102,7 @@ TEST_F(ConfigFileStreamTest, OnMemoryFiles) {
ConfigFileStream::ClearOnMemoryFiles();

{
scoped_ptr<istream> ifs(ConfigFileStream::LegacyOpen(kPath));
std::unique_ptr<istream> ifs(ConfigFileStream::LegacyOpen(kPath));
ASSERT_NE(nullptr, ifs.get());
EXPECT_TRUE(IsEof(ifs.get()));
}
Expand Down Expand Up @@ -153,10 +152,10 @@ TEST_F(ConfigFileStreamTest, OpenReadBinary) {
ASSERT_TRUE(FileUtil::FileExists(test_file_path));

{
scoped_ptr<istream> ifs(ConfigFileStream::OpenReadBinary(
std::unique_ptr<istream> ifs(ConfigFileStream::OpenReadBinary(
"user://" + string(kTestFileName)));
ASSERT_NE(nullptr, ifs.get());
scoped_ptr<char[]> buf(new char[kBinaryDataSize]);
std::unique_ptr<char[]> buf(new char[kBinaryDataSize]);
ifs->read(buf.get(), kBinaryDataSize);
// Check if all the data are loaded as binary mode.
for (size_t i = 0; i < kBinaryDataSize; ++i) {
Expand Down Expand Up @@ -199,7 +198,7 @@ TEST_F(ConfigFileStreamTest, OpenReadText) {
#undef TRAILING_CARRIAGE_RETURN

{
scoped_ptr<istream> ifs(ConfigFileStream::OpenReadText(
std::unique_ptr<istream> ifs(ConfigFileStream::OpenReadText(
"user://" + string(kTestFileName)));
ASSERT_NE(nullptr, ifs.get());
string line;
Expand Down
8 changes: 5 additions & 3 deletions src/base/cpu_stats_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@

#include "base/cpu_stats.h"

#include <string>
#include <iostream>
#include <memory>
#include <string>

#include "base/flags.h"
#include "base/thread.h"
#include "base/port.h"
#include "base/thread.h"
#include "base/util.h"

DEFINE_int32(iterations, 1000, "number of iterations");
Expand All @@ -60,7 +62,7 @@ class DummyThread : public mozc::Thread {
int main(int argc, char **argv) {
InitGoogle(argv[0], &argc, &argv, false);

scoped_ptr<DummyThread[]> threads;
std::unique_ptr<DummyThread[]> threads;

if (FLAGS_dummy_threads_size > 0) {
threads.reset(new DummyThread[FLAGS_dummy_threads_size]);
Expand Down
6 changes: 4 additions & 2 deletions src/base/encryptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include <string.h>
#endif // platforms (OS_WIN, OS_MACOSX, ...)

#include <memory>

#include "base/logging.h"
#include "base/password_manager.h"
#include "base/unverified_aes256.h"
Expand Down Expand Up @@ -198,7 +200,7 @@ bool Encryptor::EncryptString(const Encryptor::Key &key, string *data) {
return false;
}
size_t size = data->size();
scoped_ptr<char[]> buf(new char[key.GetEncryptedSize(data->size())]);
std::unique_ptr<char[]> buf(new char[key.GetEncryptedSize(data->size())]);
memcpy(buf.get(), data->data(), data->size());
if (!Encryptor::EncryptArray(key, buf.get(), &size)) {
LOG(ERROR) << "EncryptArray() failed";
Expand All @@ -214,7 +216,7 @@ bool Encryptor::DecryptString(const Encryptor::Key &key, string *data) {
return false;
}
size_t size = data->size();
scoped_ptr<char[]> buf(new char[data->size()]);
std::unique_ptr<char[]> buf(new char[data->size()]);
memcpy(buf.get(), data->data(), data->size());
if (!Encryptor::DecryptArray(key, buf.get(), &size)) {
LOG(ERROR) << "DecryptArray() failed";
Expand Down
5 changes: 3 additions & 2 deletions src/base/encryptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
#ifndef MOZC_BASE_ENCRYPTOR_H_
#define MOZC_BASE_ENCRYPTOR_H_

#include <memory>
#include <string>

#include "base/port.h"
#include "base/scoped_ptr.h"

namespace mozc {

Expand Down Expand Up @@ -83,7 +84,7 @@ class Encryptor {
~Key();

struct InternalData;
scoped_ptr<InternalData> data_;
std::unique_ptr<InternalData> data_;
};

// Encrypt character buffer. set the size of character buffer
Expand Down
9 changes: 5 additions & 4 deletions src/base/encryptor_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <memory>

#include "base/encryptor.h"
#include "base/password_manager.h"
#include "base/system_util.h"
#include "base/util.h"
#include "testing/base/public/googletest.h"
#include "testing/base/public/gunit.h"

DECLARE_string(test_tmpdir);

namespace mozc {

namespace {
Expand Down Expand Up @@ -192,7 +192,7 @@ TEST(EncryptorTest, EncryptBatch) {
10000, 16000, 100000 };

for (size_t i = 0; i < arraysize(kSizeTable); ++i) {
scoped_ptr<char[]> buf(new char[kSizeTable[i]]);
std::unique_ptr<char[]> buf(new char[kSizeTable[i]]);
Util::GetRandomSequence(buf.get(), kSizeTable[i]);

Encryptor::Key key1, key2, key3, key4;
Expand Down Expand Up @@ -246,7 +246,7 @@ TEST(EncryptorTest, ProtectData) {
const size_t kSizeTable[] = { 1, 10, 100, 1000, 10000, 100000 };

for (size_t i = 0; i < arraysize(kSizeTable); ++i) {
scoped_ptr<char[]> buf(new char[kSizeTable[i]]);
std::unique_ptr<char[]> buf(new char[kSizeTable[i]]);
Util::GetRandomSequence(buf.get(), kSizeTable[i]);
string input(buf.get(), kSizeTable[i]);
string output;
Expand All @@ -257,4 +257,5 @@ TEST(EncryptorTest, ProtectData) {
EXPECT_EQ(result, input);
}
}

} // namespace mozc
9 changes: 4 additions & 5 deletions src/base/mmap_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@

#include "base/mmap.h"

#include <string.h>
#include <cstring>
#include <memory>

#include "base/file_stream.h"
#include "base/file_util.h"
#include "base/scoped_ptr.h"
#include "base/util.h"
#include "testing/base/public/googletest.h"
#include "testing/base/public/gunit.h"

DECLARE_string(test_tmpdir);

namespace mozc {
namespace {

Expand All @@ -48,7 +47,7 @@ TEST(MmapTest, MmapTest) {
const size_t kFileNameSize[] = { 1, 100, 1024, 8192 };
for (int i = 0; i < arraysize(kFileNameSize); ++i) {
FileUtil::Unlink(filename);
scoped_ptr<char[]> buf(new char[kFileNameSize[i]]);
std::unique_ptr<char[]> buf(new char[kFileNameSize[i]]);
memset(buf.get(), 0, kFileNameSize[i]);

{
Expand Down
Loading

0 comments on commit ff953f4

Please sign in to comment.