| Index: components/sync/model/attachments/attachment_service_proxy_unittest.cc
 | 
| diff --git a/components/sync/model/attachments/attachment_service_proxy_unittest.cc b/components/sync/model/attachments/attachment_service_proxy_unittest.cc
 | 
| index 61bcdf7e11b0c20d44df937bfffd0bc22c05a309..ae6d5ec346321591ef8870d51f26c86b57aa3a49 100644
 | 
| --- a/components/sync/model/attachments/attachment_service_proxy_unittest.cc
 | 
| +++ b/components/sync/model/attachments/attachment_service_proxy_unittest.cc
 | 
| @@ -8,6 +8,7 @@
 | 
|  
 | 
|  #include "base/bind.h"
 | 
|  #include "base/location.h"
 | 
| +#include "base/memory/ptr_util.h"
 | 
|  #include "base/memory/ref_counted_memory.h"
 | 
|  #include "base/run_loop.h"
 | 
|  #include "base/single_thread_task_runner.h"
 | 
| @@ -83,98 +84,102 @@ class AttachmentServiceProxyTest : public testing::Test,
 | 
|  
 | 
|    void SetUp() override {
 | 
|      CalledOnValidThread();
 | 
| -    stub_thread.reset(new base::Thread("attachment service stub thread"));
 | 
| -    stub_thread->Start();
 | 
| -    stub.reset(new StubAttachmentService);
 | 
| -    proxy.reset(new AttachmentServiceProxy(stub_thread->task_runner(),
 | 
| -                                           stub->AsWeakPtr()));
 | 
| -
 | 
| -    callback_get_or_download =
 | 
| +    stub_thread_ =
 | 
| +        base::MakeUnique<base::Thread>("attachment service stub thread");
 | 
| +    stub_thread_->Start();
 | 
| +    stub_ = base::MakeUnique<StubAttachmentService>();
 | 
| +    proxy_ = base::MakeUnique<AttachmentServiceProxy>(
 | 
| +        stub_thread_->task_runner(), stub_->AsWeakPtr());
 | 
| +
 | 
| +    callback_get_or_download_ =
 | 
|          base::Bind(&AttachmentServiceProxyTest::IncrementGetOrDownload,
 | 
|                     base::Unretained(this));
 | 
| -    count_callback_get_or_download = 0;
 | 
| +    count_callback_get_or_download_ = 0;
 | 
|    }
 | 
|  
 | 
|    void TearDown() override {
 | 
| -    // We must take care to call the stub's destructor on the stub_thread
 | 
| +    // We must take care to call the stub's destructor on the stub_thread_
 | 
|      // because that's the thread to which its WeakPtrs are bound.
 | 
| -    if (stub) {
 | 
| -      stub_thread->task_runner()->DeleteSoon(FROM_HERE, stub.release());
 | 
| +    if (stub_) {
 | 
| +      stub_thread_->task_runner()->DeleteSoon(FROM_HERE, stub_.release());
 | 
|        WaitForStubThread();
 | 
|      }
 | 
| -    stub_thread->Stop();
 | 
| +    stub_thread_->Stop();
 | 
|    }
 | 
|  
 | 
|    // a GetOrDownloadCallback
 | 
|    void IncrementGetOrDownload(const AttachmentService::GetOrDownloadResult&,
 | 
|                                std::unique_ptr<AttachmentMap>) {
 | 
|      CalledOnValidThread();
 | 
| -    ++count_callback_get_or_download;
 | 
| +    ++count_callback_get_or_download_;
 | 
|    }
 | 
|  
 | 
|    void WaitForStubThread() {
 | 
|      base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC,
 | 
|                               base::WaitableEvent::InitialState::NOT_SIGNALED);
 | 
| -    stub_thread->task_runner()->PostTask(
 | 
| +    stub_thread_->task_runner()->PostTask(
 | 
|          FROM_HERE,
 | 
|          base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
 | 
|      done.Wait();
 | 
|    }
 | 
|  
 | 
| -  base::MessageLoop loop;
 | 
| -  std::unique_ptr<base::Thread> stub_thread;
 | 
| -  std::unique_ptr<StubAttachmentService> stub;
 | 
| -  std::unique_ptr<AttachmentServiceProxy> proxy;
 | 
| +  base::MessageLoop loop_;
 | 
| +  std::unique_ptr<base::Thread> stub_thread_;
 | 
| +  std::unique_ptr<StubAttachmentService> stub_;
 | 
| +  std::unique_ptr<AttachmentServiceProxy> proxy_;
 | 
|  
 | 
| -  AttachmentService::GetOrDownloadCallback callback_get_or_download;
 | 
| +  AttachmentService::GetOrDownloadCallback callback_get_or_download_;
 | 
|  
 | 
| -  // number of times callback_get_or_download was invoked
 | 
| -  int count_callback_get_or_download;
 | 
| +  // number of times callback_get_or_download_ was invoked
 | 
| +  int count_callback_get_or_download_;
 | 
|  };
 | 
|  
 | 
|  // Verify that each of AttachmentServiceProxy's methods are invoked on the stub.
 | 
|  // Verify that the methods that take callbacks invoke passed callbacks on this
 | 
|  // thread.
 | 
|  TEST_F(AttachmentServiceProxyTest, MethodsAreProxied) {
 | 
| -  proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download);
 | 
| -  proxy->UploadAttachments(AttachmentIdList());
 | 
| +  proxy_->GetOrDownloadAttachments(AttachmentIdList(),
 | 
| +                                   callback_get_or_download_);
 | 
| +  proxy_->UploadAttachments(AttachmentIdList());
 | 
|    // Wait for the posted calls to execute in the stub thread.
 | 
|    WaitForStubThread();
 | 
| -  EXPECT_EQ(2, stub->GetCallCount());
 | 
| +  EXPECT_EQ(2, stub_->GetCallCount());
 | 
|    // At this point the stub thread has finished executed the calls. However, the
 | 
|    // result callbacks it has posted may not have executed yet. Wait a second
 | 
|    // time to ensure the stub thread has executed the posted result callbacks.
 | 
|    WaitForStubThread();
 | 
|  
 | 
|    base::RunLoop().RunUntilIdle();
 | 
| -  EXPECT_EQ(1, count_callback_get_or_download);
 | 
| +  EXPECT_EQ(1, count_callback_get_or_download_);
 | 
|  }
 | 
|  
 | 
|  // Verify that it's safe to use an AttachmentServiceProxy even after its wrapped
 | 
|  // AttachmentService has been destroyed.
 | 
|  TEST_F(AttachmentServiceProxyTest, WrappedIsDestroyed) {
 | 
| -  proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download);
 | 
| +  proxy_->GetOrDownloadAttachments(AttachmentIdList(),
 | 
| +                                   callback_get_or_download_);
 | 
|    // Wait for the posted calls to execute in the stub thread.
 | 
|    WaitForStubThread();
 | 
| -  EXPECT_EQ(1, stub->GetCallCount());
 | 
| +  EXPECT_EQ(1, stub_->GetCallCount());
 | 
|    // Wait a second time ensure the stub thread has executed the posted result
 | 
|    // callbacks.
 | 
|    WaitForStubThread();
 | 
|  
 | 
|    base::RunLoop().RunUntilIdle();
 | 
| -  EXPECT_EQ(1, count_callback_get_or_download);
 | 
| +  EXPECT_EQ(1, count_callback_get_or_download_);
 | 
|  
 | 
|    // Destroy the stub and call GetOrDownloadAttachments again.
 | 
| -  stub_thread->task_runner()->DeleteSoon(FROM_HERE, stub.release());
 | 
| +  stub_thread_->task_runner()->DeleteSoon(FROM_HERE, stub_.release());
 | 
|    WaitForStubThread();
 | 
|  
 | 
|    // Now that the wrapped object has been destroyed, call again and see that we
 | 
|    // don't crash and the count remains the same.
 | 
| -  proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download);
 | 
| +  proxy_->GetOrDownloadAttachments(AttachmentIdList(),
 | 
| +                                   callback_get_or_download_);
 | 
|    WaitForStubThread();
 | 
|    WaitForStubThread();
 | 
|    base::RunLoop().RunUntilIdle();
 | 
| -  EXPECT_EQ(1, count_callback_get_or_download);
 | 
| +  EXPECT_EQ(1, count_callback_get_or_download_);
 | 
|  }
 | 
|  
 | 
|  }  // namespace syncer
 | 
| 
 |