diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-29 03:09:44 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-29 03:09:44 +0000 |
commit | 6790e994966a2986bab059b9ecd00ecf31e6bda6 (patch) | |
tree | 0eb8334013483d34237d69ec1aec7185e040d3a1 | |
parent | be06d67c4742c12b2ad98bcfd7e0dbc74b627075 (diff) | |
download | chromium_src-6790e994966a2986bab059b9ecd00ecf31e6bda6.zip chromium_src-6790e994966a2986bab059b9ecd00ecf31e6bda6.tar.gz chromium_src-6790e994966a2986bab059b9ecd00ecf31e6bda6.tar.bz2 |
Revert 111850 - 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
TBR=jhawkins@chromium.org
Review URL: http://codereview.chromium.org/8729019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111851 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, 188 insertions, 106 deletions
diff --git a/chrome/browser/automation/automation_provider_win.cc b/chrome/browser/automation/automation_provider_win.cc index 999ae50..189ebef 100644 --- a/chrome/browser/automation/automation_provider_win.cc +++ b/chrome/browser/automation/automation_provider_win.cc @@ -30,16 +30,14 @@ #include "ui/views/focus/accelerator_handler.h" #include "ui/views/widget/root_view.h" -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); +// 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); } -void MoveMouse(const POINT& point) { +static void MoveMouse(const POINT& point) { SetCursorPos(point.x, point.y); // Now, make sure that GetMessagePos returns the values we just set by @@ -66,18 +64,78 @@ BOOL CALLBACK EnumThreadWndProc(HWND hwnd, LPARAM l_param) { return TRUE; } -// 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); -} +// 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_; -} // namespace + DISALLOW_COPY_AND_ASSIGN(WindowDragResponseTask); +}; void AutomationProvider::WindowSimulateDrag( int handle, @@ -155,9 +213,8 @@ void AutomationProvider::WindowSimulateDrag( MAKELPARAM(end.x, end.y)); MessageLoop::current()->PostTask( - FROM_HERE, base::Bind( - &InvokeCallbackLater, - base::Bind(&WindowDragResponseCallback, this, reply_message))); + FROM_HERE, base::Bind(&InvokeTaskLater, + new WindowDragResponseTask(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 aa0584e..86619e3 100644 --- a/chrome/browser/chrome_browser_main.cc +++ b/chrome/browser/chrome_browser_main.cc @@ -245,9 +245,16 @@ void AddFirstRunNewTabs(BrowserInit* browser_init, } #if defined(USE_LINUX_BREAKPAD) -void GetLinuxDistroCallback() { - base::GetLinuxDistro(); // Initialize base::linux_distro if needed. -} +class GetLinuxDistroTask : public Task { + public: + explicit GetLinuxDistroTask() {} + + virtual void Run() { + base::GetLinuxDistro(); // Initialize base::linux_distro if needed. + } + + DISALLOW_COPY_AND_ASSIGN(GetLinuxDistroTask); +}; #endif // USE_LINUX_BREAKPAD void InitializeNetworkOptions(const CommandLine& parsed_command_line) { @@ -1213,7 +1220,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, base::Bind(&GetLinuxDistroCallback)); + FROM_HERE, new GetLinuxDistroTask()); 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 a9faa56..c431b7f 100644 --- a/chrome/browser/chromeos/web_socket_proxy_controller.cc +++ b/chrome/browser/chromeos/web_socket_proxy_controller.cc @@ -10,8 +10,6 @@ #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" @@ -100,6 +98,10 @@ 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 { @@ -107,8 +109,7 @@ class ProxyLifetime ProxyLifetime() : delay_ms_(1000), port_(-1), shutdown_requested_(false) { DLOG(INFO) << "WebSocketProxyController initiation"; BrowserThread::PostTask( - BrowserThread::WEB_SOCKET_PROXY, FROM_HERE, - base::Bind(&ProxyLifetime::ProxyCallback, base::Unretained(this))); + BrowserThread::WEB_SOCKET_PROXY, FROM_HERE, new ProxyTask()); net::NetworkChangeNotifier::AddOnlineStateObserver(this); registrar_.Add( this, chrome::NOTIFICATION_WEB_SOCKET_PROXY_STARTED, @@ -131,7 +132,7 @@ class ProxyLifetime } private: - // net::NetworkChangeNotifier::OnlineStateObserver implementation. + // net::NetworkChangeNotifier::OnlineStateObserver overrides. virtual void OnOnlineStateChanged(bool online) OVERRIDE { DCHECK(chromeos::WebSocketProxyController::IsInitiated()); base::AutoLock alk(lock_); @@ -139,36 +140,6 @@ 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_; @@ -179,11 +150,40 @@ 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 ae8a3af..4f3afac 100644 --- a/chrome/browser/net/cookie_policy_browsertest.cc +++ b/chrome/browser/net/cookie_policy_browsertest.cc @@ -3,7 +3,6 @@ // 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" @@ -23,24 +22,41 @@ using content::BrowserThread; namespace { -void GetCookiesCallback(std::string* cookies_out, - base::WaitableEvent* event, - const std::string& cookies) { - *cookies_out = cookies; - event->Signal(); -} +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_))); + } -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))); -} + 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_; + + DISALLOW_COPY_AND_ASSIGN(GetCookiesTask); +}; class CookiePolicyBrowserTest : public InProcessBrowserTest { protected: @@ -55,8 +71,7 @@ class CookiePolicyBrowserTest : public InProcessBrowserTest { EXPECT_TRUE( BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, - base::Bind(&GetCookiesOnIOThread, url, - make_scoped_refptr(context_getter), &event, &cookies))); + new GetCookiesTask(url, 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 da9b322..153f104 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() OVERRIDE { + virtual AutofillTable* GetAutofillTable() { return autofill_table_; } @@ -176,11 +176,11 @@ class WebDataServiceFake : public WebDataService { syncable_service_created_or_destroyed_.Wait(); } - virtual bool IsDatabaseLoaded() OVERRIDE { + virtual bool IsDatabaseLoaded() { return true; } - virtual WebDatabase* GetDatabase() OVERRIDE { + virtual WebDatabase* GetDatabase() { return web_database_; } @@ -264,17 +264,17 @@ class AbstractAutofillFactory { class AutofillEntryFactory : public AbstractAutofillFactory { public: - virtual browser_sync::DataTypeController* CreateDataTypeController( + browser_sync::DataTypeController* CreateDataTypeController( ProfileSyncComponentsFactory* factory, ProfileMock* profile, - ProfileSyncService* service) OVERRIDE { + ProfileSyncService* service) { return new AutofillDataTypeController(factory, profile); } - virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory, - ProfileSyncService* service, - WebDataService* wds, - DataTypeController* dtc) OVERRIDE { + void SetExpectation(ProfileSyncComponentsFactoryMock* factory, + ProfileSyncService* service, + WebDataService* wds, + DataTypeController* dtc) { EXPECT_CALL(*factory, CreateGenericChangeProcessor(_,_,_)). WillOnce(MakeGenericChangeProcessor()); EXPECT_CALL(*factory, CreateSharedChangeProcessor()). @@ -286,17 +286,17 @@ class AutofillEntryFactory : public AbstractAutofillFactory { class AutofillProfileFactory : public AbstractAutofillFactory { public: - virtual browser_sync::DataTypeController* CreateDataTypeController( + browser_sync::DataTypeController* CreateDataTypeController( ProfileSyncComponentsFactory* factory, ProfileMock* profile, - ProfileSyncService* service) OVERRIDE { + ProfileSyncService* service) { return new AutofillProfileDataTypeController(factory, profile); } - virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory, - ProfileSyncService* service, - WebDataService* wds, - DataTypeController* dtc) OVERRIDE { + void SetExpectation(ProfileSyncComponentsFactoryMock* factory, + ProfileSyncService* service, + WebDataService* wds, + DataTypeController* dtc) { EXPECT_CALL(*factory, CreateGenericChangeProcessor(_,_,_)). WillOnce(MakeGenericChangeProcessor()); EXPECT_CALL(*factory, CreateSharedChangeProcessor()). @@ -338,7 +338,7 @@ class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest { } } - virtual void SetUp() OVERRIDE { + virtual void SetUp() { 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() OVERRIDE { + virtual void TearDown() { // Note: The tear down order is important. service_.reset(); web_data_service_->ShutdownSyncableService(); @@ -582,6 +582,7 @@ 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, @@ -591,8 +592,7 @@ class WriteTransactionTest: public WriteTransaction { : WriteTransaction(from_here, writer, directory), wait_for_syncapi_(wait_for_syncapi) { } - virtual void NotifyTransactionComplete( - syncable::ModelTypeBitSet types) OVERRIDE { + virtual void NotifyTransactionComplete(syncable::ModelTypeBitSet types) { // 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,10 +670,11 @@ 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; } @@ -681,6 +682,8 @@ 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 873d88b..1276e2d 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, occasionally use Cookie headers >4k. + // Note: Some sites, such as Facebook, occationally 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 additionally provides detailed + // GetCookiesWithOptions except that it additionaly provides detailed // information about the cookie contained in the cookie line. See |struct // CookieInfo| above for details. virtual void GetCookiesWithInfoAsync( |