diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-29 03:07:52 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-29 03:07:52 +0000 |
commit | be06d67c4742c12b2ad98bcfd7e0dbc74b627075 (patch) | |
tree | 8ea299a009a72a9520555f3f09f421f6974bb6d9 | |
parent | 2094f18805eb060a1603dfe5b4523ac2a44a4529 (diff) | |
download | chromium_src-be06d67c4742c12b2ad98bcfd7e0dbc74b627075.zip chromium_src-be06d67c4742c12b2ad98bcfd7e0dbc74b627075.tar.gz chromium_src-be06d67c4742c12b2ad98bcfd7e0dbc74b627075.tar.bz2 |
base::Bind: Convert the following files.
* automation_provider_win.cc
* chrome_browser_main.cc
* web_socket_proxy_controller.cc
* cookie_policy_browsertest.cc
* profile_sync_service_autofill_unittest.cc
BUG=none
TEST=none
R=csilv@chromium.org
Review URL: http://codereview.chromium.org/8727018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111850 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/automation/automation_provider_win.cc | 101 | ||||
-rw-r--r-- | chrome/browser/chrome_browser_main.cc | 15 | ||||
-rw-r--r-- | chrome/browser/chromeos/web_socket_proxy_controller.cc | 70 | ||||
-rw-r--r-- | chrome/browser/net/cookie_policy_browsertest.cc | 55 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_service_autofill_unittest.cc | 49 | ||||
-rw-r--r-- | net/base/cookie_store.h | 4 |
6 files changed, 106 insertions, 188 deletions
diff --git a/chrome/browser/automation/automation_provider_win.cc b/chrome/browser/automation/automation_provider_win.cc index 189ebef..999ae50 100644 --- a/chrome/browser/automation/automation_provider_win.cc +++ b/chrome/browser/automation/automation_provider_win.cc @@ -30,14 +30,16 @@ #include "ui/views/focus/accelerator_handler.h" #include "ui/views/widget/root_view.h" -// This task just adds another task to the event queue. This is useful if -// you want to ensure that any tasks added to the event queue after this one -// have already been processed by the time |task| is run. -void InvokeTaskLater(Task* task) { - MessageLoop::current()->PostTask(FROM_HERE, task); +namespace { + +// This callback just adds another callback to the event queue. This is useful +// if you want to ensure that any callbacks added to the event queue after this +// one have already been processed by the time |callback| is run. +void InvokeCallbackLater(const base::Closure& callbck) { + MessageLoop::current()->PostTask(FROM_HERE, callback); } -static void MoveMouse(const POINT& point) { +void MoveMouse(const POINT& point) { SetCursorPos(point.x, point.y); // Now, make sure that GetMessagePos returns the values we just set by @@ -64,78 +66,18 @@ BOOL CALLBACK EnumThreadWndProc(HWND hwnd, LPARAM l_param) { return TRUE; } -// This task enqueues a mouse event on the event loop, so that the view -// that it's being sent to can do the requisite post-processing. -class MouseEventTask : public Task { - public: - MouseEventTask(views::View* view, - ui::EventType type, - const gfx::Point& point, - int flags) - : view_(view), type_(type), point_(point), flags_(flags) {} - virtual ~MouseEventTask() {} - - virtual void Run() { - views::MouseEvent event(type_, point_.x(), point_.y(), flags_); - // We need to set the cursor position before we process the event because - // some code (tab dragging, for instance) queries the actual cursor location - // rather than the location of the mouse event. Note that the reason why - // the drag code moved away from using mouse event locations was because - // our conversion to screen location doesn't work well with multiple - // monitors, so this only works reliably in a single monitor setup. - gfx::Point screen_location(point_.x(), point_.y()); - view_->ConvertPointToScreen(view_, &screen_location); - MoveMouse(screen_location.ToPOINT()); - switch (type_) { - case ui::ET_MOUSE_PRESSED: - view_->OnMousePressed(event); - break; - - case ui::ET_MOUSE_DRAGGED: - view_->OnMouseDragged(event); - break; - - case ui::ET_MOUSE_RELEASED: - view_->OnMouseReleased(event); - break; - - default: - NOTREACHED(); - } - } - - private: - views::View* view_; - ui::EventType type_; - gfx::Point point_; - int flags_; - - DISALLOW_COPY_AND_ASSIGN(MouseEventTask); -}; - -// This task sends a WindowDragResponse message with the appropriate -// routing ID to the automation proxy. This is implemented as a task so that -// we know that the mouse events (and any tasks that they spawn on the message -// loop) have been processed by the time this is sent. -class WindowDragResponseTask : public Task { - public: - WindowDragResponseTask(AutomationProvider* provider, - IPC::Message* reply_message) - : provider_(provider), reply_message_(reply_message) {} - virtual ~WindowDragResponseTask() {} - - virtual void Run() { - DCHECK(reply_message_ != NULL); - AutomationMsg_WindowDrag::WriteReplyParams(reply_message_, true); - provider_->Send(reply_message_); - } - - private: - AutomationProvider* provider_; - IPC::Message* reply_message_; +// This callback sends a WindowDragResponse message with the appropriate routing +// ID to the automation proxy. This is implemented as a task so that we know +// that the mouse events (and any tasks that they spawn on the message loop) +// have been processed by the time this is sent. +void WindowDragResponseCallback(AutomationProvider* provider, + IPC::Message* reply_message) { + DCHECK(reply_message != NULL); + AutomationMsg_WindowDrag::WriteReplyParams(reply_message, true); + provider->Send(reply_message); +} - DISALLOW_COPY_AND_ASSIGN(WindowDragResponseTask); -}; +} // namespace void AutomationProvider::WindowSimulateDrag( int handle, @@ -213,8 +155,9 @@ void AutomationProvider::WindowSimulateDrag( MAKELPARAM(end.x, end.y)); MessageLoop::current()->PostTask( - FROM_HERE, base::Bind(&InvokeTaskLater, - new WindowDragResponseTask(this, reply_message))); + FROM_HERE, base::Bind( + &InvokeCallbackLater, + base::Bind(&WindowDragResponseCallback, this, reply_message))); } else { AutomationMsg_WindowDrag::WriteReplyParams(reply_message, false); Send(reply_message); diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc index 86619e3..aa0584e 100644 --- a/chrome/browser/chrome_browser_main.cc +++ b/chrome/browser/chrome_browser_main.cc @@ -245,16 +245,9 @@ void AddFirstRunNewTabs(BrowserInit* browser_init, } #if defined(USE_LINUX_BREAKPAD) -class GetLinuxDistroTask : public Task { - public: - explicit GetLinuxDistroTask() {} - - virtual void Run() { - base::GetLinuxDistro(); // Initialize base::linux_distro if needed. - } - - DISALLOW_COPY_AND_ASSIGN(GetLinuxDistroTask); -}; +void GetLinuxDistroCallback() { + base::GetLinuxDistro(); // Initialize base::linux_distro if needed. +} #endif // USE_LINUX_BREAKPAD void InitializeNetworkOptions(const CommandLine& parsed_command_line) { @@ -1220,7 +1213,7 @@ void ChromeBrowserMainParts::PostStartThread( // Needs to be called after we have chrome::DIR_USER_DATA and // g_browser_process. This happens in PreCreateThreads. g_browser_process->file_thread()->message_loop()->PostTask( - FROM_HERE, new GetLinuxDistroTask()); + FROM_HERE, base::Bind(&GetLinuxDistroCallback)); if (IsCrashReportingEnabled(local_state_)) InitCrashReporter(); diff --git a/chrome/browser/chromeos/web_socket_proxy_controller.cc b/chrome/browser/chromeos/web_socket_proxy_controller.cc index c431b7f..a9faa56 100644 --- a/chrome/browser/chromeos/web_socket_proxy_controller.cc +++ b/chrome/browser/chromeos/web_socket_proxy_controller.cc @@ -10,6 +10,8 @@ #include <sys/wait.h> #include <unistd.h> +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/command_line.h" #include "base/lazy_instance.h" #include "base/message_loop.h" @@ -98,10 +100,6 @@ class OriginValidator { base::LazyInstance<OriginValidator> g_validator = LAZY_INSTANCE_INITIALIZER; -class ProxyTask : public Task { - virtual void Run() OVERRIDE; -}; - class ProxyLifetime : public net::NetworkChangeNotifier::OnlineStateObserver, public content::NotificationObserver { @@ -109,7 +107,8 @@ class ProxyLifetime ProxyLifetime() : delay_ms_(1000), port_(-1), shutdown_requested_(false) { DLOG(INFO) << "WebSocketProxyController initiation"; BrowserThread::PostTask( - BrowserThread::WEB_SOCKET_PROXY, FROM_HERE, new ProxyTask()); + BrowserThread::WEB_SOCKET_PROXY, FROM_HERE, + base::Bind(&ProxyLifetime::ProxyCallback, base::Unretained(this))); net::NetworkChangeNotifier::AddOnlineStateObserver(this); registrar_.Add( this, chrome::NOTIFICATION_WEB_SOCKET_PROXY_STARTED, @@ -132,7 +131,7 @@ class ProxyLifetime } private: - // net::NetworkChangeNotifier::OnlineStateObserver overrides. + // net::NetworkChangeNotifier::OnlineStateObserver implementation. virtual void OnOnlineStateChanged(bool online) OVERRIDE { DCHECK(chromeos::WebSocketProxyController::IsInitiated()); base::AutoLock alk(lock_); @@ -140,6 +139,36 @@ class ProxyLifetime server_->OnNetworkChange(); } + void ProxyCallback() { + LOG(INFO) << "Attempt to run web socket proxy task"; + chromeos::WebSocketProxy* server = new chromeos::WebSocketProxy( + g_validator.Get().allowed_origins()); + { + base::AutoLock alk(lock_); + if (shutdown_requested_) + return; + delete server_; + server_ = server; + } + server->Run(); + { + base::AutoLock alk(lock_); + delete server; + server_ = NULL; + if (!shutdown_requested_) { + // Proxy terminated unexpectedly or failed to start (it can happen due + // to a network problem). Keep trying. + if (delay_ms_ < 100 * 1000) + (delay_ms_ *= 3) /= 2; + + BrowserThread::PostDelayedTask( + BrowserThread::WEB_SOCKET_PROXY, FROM_HERE, + base::Bind(&ProxyLifetime::ProxyCallback, base::Unretained(this)), + delay_ms_); + } + } + } + // Delay between next attempt to run proxy. int volatile delay_ms_; @@ -150,40 +179,11 @@ class ProxyLifetime volatile bool shutdown_requested_; base::Lock lock_; content::NotificationRegistrar registrar_; - friend class ProxyTask; friend class chromeos::WebSocketProxyController; }; base::LazyInstance<ProxyLifetime> g_proxy_lifetime = LAZY_INSTANCE_INITIALIZER; -void ProxyTask::Run() { - LOG(INFO) << "Attempt to run web socket proxy task"; - chromeos::WebSocketProxy* server = new chromeos::WebSocketProxy( - g_validator.Get().allowed_origins()); - { - base::AutoLock alk(g_proxy_lifetime.Get().lock_); - if (g_proxy_lifetime.Get().shutdown_requested_) - return; - delete g_proxy_lifetime.Get().server_; - g_proxy_lifetime.Get().server_ = server; - } - server->Run(); - { - base::AutoLock alk(g_proxy_lifetime.Get().lock_); - delete server; - g_proxy_lifetime.Get().server_ = NULL; - if (!g_proxy_lifetime.Get().shutdown_requested_) { - // Proxy terminated unexpectedly or failed to start (it can happen due to - // a network problem). Keep trying. - if (g_proxy_lifetime.Get().delay_ms_ < 100 * 1000) - (g_proxy_lifetime.Get().delay_ms_ *= 3) /= 2; - BrowserThread::PostDelayedTask( - BrowserThread::WEB_SOCKET_PROXY, FROM_HERE, new ProxyTask(), - g_proxy_lifetime.Get().delay_ms_); - } - } -} - } // namespace namespace chromeos { diff --git a/chrome/browser/net/cookie_policy_browsertest.cc b/chrome/browser/net/cookie_policy_browsertest.cc index 4f3afac..ae8a3af 100644 --- a/chrome/browser/net/cookie_policy_browsertest.cc +++ b/chrome/browser/net/cookie_policy_browsertest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/bind.h" +#include "base/bind_helpers.h" #include "base/task.h" #include "base/synchronization/waitable_event.h" #include "chrome/browser/content_settings/host_content_settings_map.h" @@ -22,41 +23,24 @@ using content::BrowserThread; namespace { -class GetCookiesTask : public Task { - public: - GetCookiesTask(const GURL& url, - net::URLRequestContextGetter* context_getter, - base::WaitableEvent* event, - std::string* cookies) - : url_(url), - context_getter_(context_getter), - event_(event), - cookies_(cookies) {} - - virtual void Run() { - net::CookieOptions options; - context_getter_->GetURLRequestContext()->cookie_store() - ->GetCookiesWithOptionsAsync( - url_, options, base::Bind(&GetCookiesTask::GetCookiesCallback, - base::Unretained(cookies_), - base::Unretained(event_))); - } - - static void GetCookiesCallback(std::string* cookies_out, - base::WaitableEvent* event, - const std::string& cookies) { - *cookies_out = cookies; - event->Signal(); - } - - private: - const GURL& url_; - net::URLRequestContextGetter* const context_getter_; - base::WaitableEvent* const event_; - std::string* const cookies_; +void GetCookiesCallback(std::string* cookies_out, + base::WaitableEvent* event, + const std::string& cookies) { + *cookies_out = cookies; + event->Signal(); +} - DISALLOW_COPY_AND_ASSIGN(GetCookiesTask); -}; +void GetCookiesOnIOThread(const GURL& url, + net::URLRequestContextGetter* context_getter, + base::WaitableEvent* event, + std::string* cookies) { + net::CookieStore* cookie_store = + context_getter->GetURLRequestContext()->cookie_store(); + cookie_store->GetCookiesWithOptionsAsync( + url, net::CookieOptions(), + base::Bind(&GetCookiesCallback, + base::Unretained(cookies), base::Unretained(event))); +} class CookiePolicyBrowserTest : public InProcessBrowserTest { protected: @@ -71,7 +55,8 @@ class CookiePolicyBrowserTest : public InProcessBrowserTest { EXPECT_TRUE( BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, - new GetCookiesTask(url, context_getter, &event, &cookies))); + base::Bind(&GetCookiesOnIOThread, url, + make_scoped_refptr(context_getter), &event, &cookies))); event.Wait(); return cookies; } diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc index 153f104..da9b322 100644 --- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc @@ -125,7 +125,7 @@ class WebDatabaseFake : public WebDatabase { explicit WebDatabaseFake(AutofillTable* autofill_table) : autofill_table_(autofill_table) {} - virtual AutofillTable* GetAutofillTable() { + virtual AutofillTable* GetAutofillTable() OVERRIDE { return autofill_table_; } @@ -176,11 +176,11 @@ class WebDataServiceFake : public WebDataService { syncable_service_created_or_destroyed_.Wait(); } - virtual bool IsDatabaseLoaded() { + virtual bool IsDatabaseLoaded() OVERRIDE { return true; } - virtual WebDatabase* GetDatabase() { + virtual WebDatabase* GetDatabase() OVERRIDE { return web_database_; } @@ -264,17 +264,17 @@ class AbstractAutofillFactory { class AutofillEntryFactory : public AbstractAutofillFactory { public: - browser_sync::DataTypeController* CreateDataTypeController( + virtual browser_sync::DataTypeController* CreateDataTypeController( ProfileSyncComponentsFactory* factory, ProfileMock* profile, - ProfileSyncService* service) { + ProfileSyncService* service) OVERRIDE { return new AutofillDataTypeController(factory, profile); } - void SetExpectation(ProfileSyncComponentsFactoryMock* factory, - ProfileSyncService* service, - WebDataService* wds, - DataTypeController* dtc) { + virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory, + ProfileSyncService* service, + WebDataService* wds, + DataTypeController* dtc) OVERRIDE { EXPECT_CALL(*factory, CreateGenericChangeProcessor(_,_,_)). WillOnce(MakeGenericChangeProcessor()); EXPECT_CALL(*factory, CreateSharedChangeProcessor()). @@ -286,17 +286,17 @@ class AutofillEntryFactory : public AbstractAutofillFactory { class AutofillProfileFactory : public AbstractAutofillFactory { public: - browser_sync::DataTypeController* CreateDataTypeController( + virtual browser_sync::DataTypeController* CreateDataTypeController( ProfileSyncComponentsFactory* factory, ProfileMock* profile, - ProfileSyncService* service) { + ProfileSyncService* service) OVERRIDE { return new AutofillProfileDataTypeController(factory, profile); } - void SetExpectation(ProfileSyncComponentsFactoryMock* factory, - ProfileSyncService* service, - WebDataService* wds, - DataTypeController* dtc) { + virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory, + ProfileSyncService* service, + WebDataService* wds, + DataTypeController* dtc) OVERRIDE { EXPECT_CALL(*factory, CreateGenericChangeProcessor(_,_,_)). WillOnce(MakeGenericChangeProcessor()); EXPECT_CALL(*factory, CreateSharedChangeProcessor()). @@ -338,7 +338,7 @@ class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest { } } - virtual void SetUp() { + virtual void SetUp() OVERRIDE { AbstractProfileSyncServiceTest::SetUp(); profile_.CreateRequestContext(); web_database_.reset(new WebDatabaseFake(&autofill_table_)); @@ -364,7 +364,7 @@ class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest { web_data_service_->StartSyncableService(); } - virtual void TearDown() { + virtual void TearDown() OVERRIDE { // Note: The tear down order is important. service_.reset(); web_data_service_->ShutdownSyncableService(); @@ -582,7 +582,6 @@ class AddAutofillHelper { }; // Overload write transaction to use custom NotifyTransactionComplete -static const bool kLoggingInfo = true; class WriteTransactionTest: public WriteTransaction { public: WriteTransactionTest(const tracked_objects::Location& from_here, @@ -592,7 +591,8 @@ class WriteTransactionTest: public WriteTransaction { : WriteTransaction(from_here, writer, directory), wait_for_syncapi_(wait_for_syncapi) { } - virtual void NotifyTransactionComplete(syncable::ModelTypeBitSet types) { + virtual void NotifyTransactionComplete( + syncable::ModelTypeBitSet types) OVERRIDE { // This is where we differ. Force a thread change here, giving another // thread a chance to create a WriteTransaction (*wait_for_syncapi_)->Wait(); @@ -626,7 +626,7 @@ class FakeServerUpdater : public base::RefCountedThreadSafe<FakeServerUpdater> { syncable::ScopedDirLookup dir(dir_manager, user_share->name); ASSERT_TRUE(dir.good()); - // Create autofill protobuf + // Create autofill protobuf. std::string tag = AutocompleteSyncableService::KeyToTag( UTF16ToUTF8(entry_.key().name()), UTF16ToUTF8(entry_.key().value())); sync_pb::AutofillSpecifics new_autofill; @@ -670,11 +670,10 @@ class FakeServerUpdater : public base::RefCountedThreadSafe<FakeServerUpdater> { void CreateNewEntry(const AutofillEntry& entry) { entry_ = entry; - scoped_ptr<Callback0::Type> c(NewCallback((FakeServerUpdater*)this, - &FakeServerUpdater::Update)); ASSERT_FALSE(BrowserThread::CurrentlyOn(BrowserThread::DB)); - if (!BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, - base::Bind(&FakeServerUpdater::Update, this))) { + if (!BrowserThread::PostTask( + BrowserThread::DB, FROM_HERE, + base::Bind(&FakeServerUpdater::Update, this))) { NOTREACHED() << "Failed to post task to the db thread."; return; } @@ -682,8 +681,6 @@ class FakeServerUpdater : public base::RefCountedThreadSafe<FakeServerUpdater> { void CreateNewEntryAndWait(const AutofillEntry& entry) { entry_ = entry; - scoped_ptr<Callback0::Type> c(NewCallback((FakeServerUpdater*)this, - &FakeServerUpdater::Update)); ASSERT_FALSE(BrowserThread::CurrentlyOn(BrowserThread::DB)); is_finished_.Reset(); if (!BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, diff --git a/net/base/cookie_store.h b/net/base/cookie_store.h index 1276e2d..873d88b 100644 --- a/net/base/cookie_store.h +++ b/net/base/cookie_store.h @@ -69,7 +69,7 @@ class NET_EXPORT CookieStore : public base::RefCountedThreadSafe<CookieStore> { // TODO(???): what if the total size of all the cookies >4k, can we have a // header that big or do we need multiple Cookie: headers? - // Note: Some sites, such as Facebook, occationally use Cookie headers >4k. + // Note: Some sites, such as Facebook, occasionally use Cookie headers >4k. // // Simple interface, gets a cookie string "a=b; c=d" for the given URL. // Use options to access httponly cookies. @@ -78,7 +78,7 @@ class NET_EXPORT CookieStore : public base::RefCountedThreadSafe<CookieStore> { const GetCookiesCallback& callback) = 0; // This function is similar to GetCookiesWithOptions same functionality as - // GetCookiesWithOptions except that it additionaly provides detailed + // GetCookiesWithOptions except that it additionally provides detailed // information about the cookie contained in the cookie line. See |struct // CookieInfo| above for details. virtual void GetCookiesWithInfoAsync( |