Chromium Code Reviews| Index: content/common/file_path_watcher/file_path_watcher.h |
| diff --git a/chrome/browser/file_path_watcher/file_path_watcher.h b/content/common/file_path_watcher/file_path_watcher.h |
| similarity index 54% |
| rename from chrome/browser/file_path_watcher/file_path_watcher.h |
| rename to content/common/file_path_watcher/file_path_watcher.h |
| index 530962e3e8ee6da239d8a8d3e762b833b4f1f731..a08c70ce15df1a7889529fcf1feac551e3827a82 100644 |
| --- a/chrome/browser/file_path_watcher/file_path_watcher.h |
| +++ b/content/common/file_path_watcher/file_path_watcher.h |
| @@ -4,14 +4,14 @@ |
| // This module provides a way to monitor a file or directory for changes. |
| -#ifndef CHROME_BROWSER_FILE_PATH_WATCHER_FILE_PATH_WATCHER_H_ |
| -#define CHROME_BROWSER_FILE_PATH_WATCHER_FILE_PATH_WATCHER_H_ |
| +#ifndef CONTENT_COMMON_FILE_PATH_WATCHER_FILE_PATH_WATCHER_H_ |
| +#define CONTENT_COMMON_FILE_PATH_WATCHER_FILE_PATH_WATCHER_H_ |
| #pragma once |
| #include "base/basictypes.h" |
| #include "base/file_path.h" |
| +#include "base/message_loop_proxy.h" |
| #include "base/ref_counted.h" |
| -#include "content/browser/browser_thread.h" |
| // This class lets you register interest in changes on a FilePath. |
| // The delegate will get called whenever the file or directory referenced by the |
| @@ -36,27 +36,53 @@ class FilePathWatcher { |
| ~FilePathWatcher(); |
| // Register interest in any changes on |path|. OnPathChanged will be called |
| - // back for each change. Returns true on success. |
| - bool Watch(const FilePath& path, Delegate* delegate) WARN_UNUSED_RESULT; |
| + // back for each change. Returns true on success. |loop| is only used |
| + // by the Mac implementation right now, and must be backed by a CFRunLoop |
| + // based MessagePump. This is usually going to be a MessageLoop of type |
| + // TYPE_UI. |
| + bool Watch(const FilePath& path, |
| + Delegate* delegate, |
| + scoped_refptr<base::MessageLoopProxy> loop) WARN_UNUSED_RESULT; |
|
Mattias Nissler (ping if slow)
2011/03/17 18:14:27
Plain pointer here, too?
|
| + |
| + class PlatformDelegate; |
| + |
| + // Traits for PlatformDelegate, which must delete itself on the IO message |
| + // loop that Watch was called from. |
| + struct DeletePlatformDelegate { |
| + static void Destruct(const PlatformDelegate* delegate); |
| + }; |
| // Used internally to encapsulate different members on different platforms. |
| class PlatformDelegate |
| : public base::RefCountedThreadSafe<PlatformDelegate, |
| - BrowserThread::DeleteOnFileThread> { |
| + DeletePlatformDelegate> { |
| public: |
| // Start watching for the given |path| and notify |delegate| about changes. |
| - virtual bool Watch(const FilePath& path, Delegate* delegate) |
| - WARN_UNUSED_RESULT = 0; |
| + // |loop| is only used by the Mac implementation right now, and must be |
| + // backed by a CFRunLoop based MessagePump. This is usually going to be a |
| + // MessageLoop of type TYPE_UI. |
| + virtual bool Watch( |
| + const FilePath& path, |
| + Delegate* delegate, |
| + scoped_refptr<base::MessageLoopProxy> loop) WARN_UNUSED_RESULT = 0; |
|
Mattias Nissler (ping if slow)
2011/03/17 18:14:27
and here?
|
| // Stop watching. This is called from FilePathWatcher's dtor in order to |
| // allow to shut down properly while the object is still alive. |
| - virtual void Cancel() {} |
| + virtual void Cancel() = 0; |
| + |
| + scoped_refptr<base::MessageLoopProxy> message_loop() const { |
|
Mattias Nissler (ping if slow)
2011/03/17 18:14:27
Why is this public? The only reason I can see is t
|
| + return message_loop_; |
| + } |
| + void set_message_loop(scoped_refptr<base::MessageLoopProxy> loop); |
|
Mattias Nissler (ping if slow)
2011/03/17 18:14:27
It seems odd that the message_loop_ accessors are
|
| protected: |
| - friend struct BrowserThread::DeleteOnThread<BrowserThread::FILE>; |
| friend class DeleteTask<PlatformDelegate>; |
| + friend struct DeletePlatformDelegate; |
| + virtual ~PlatformDelegate(); |
| - virtual ~PlatformDelegate() {} |
| + private: |
| + // IO Message Loop. |
| + scoped_refptr<base::MessageLoopProxy> message_loop_; |
| }; |
| private: |
| @@ -65,4 +91,4 @@ class FilePathWatcher { |
| DISALLOW_COPY_AND_ASSIGN(FilePathWatcher); |
| }; |
| -#endif // CHROME_BROWSER_FILE_PATH_WATCHER_FILE_PATH_WATCHER_H_ |
| +#endif // CONTENT_COMMON_FILE_PATH_WATCHER_FILE_PATH_WATCHER_H_ |