inSearchLoop.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #include "inSearchLoop.h"
  5. #include "nsITimer.h"
  6. #include "nsIServiceManager.h"
  7. ///////////////////////////////////////////////////////////////////////////////
  8. inSearchLoop::inSearchLoop(inISearchProcess* aSearchProcess)
  9. {
  10. mSearchProcess = aSearchProcess;
  11. nsresult rv;
  12. mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
  13. }
  14. inSearchLoop::~inSearchLoop()
  15. {
  16. }
  17. ///////////////////////////////////////////////////////////////////////////////
  18. // inSearchLoop
  19. nsresult
  20. inSearchLoop::Start()
  21. {
  22. mTimer->InitWithFuncCallback(inSearchLoop::TimerCallback, (void*)this, 0, nsITimer::TYPE_REPEATING_SLACK);
  23. return NS_OK;
  24. }
  25. nsresult
  26. inSearchLoop::Step()
  27. {
  28. bool done = false;
  29. mSearchProcess->SearchStep(&done);
  30. if (done)
  31. Stop();
  32. return NS_OK;
  33. }
  34. nsresult
  35. inSearchLoop::Stop()
  36. {
  37. mTimer->Cancel();
  38. return NS_OK;
  39. }
  40. void
  41. inSearchLoop::TimerCallback(nsITimer *aTimer, void *aClosure)
  42. {
  43. inSearchLoop* loop = (inSearchLoop*) aClosure;
  44. loop->Step();
  45. }