diff options
author | pavely <pavely@chromium.org> | 2015-01-16 09:20:41 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-16 17:21:40 +0000 |
commit | a8e369960cfab093ffffc9dc9f0066cca2b56812 (patch) | |
tree | 8f4d6d16ad9dfeb0af61aa47eea1ed0c53bc919b /sync | |
parent | 4bdbb054140fb4d84a767a8828159b5f5dbe8799 (diff) | |
download | chromium_src-a8e369960cfab093ffffc9dc9f0066cca2b56812.zip chromium_src-a8e369960cfab093ffffc9dc9f0066cca2b56812.tar.gz chromium_src-a8e369960cfab093ffffc9dc9f0066cca2b56812.tar.bz2 |
Don't DCHECK in AttachmentServiceProxyForTest when MessageLoop is absent
The code in AttachmentServiceProxyForTest::Create checks that
base::ThreadTaskRunnerHandle::Get() returns valid runner in the
incorrect way. Get() DCHECKs that there is valid MessageLoop.
Instead it should check ThreadTaskRunnerHandle::IsSet().
BUG=449327
R=maniscalco@chromium.org
Review URL: https://codereview.chromium.org/814273006
Cr-Commit-Position: refs/heads/master@{#311917}
Diffstat (limited to 'sync')
-rw-r--r-- | sync/api/attachments/attachment_store.cc | 17 | ||||
-rw-r--r-- | sync/internal_api/attachments/attachment_service_proxy_for_test.cc | 11 |
2 files changed, 19 insertions, 9 deletions
diff --git a/sync/api/attachments/attachment_store.cc b/sync/api/attachments/attachment_store.cc index 9b22c51..129ac0b5 100644 --- a/sync/api/attachments/attachment_store.cc +++ b/sync/api/attachments/attachment_store.cc @@ -7,6 +7,7 @@ #include "base/bind.h" #include "base/callback.h" #include "base/location.h" +#include "base/message_loop/message_loop.h" #include "base/sequenced_task_runner.h" #include "base/thread_task_runner_handle.h" #include "sync/internal_api/public/attachments/attachment_store_handle.h" @@ -23,10 +24,18 @@ AttachmentStore::~AttachmentStore() {} scoped_refptr<AttachmentStore> AttachmentStore::CreateInMemoryStore() { // Both frontend and backend of attachment store will live on current thread. - scoped_ptr<AttachmentStoreBase> backend( - new InMemoryAttachmentStore(base::ThreadTaskRunnerHandle::Get())); - return scoped_refptr<AttachmentStore>(new AttachmentStoreHandle( - backend.Pass(), base::ThreadTaskRunnerHandle::Get())); + scoped_refptr<base::SingleThreadTaskRunner> runner; + if (base::ThreadTaskRunnerHandle::IsSet()) { + runner = base::ThreadTaskRunnerHandle::Get(); + } else { + // Dummy runner for tests that don't have MessageLoop. + base::MessageLoop loop; + // This works because |runner| takes a ref to the proxy. + runner = base::ThreadTaskRunnerHandle::Get(); + } + scoped_ptr<AttachmentStoreBase> backend(new InMemoryAttachmentStore(runner)); + return scoped_refptr<AttachmentStore>( + new AttachmentStoreHandle(backend.Pass(), runner)); } scoped_refptr<AttachmentStore> AttachmentStore::CreateOnDiskStore( diff --git a/sync/internal_api/attachments/attachment_service_proxy_for_test.cc b/sync/internal_api/attachments/attachment_service_proxy_for_test.cc index 53f7d60..8682a91 100644 --- a/sync/internal_api/attachments/attachment_service_proxy_for_test.cc +++ b/sync/internal_api/attachments/attachment_service_proxy_for_test.cc @@ -38,14 +38,15 @@ AttachmentServiceProxy AttachmentServiceProxyForTest::Create() { scoped_refptr<Core> core_for_test( new OwningCore(wrapped.Pass(), weak_ptr_factory.Pass())); - scoped_refptr<base::SequencedTaskRunner> runner( - base::ThreadTaskRunnerHandle::Get()); - if (!runner.get()) { - // Dummy runner for tests that don't care about AttachmentServiceProxy. + scoped_refptr<base::SequencedTaskRunner> runner; + if (base::ThreadTaskRunnerHandle::IsSet()) { + runner = base::ThreadTaskRunnerHandle::Get(); + } else { + // Dummy runner for tests that don't have MessageLoop. DVLOG(1) << "Creating dummy MessageLoop for AttachmentServiceProxy."; base::MessageLoop loop; // This works because |runner| takes a ref to the proxy. - runner = loop.message_loop_proxy(); + runner = base::ThreadTaskRunnerHandle::Get(); } return AttachmentServiceProxyForTest(runner, core_for_test); } |