Skip to content

Commit ff953f4

Browse files
Noriyuki Takahashiyukawa
Noriyuki Takahashi
authored andcommitted
Deprecate scoped_ptr part 4.
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
1 parent 78faab4 commit ff953f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+332
-293
lines changed

src/android/jni/mozcjni.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@
3131

3232
#include <jni.h>
3333

34+
#include <memory>
35+
3436
#include "base/android_jni_proxy.h"
3537
#include "base/android_util.h"
3638
#include "base/scheduler.h"
37-
#include "base/scoped_ptr.h"
3839
#include "base/singleton.h"
3940
#include "base/system_util.h"
4041
#include "base/version.h"
@@ -69,8 +70,8 @@ class SessionHandlerSingletonAdapter {
6970

7071
private:
7172
// Must be defined earlier than session_handler_, which depends on this.
72-
scoped_ptr<EngineInterface> engine_;
73-
scoped_ptr<SessionHandlerInterface> session_handler_;
73+
std::unique_ptr<EngineInterface> engine_;
74+
std::unique_ptr<SessionHandlerInterface> session_handler_;
7475

7576
DISALLOW_COPY_AND_ASSIGN(SessionHandlerSingletonAdapter);
7677
};

src/base/android_jni_mock.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
// An utility to mock JNI releated stuff for testing purpose.
3434
#include <jni.h>
3535
#include <map>
36+
#include <memory>
3637
#include <utility>
3738

3839
#include "base/port.h"
39-
#include "base/scoped_ptr.h"
4040

4141
namespace mozc {
4242
namespace jni {
@@ -108,7 +108,7 @@ class MockJNIEnv {
108108
map<jbyteArray, pair<jsize, jbyte*> > byte_array_map_;
109109

110110
// Http client's mock injecting point.
111-
scoped_ptr<MockJavaHttpClient> mock_http_client_;
111+
std::unique_ptr<MockJavaHttpClient> mock_http_client_;
112112
_jclass mock_http_client_class_;
113113
MockJMethodId mock_request_;
114114

src/base/android_jni_proxy.cc

+8-4
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@
3131

3232
#include <jni.h>
3333

34+
#include <memory>
35+
3436
#include "base/logging.h"
3537
#include "base/mutex.h"
36-
#include "base/scoped_ptr.h"
3738
#include "net/http_client_common.h"
3839

3940
namespace {
@@ -129,7 +130,7 @@ bool CopyJByteArrayToBuf(JNIEnv *env, const jbyteArray &source,
129130
void AssignJByteArrayToString(JNIEnv *env, const jbyteArray &source,
130131
string *dest) {
131132
size_t size = env->GetArrayLength(source);
132-
scoped_ptr<char[]> buf(new char[size]);
133+
std::unique_ptr<char[]> buf(new char[size]);
133134
CHECK(CopyJByteArrayToBuf(env, source, buf.get(), &size));
134135
dest->assign(buf.get(), size);
135136
}
@@ -148,7 +149,8 @@ const char *HTTPMethodTypeToChars(mozc::HTTPMethodType type) {
148149
}
149150
}
150151

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

229231
DISALLOW_COPY_AND_ASSIGN(JavaHttpClientDescriptor);
230232
};
231-
scoped_ptr<JavaHttpClientDescriptor> http_client_descriptor;
233+
234+
std::unique_ptr<JavaHttpClientDescriptor> http_client_descriptor;
235+
232236
} // namespace
233237

234238
namespace mozc {

src/base/android_jni_proxy_test.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@
3636

3737
#include "base/android_jni_proxy.h"
3838

39+
#include <memory>
40+
3941
#include "base/android_jni_mock.h"
4042
#include "base/logging.h"
4143
#include "testing/base/public/gmock.h"
4244
#include "testing/base/public/gunit.h"
4345

4446
namespace mozc {
4547
namespace jni {
46-
4748
namespace {
4849

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

64-
scoped_ptr<MockJavaVM> jvm_;
65+
std::unique_ptr<MockJavaVM> jvm_;
6566
};
6667

6768
bool IsEqualByteArray(MockJNIEnv *env,

src/base/bitarray.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
#define MOZC_BASE_BITARRAY_H_
3232

3333
#include <cstring> // memset
34+
#include <memory>
3435

3536
#include "base/port.h"
36-
#include "base/scoped_ptr.h"
3737

3838
namespace mozc {
3939

@@ -86,7 +86,7 @@ class BitArray {
8686
}
8787

8888
private:
89-
scoped_ptr<uint32[]> array_;
89+
std::unique_ptr<uint32[]> array_;
9090
const size_t size_;
9191

9292
DISALLOW_COPY_AND_ASSIGN(BitArray);

src/base/codegen_bytearray_stream.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@
4343
#define MOZC_BASE_CODEGEN_BYTEARRAY_STREAM_H_
4444

4545
#include <algorithm>
46+
#include <memory>
4647
#include <ostream>
4748
#include <streambuf>
4849
#include <string>
4950

5051
#include "base/port.h"
51-
#include "base/scoped_ptr.h"
5252

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

284284
size_t internal_output_buffer_size_;
285-
scoped_ptr<char[]> internal_output_buffer_;
285+
std::unique_ptr<char[]> internal_output_buffer_;
286286

287287
std::basic_ostream<char> *output_stream_;
288288
codegenstream::StreamOwner own_output_stream_;

src/base/codegen_bytearray_stream_test.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
#include "base/codegen_bytearray_stream.h"
3939

40+
#include <memory>
4041
#include <sstream>
4142

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

86-
scoped_ptr<mozc::CodeGenByteArrayOutputStream> codegen_stream_;
87-
scoped_ptr<ostringstream> result_stream_;
87+
std::unique_ptr<mozc::CodeGenByteArrayOutputStream> codegen_stream_;
88+
std::unique_ptr<ostringstream> result_stream_;
8889
};
8990

9091
TEST_F(CodeGenByteArrayStreamTest, NoInput) {

src/base/config_file_stream_test.cc

+9-10
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,17 @@
2727
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2828
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929

30-
#include <stddef.h>
30+
#include <cstddef>
3131
#include <ios>
3232
#include <istream>
33+
#include <memory>
3334

3435
#include "base/config_file_stream.h"
3536
#include "base/file_util.h"
36-
#include "base/scoped_ptr.h"
3737
#include "base/system_util.h"
38+
#include "testing/base/public/googletest.h"
3839
#include "testing/base/public/gunit.h"
3940

40-
DECLARE_string(test_tmpdir);
41-
4241
namespace mozc {
4342

4443
namespace {
@@ -91,9 +90,9 @@ TEST_F(ConfigFileStreamTest, OnMemoryFiles) {
9190
ConfigFileStream::AtomicUpdate(kPath, kData);
9291

9392
{
94-
scoped_ptr<istream> ifs(ConfigFileStream::LegacyOpen(kPath));
93+
std::unique_ptr<istream> ifs(ConfigFileStream::LegacyOpen(kPath));
9594
ASSERT_NE(nullptr, ifs.get());
96-
scoped_ptr<char[]> buf(new char[kData.size() + 1]);
95+
std::unique_ptr<char[]> buf(new char[kData.size() + 1]);
9796
ifs->read(buf.get(), kData.size());
9897
buf.get()[kData.size()] = '\0';
9998
EXPECT_EQ(kData, buf.get());
@@ -103,7 +102,7 @@ TEST_F(ConfigFileStreamTest, OnMemoryFiles) {
103102
ConfigFileStream::ClearOnMemoryFiles();
104103

105104
{
106-
scoped_ptr<istream> ifs(ConfigFileStream::LegacyOpen(kPath));
105+
std::unique_ptr<istream> ifs(ConfigFileStream::LegacyOpen(kPath));
107106
ASSERT_NE(nullptr, ifs.get());
108107
EXPECT_TRUE(IsEof(ifs.get()));
109108
}
@@ -153,10 +152,10 @@ TEST_F(ConfigFileStreamTest, OpenReadBinary) {
153152
ASSERT_TRUE(FileUtil::FileExists(test_file_path));
154153

155154
{
156-
scoped_ptr<istream> ifs(ConfigFileStream::OpenReadBinary(
155+
std::unique_ptr<istream> ifs(ConfigFileStream::OpenReadBinary(
157156
"user://" + string(kTestFileName)));
158157
ASSERT_NE(nullptr, ifs.get());
159-
scoped_ptr<char[]> buf(new char[kBinaryDataSize]);
158+
std::unique_ptr<char[]> buf(new char[kBinaryDataSize]);
160159
ifs->read(buf.get(), kBinaryDataSize);
161160
// Check if all the data are loaded as binary mode.
162161
for (size_t i = 0; i < kBinaryDataSize; ++i) {
@@ -199,7 +198,7 @@ TEST_F(ConfigFileStreamTest, OpenReadText) {
199198
#undef TRAILING_CARRIAGE_RETURN
200199

201200
{
202-
scoped_ptr<istream> ifs(ConfigFileStream::OpenReadText(
201+
std::unique_ptr<istream> ifs(ConfigFileStream::OpenReadText(
203202
"user://" + string(kTestFileName)));
204203
ASSERT_NE(nullptr, ifs.get());
205204
string line;

src/base/cpu_stats_main.cc

+5-3
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929

3030
#include "base/cpu_stats.h"
3131

32-
#include <string>
3332
#include <iostream>
33+
#include <memory>
34+
#include <string>
35+
3436
#include "base/flags.h"
35-
#include "base/thread.h"
3637
#include "base/port.h"
38+
#include "base/thread.h"
3739
#include "base/util.h"
3840

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

63-
scoped_ptr<DummyThread[]> threads;
65+
std::unique_ptr<DummyThread[]> threads;
6466

6567
if (FLAGS_dummy_threads_size > 0) {
6668
threads.reset(new DummyThread[FLAGS_dummy_threads_size]);

src/base/encryptor.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
#include <string.h>
4040
#endif // platforms (OS_WIN, OS_MACOSX, ...)
4141

42+
#include <memory>
43+
4244
#include "base/logging.h"
4345
#include "base/password_manager.h"
4446
#include "base/unverified_aes256.h"
@@ -198,7 +200,7 @@ bool Encryptor::EncryptString(const Encryptor::Key &key, string *data) {
198200
return false;
199201
}
200202
size_t size = data->size();
201-
scoped_ptr<char[]> buf(new char[key.GetEncryptedSize(data->size())]);
203+
std::unique_ptr<char[]> buf(new char[key.GetEncryptedSize(data->size())]);
202204
memcpy(buf.get(), data->data(), data->size());
203205
if (!Encryptor::EncryptArray(key, buf.get(), &size)) {
204206
LOG(ERROR) << "EncryptArray() failed";
@@ -214,7 +216,7 @@ bool Encryptor::DecryptString(const Encryptor::Key &key, string *data) {
214216
return false;
215217
}
216218
size_t size = data->size();
217-
scoped_ptr<char[]> buf(new char[data->size()]);
219+
std::unique_ptr<char[]> buf(new char[data->size()]);
218220
memcpy(buf.get(), data->data(), data->size());
219221
if (!Encryptor::DecryptArray(key, buf.get(), &size)) {
220222
LOG(ERROR) << "DecryptArray() failed";

src/base/encryptor.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
3030
#ifndef MOZC_BASE_ENCRYPTOR_H_
3131
#define MOZC_BASE_ENCRYPTOR_H_
3232

33+
#include <memory>
3334
#include <string>
35+
3436
#include "base/port.h"
35-
#include "base/scoped_ptr.h"
3637

3738
namespace mozc {
3839

@@ -83,7 +84,7 @@ class Encryptor {
8384
~Key();
8485

8586
struct InternalData;
86-
scoped_ptr<InternalData> data_;
87+
std::unique_ptr<InternalData> data_;
8788
};
8889

8990
// Encrypt character buffer. set the size of character buffer

src/base/encryptor_test.cc

+5-4
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2828
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929

30+
#include <memory>
31+
3032
#include "base/encryptor.h"
3133
#include "base/password_manager.h"
3234
#include "base/system_util.h"
3335
#include "base/util.h"
3436
#include "testing/base/public/googletest.h"
3537
#include "testing/base/public/gunit.h"
3638

37-
DECLARE_string(test_tmpdir);
38-
3939
namespace mozc {
4040

4141
namespace {
@@ -192,7 +192,7 @@ TEST(EncryptorTest, EncryptBatch) {
192192
10000, 16000, 100000 };
193193

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

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

248248
for (size_t i = 0; i < arraysize(kSizeTable); ++i) {
249-
scoped_ptr<char[]> buf(new char[kSizeTable[i]]);
249+
std::unique_ptr<char[]> buf(new char[kSizeTable[i]]);
250250
Util::GetRandomSequence(buf.get(), kSizeTable[i]);
251251
string input(buf.get(), kSizeTable[i]);
252252
string output;
@@ -257,4 +257,5 @@ TEST(EncryptorTest, ProtectData) {
257257
EXPECT_EQ(result, input);
258258
}
259259
}
260+
260261
} // namespace mozc

src/base/mmap_test.cc

+4-5
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@
2929

3030
#include "base/mmap.h"
3131

32-
#include <string.h>
32+
#include <cstring>
33+
#include <memory>
3334

3435
#include "base/file_stream.h"
3536
#include "base/file_util.h"
36-
#include "base/scoped_ptr.h"
3737
#include "base/util.h"
38+
#include "testing/base/public/googletest.h"
3839
#include "testing/base/public/gunit.h"
3940

40-
DECLARE_string(test_tmpdir);
41-
4241
namespace mozc {
4342
namespace {
4443

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

5453
{

0 commit comments

Comments
 (0)