summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-13 02:17:52 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-13 02:17:52 +0000
commit69731106c2858255cc7ef38d0241ee94bfa63a93 (patch)
tree975aec0a022383d9aa3778bd54eebba1e71d7867 /chrome/browser/sync
parent44e621d061718eb36b814cda5e9fc466abb850f6 (diff)
downloadchromium_src-69731106c2858255cc7ef38d0241ee94bfa63a93.zip
chromium_src-69731106c2858255cc7ef38d0241ee94bfa63a93.tar.gz
chromium_src-69731106c2858255cc7ef38d0241ee94bfa63a93.tar.bz2
Added NetworkChangeNotifierIOThread, which will be used by the
sync/notifier threads to pass into NetworkChangeNotifierProxy. Refactored unit tests a bit. BUG=19784 TEST=unit tests Review URL: http://codereview.chromium.org/1987013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47112 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync')
-rw-r--r--chrome/browser/sync/net/network_change_notifier_io_thread.cc24
-rw-r--r--chrome/browser/sync/net/network_change_notifier_io_thread.h38
-rw-r--r--chrome/browser/sync/net/network_change_notifier_io_thread_unittest.cc80
3 files changed, 142 insertions, 0 deletions
diff --git a/chrome/browser/sync/net/network_change_notifier_io_thread.cc b/chrome/browser/sync/net/network_change_notifier_io_thread.cc
new file mode 100644
index 0000000..c2cd2b4
--- /dev/null
+++ b/chrome/browser/sync/net/network_change_notifier_io_thread.cc
@@ -0,0 +1,24 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/sync/net/network_change_notifier_io_thread.h"
+
+#include "base/logging.h"
+#include "chrome/browser/io_thread.h"
+
+NetworkChangeNotifierIOThread::NetworkChangeNotifierIOThread(
+ IOThread* io_thread) : io_thread_(io_thread) {
+ DCHECK(io_thread_);
+}
+
+NetworkChangeNotifierIOThread::~NetworkChangeNotifierIOThread() {}
+
+MessageLoop* NetworkChangeNotifierIOThread::GetMessageLoop() const {
+ return io_thread_->message_loop();
+}
+
+net::NetworkChangeNotifier*
+NetworkChangeNotifierIOThread::GetNetworkChangeNotifier() const {
+ return io_thread_->globals()->network_change_notifier.get();
+}
diff --git a/chrome/browser/sync/net/network_change_notifier_io_thread.h b/chrome/browser/sync/net/network_change_notifier_io_thread.h
new file mode 100644
index 0000000..c15156a
--- /dev/null
+++ b/chrome/browser/sync/net/network_change_notifier_io_thread.h
@@ -0,0 +1,38 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SYNC_NET_NETWORK_CHANGE_NOTIFIER_IO_THREAD_H_
+#define CHROME_BROWSER_SYNC_NET_NETWORK_CHANGE_NOTIFIER_IO_THREAD_H_
+
+// This is a simple NetworkChangeNotifierThread wrapper around an
+// IOThread and its NetworkChangeNotifier.
+
+#include "base/basictypes.h"
+#include "chrome/common/net/network_change_notifier_thread.h"
+
+class IOThread;
+class MessageLoop;
+
+class NetworkChangeNotifierIOThread
+ : public chrome_common_net::NetworkChangeNotifierThread {
+ public:
+ // Does not take ownership of |io_thread|. This instance must live
+ // no longer than |io_thread|.
+ explicit NetworkChangeNotifierIOThread(IOThread* io_thread);
+
+ virtual ~NetworkChangeNotifierIOThread();
+
+ // chrome_common_net::NetworkChangeNotifierThread implementation.
+
+ virtual MessageLoop* GetMessageLoop() const;
+
+ virtual net::NetworkChangeNotifier* GetNetworkChangeNotifier() const;
+
+ private:
+ IOThread* const io_thread_;
+
+ DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierIOThread);
+};
+
+#endif // CHROME_BROWSER_SYNC_NET_NETWORK_CHANGE_NOTIFIER_IO_THREAD_H_
diff --git a/chrome/browser/sync/net/network_change_notifier_io_thread_unittest.cc b/chrome/browser/sync/net/network_change_notifier_io_thread_unittest.cc
new file mode 100644
index 0000000..e2b4e91
--- /dev/null
+++ b/chrome/browser/sync/net/network_change_notifier_io_thread_unittest.cc
@@ -0,0 +1,80 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/sync/net/network_change_notifier_io_thread.h"
+
+#include "base/basictypes.h"
+#include "base/message_loop.h"
+#include "base/scoped_ptr.h"
+#include "base/task.h"
+#include "chrome/browser/io_thread.h"
+#include "chrome/common/net/thread_blocker.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+class NetworkChangeNotifierIOThreadTest : public testing::Test {
+ protected:
+ NetworkChangeNotifierIOThreadTest() {}
+
+ virtual ~NetworkChangeNotifierIOThreadTest() {}
+
+ virtual void SetUp() {
+ // We need to set the message loop type explicitly because
+ // IOThread doesn't do it for us and the Linux
+ // NetworkChangeNotifier expects it.
+ base::Thread::Options options;
+ options.message_loop_type = MessageLoop::TYPE_IO;
+ EXPECT_TRUE(io_thread_.StartWithOptions(options));
+ thread_blocker_.reset(new chrome_common_net::ThreadBlocker(&io_thread_));
+ thread_blocker_->Block();
+ network_change_notifier_io_thread_.reset(
+ new NetworkChangeNotifierIOThread(&io_thread_));
+ }
+
+ virtual void TearDown() {
+ network_change_notifier_io_thread_.reset();
+ // Nothing should be posted on |io_thread_| at this point;
+ // otherwise, it may try to access
+ // network_change_notifier_io_thread_, which now NULL
+ thread_blocker_->Unblock();
+ thread_blocker_.reset();
+ io_thread_.Stop();
+ }
+
+ IOThread io_thread_;
+ scoped_ptr<chrome_common_net::ThreadBlocker> thread_blocker_;
+ scoped_ptr<NetworkChangeNotifierIOThread>
+ network_change_notifier_io_thread_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierIOThreadTest);
+};
+
+void CompareNetworkChangeNotifiers(
+ IOThread* io_thread,
+ NetworkChangeNotifierIOThread* network_change_notifier_io_thread) {
+ EXPECT_EQ(network_change_notifier_io_thread->GetMessageLoop(),
+ MessageLoop::current());
+ EXPECT_EQ(io_thread->globals()->network_change_notifier.get(),
+ network_change_notifier_io_thread->GetNetworkChangeNotifier());
+}
+
+TEST_F(NetworkChangeNotifierIOThreadTest, Basic) {
+ EXPECT_EQ(io_thread_.message_loop(),
+ network_change_notifier_io_thread_->GetMessageLoop());
+ ASSERT_TRUE(
+ io_thread_.PostTask(ChromeThread::IO,
+ FROM_HERE,
+ NewRunnableFunction(
+ &CompareNetworkChangeNotifiers,
+ &io_thread_,
+ network_change_notifier_io_thread_.get())));
+ // Pump the thread to make sure the task we just posted is run
+ // before this test ends.
+ thread_blocker_->Unblock();
+ thread_blocker_->Block();
+}
+
+} // namespace