diff options
-rw-r--r-- | base/base.gyp | 1 | ||||
-rw-r--r-- | base/base.gypi | 22 | ||||
-rw-r--r-- | base/directory_watcher.h | 64 | ||||
-rw-r--r-- | base/directory_watcher_inotify.cc | 473 | ||||
-rw-r--r-- | base/directory_watcher_mac.cc | 122 | ||||
-rw-r--r-- | base/directory_watcher_stub.cc | 20 | ||||
-rw-r--r-- | base/directory_watcher_unittest.cc | 426 | ||||
-rw-r--r-- | base/directory_watcher_win.cc | 84 | ||||
-rw-r--r-- | base/mac_util_unittest.mm | 3 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 3 | ||||
-rw-r--r-- | chrome/browser/extensions/user_script_master.cc | 30 | ||||
-rw-r--r-- | chrome/browser/extensions/user_script_master.h | 15 | ||||
-rw-r--r-- | chrome/browser/extensions/user_script_master_unittest.cc | 24 | ||||
-rw-r--r-- | chrome/browser/profile.cc | 4 |
14 files changed, 3 insertions, 1288 deletions
diff --git a/base/base.gyp b/base/base.gyp index 1c1b296..a0b6dd3 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -67,7 +67,6 @@ 'crypto/signature_verifier_unittest.cc', 'data_pack_unittest.cc', 'debug_util_unittest.cc', - 'directory_watcher_unittest.cc', 'event_trace_consumer_win_unittest.cc', 'event_trace_controller_win_unittest.cc', 'event_trace_provider_win_unittest.cc', diff --git a/base/base.gypi b/base/base.gypi index 369fa54..7e1fbf6 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -287,7 +287,6 @@ 'sources!': [ 'atomicops_internals_x86_gcc.cc', 'base_paths_posix.cc', - 'directory_watcher_inotify.cc', 'linux_util.cc', 'message_pump_glib.cc', ], @@ -310,17 +309,6 @@ 'sources/': [ ['exclude', '_openbsd\\.cc$'] ], }, ], - [ 'GENERATOR == "quentin"', { - # Quentin builds don't have a recent enough glibc to include the - # inotify headers - 'sources!': [ - 'directory_watcher_inotify.cc', - ], - 'sources': [ - 'directory_watcher_stub.cc', - ], - }, - ], [ 'OS == "mac"', { 'sources!': [ # TODO(wtc): Remove nss_util.{cc,h} when http://crbug.com/30689 @@ -413,12 +401,6 @@ ], },], [ 'OS == "freebsd"', { - 'sources!': [ - 'directory_watcher_inotify.cc', - ], - 'sources': [ - 'directory_watcher_stub.cc', - ], 'link_settings': { 'libraries': [ '-L/usr/local/lib -lexecinfo', @@ -498,10 +480,6 @@ 'base_drop_target.cc', 'base_drop_target.h', 'data_pack.cc', - 'directory_watcher.h', - 'directory_watcher_inotify.cc', - 'directory_watcher_mac.cc', - 'directory_watcher_win.cc', 'dynamic_annotations.h', 'dynamic_annotations.cc', 'event_recorder.cc', diff --git a/base/directory_watcher.h b/base/directory_watcher.h deleted file mode 100644 index 207d6d2..0000000 --- a/base/directory_watcher.h +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) 2006-2008 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. - -// This module provides a way to monitor a directory for changes. - -#ifndef BASE_DIRECTORY_WATCHER_H_ -#define BASE_DIRECTORY_WATCHER_H_ - -#include "base/basictypes.h" -#include "base/ref_counted.h" - -class FilePath; -class MessageLoop; - -// This class lets you register interest in changes on a directory. -// The delegate will get called whenever a file is added or changed in the -// directory. -class DirectoryWatcher { - public: - class Delegate { - public: - virtual ~Delegate() {} - virtual void OnDirectoryChanged(const FilePath& path) = 0; - }; - - DirectoryWatcher(); - ~DirectoryWatcher() {} - - // Register interest in any changes in the directory |path|. - // OnDirectoryChanged will be called back for each change within the dir. - // Any background operations will be ran on |backend_loop|, or inside Watch - // if |backend_loop| is NULL. If |recursive| is true, the delegate will be - // notified for each change within the directory tree starting at |path|. - // Returns false on error. - // - // Note: on Windows you may got more notifications for non-recursive watch - // than you expect, especially on versions earlier than Vista. The behavior - // is consistent on any particular version of Windows, but not across - // different versions. - bool Watch(const FilePath& path, Delegate* delegate, - MessageLoop* backend_loop, bool recursive) { - return impl_->Watch(path, delegate, backend_loop, recursive); - } - - // Used internally to encapsulate different members on different platforms. - class PlatformDelegate : public base::RefCounted<PlatformDelegate> { - public: - virtual bool Watch(const FilePath& path, Delegate* delegate, - MessageLoop* backend_loop, bool recursive) = 0; - - protected: - friend class base::RefCounted<PlatformDelegate>; - - virtual ~PlatformDelegate() {} - }; - - private: - scoped_refptr<PlatformDelegate> impl_; - - DISALLOW_COPY_AND_ASSIGN(DirectoryWatcher); -}; - -#endif // BASE_DIRECTORY_WATCHER_H_ diff --git a/base/directory_watcher_inotify.cc b/base/directory_watcher_inotify.cc deleted file mode 100644 index c593ff5..0000000 --- a/base/directory_watcher_inotify.cc +++ /dev/null @@ -1,473 +0,0 @@ -// Copyright (c) 2009 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 "base/directory_watcher.h" - -#include <errno.h> -#include <string.h> -#include <sys/inotify.h> -#include <sys/ioctl.h> -#include <sys/select.h> -#include <unistd.h> - -#include <algorithm> -#include <set> -#include <utility> -#include <vector> - -#include "base/eintr_wrapper.h" -#include "base/file_path.h" -#include "base/file_util.h" -#include "base/hash_tables.h" -#include "base/lock.h" -#include "base/logging.h" -#include "base/message_loop.h" -#include "base/scoped_ptr.h" -#include "base/singleton.h" -#include "base/task.h" -#include "base/thread.h" -#include "base/waitable_event.h" - -namespace { - -class DirectoryWatcherImpl; - -// Singleton to manage all inotify watches. -class InotifyReader { - public: - typedef int Watch; // Watch descriptor used by AddWatch and RemoveWatch. - static const Watch kInvalidWatch = -1; - - // Watch |path| for changes. |watcher| will be notified on each change. - // Returns kInvalidWatch on failure. - Watch AddWatch(const FilePath& path, DirectoryWatcherImpl* watcher); - - // Remove |watch|. Returns true on success. - bool RemoveWatch(Watch watch, DirectoryWatcherImpl* watcher); - - // Callback for InotifyReaderTask. - void OnInotifyEvent(const inotify_event* event); - - private: - friend struct DefaultSingletonTraits<InotifyReader>; - - typedef std::set<DirectoryWatcherImpl*> WatcherSet; - - InotifyReader(); - ~InotifyReader(); - - // We keep track of which delegates want to be notified on which watches. - base::hash_map<Watch, WatcherSet> watchers_; - - // For each watch we also want to know the path it's watching. - base::hash_map<Watch, FilePath> paths_; - - // Lock to protect delegates_ and paths_. - Lock lock_; - - // Separate thread on which we run blocking read for inotify events. - base::Thread thread_; - - // File descriptor returned by inotify_init. - const int inotify_fd_; - - // Use self-pipe trick to unblock select during shutdown. - int shutdown_pipe_[2]; - - // Flag set to true when startup was successful. - bool valid_; - - DISALLOW_COPY_AND_ASSIGN(InotifyReader); -}; - -class DirectoryWatcherImpl : public DirectoryWatcher::PlatformDelegate { - public: - typedef std::set<FilePath> FilePathSet; - - DirectoryWatcherImpl(); - ~DirectoryWatcherImpl(); - - void EnsureSetupFinished(); - - // Called for each event coming from one of watches. - void OnInotifyEvent(const inotify_event* event); - - // Callback for RegisterSubtreeWatchesTask. - bool OnEnumeratedSubtree(const FilePathSet& paths); - - // Start watching |path| for changes and notify |delegate| on each change. - // If |recursive| is true, watch entire subtree. - // Returns true if watch for |path| has been added successfully. Watches - // required for |recursive| are added on a background thread and have no - // effect on the return value. - virtual bool Watch(const FilePath& path, DirectoryWatcher::Delegate* delegate, - MessageLoop* backend_loop, bool recursive); - - private: - typedef std::set<InotifyReader::Watch> WatchSet; - typedef std::set<ino_t> InodeSet; - - // Returns true if |inode| is watched by DirectoryWatcherImpl. - bool IsInodeWatched(ino_t inode) const; - - // Delegate to notify upon changes. - DirectoryWatcher::Delegate* delegate_; - - // Path we're watching (passed to delegate). - FilePath root_path_; - - // Watch returned by InotifyReader. - InotifyReader::Watch watch_; - - // Set of watched inodes. - InodeSet inodes_watched_; - - // Keep track of registered watches. - WatchSet watches_; - - // Lock to protect inodes_watched_ and watches_. - Lock lock_; - - // Flag set to true when recursively watching subtree. - bool recursive_; - - // Loop where we post directory change notifications to. - MessageLoop* loop_; - - // Event signaled when the background task finished adding initial inotify - // watches for recursive watch. - base::WaitableEvent recursive_setup_finished_; - - DISALLOW_COPY_AND_ASSIGN(DirectoryWatcherImpl); -}; - -class RegisterSubtreeWatchesTask : public Task { - public: - RegisterSubtreeWatchesTask(DirectoryWatcherImpl* watcher, - const FilePath& path) - : watcher_(watcher), - path_(path) { - } - - virtual void Run() { - file_util::FileEnumerator dir_list(path_, true, - file_util::FileEnumerator::DIRECTORIES); - - DirectoryWatcherImpl::FilePathSet subtree; - for (FilePath subdirectory = dir_list.Next(); - !subdirectory.empty(); - subdirectory = dir_list.Next()) { - subtree.insert(subdirectory); - } - watcher_->OnEnumeratedSubtree(subtree); - } - - private: - DirectoryWatcherImpl* watcher_; - FilePath path_; - - DISALLOW_COPY_AND_ASSIGN(RegisterSubtreeWatchesTask); -}; - -class DirectoryWatcherImplNotifyTask : public Task { - public: - DirectoryWatcherImplNotifyTask(DirectoryWatcher::Delegate* delegate, - const FilePath& path) - : delegate_(delegate), - path_(path) { - } - - virtual void Run() { - delegate_->OnDirectoryChanged(path_); - } - - private: - DirectoryWatcher::Delegate* delegate_; - FilePath path_; - - DISALLOW_COPY_AND_ASSIGN(DirectoryWatcherImplNotifyTask); -}; - -class InotifyReaderTask : public Task { - public: - InotifyReaderTask(InotifyReader* reader, int inotify_fd, int shutdown_fd) - : reader_(reader), - inotify_fd_(inotify_fd), - shutdown_fd_(shutdown_fd) { - } - - virtual void Run() { - while (true) { - fd_set rfds; - FD_ZERO(&rfds); - FD_SET(inotify_fd_, &rfds); - FD_SET(shutdown_fd_, &rfds); - - // Wait until some inotify events are available. - int select_result = - HANDLE_EINTR(select(std::max(inotify_fd_, shutdown_fd_) + 1, - &rfds, NULL, NULL, NULL)); - if (select_result < 0) { - DPLOG(WARNING) << "select failed"; - return; - } - - if (FD_ISSET(shutdown_fd_, &rfds)) - return; - - // Adjust buffer size to current event queue size. - int buffer_size; - int ioctl_result = HANDLE_EINTR(ioctl(inotify_fd_, FIONREAD, - &buffer_size)); - - if (ioctl_result != 0) { - DPLOG(WARNING) << "ioctl failed"; - return; - } - - std::vector<char> buffer(buffer_size); - - ssize_t bytes_read = HANDLE_EINTR(read(inotify_fd_, &buffer[0], - buffer_size)); - - if (bytes_read < 0) { - DPLOG(WARNING) << "read from inotify fd failed"; - return; - } - - ssize_t i = 0; - while (i < bytes_read) { - inotify_event* event = reinterpret_cast<inotify_event*>(&buffer[i]); - size_t event_size = sizeof(inotify_event) + event->len; - DCHECK(i + event_size <= static_cast<size_t>(bytes_read)); - reader_->OnInotifyEvent(event); - i += event_size; - } - } - } - - private: - InotifyReader* reader_; - int inotify_fd_; - int shutdown_fd_; - - DISALLOW_COPY_AND_ASSIGN(InotifyReaderTask); -}; - -InotifyReader::InotifyReader() - : thread_("inotify_reader"), - inotify_fd_(inotify_init()), - valid_(false) { - shutdown_pipe_[0] = -1; - shutdown_pipe_[1] = -1; - if (inotify_fd_ >= 0 && pipe(shutdown_pipe_) == 0 && thread_.Start()) { - thread_.message_loop()->PostTask( - FROM_HERE, new InotifyReaderTask(this, inotify_fd_, shutdown_pipe_[0])); - valid_ = true; - } -} - -InotifyReader::~InotifyReader() { - if (valid_) { - // Write to the self-pipe so that the select call in InotifyReaderTask - // returns. - ssize_t ret = HANDLE_EINTR(write(shutdown_pipe_[1], "", 1)); - DPCHECK(ret > 0); - DCHECK_EQ(ret, 1); - thread_.Stop(); - } - if (inotify_fd_ >= 0) - close(inotify_fd_); - if (shutdown_pipe_[0] >= 0) - close(shutdown_pipe_[0]); - if (shutdown_pipe_[1] >= 0) - close(shutdown_pipe_[1]); -} - -InotifyReader::Watch InotifyReader::AddWatch( - const FilePath& path, DirectoryWatcherImpl* watcher) { - - if (!valid_) - return kInvalidWatch; - - AutoLock auto_lock(lock_); - - Watch watch = inotify_add_watch(inotify_fd_, path.value().c_str(), - IN_CREATE | IN_DELETE | - IN_CLOSE_WRITE | IN_MOVE); - - if (watch == kInvalidWatch) - return kInvalidWatch; - - if (paths_[watch].empty()) - paths_[watch] = path; // We don't yet watch this path. - - watchers_[watch].insert(watcher); - - return watch; -} - -bool InotifyReader::RemoveWatch(Watch watch, - DirectoryWatcherImpl* watcher) { - if (!valid_) - return false; - - AutoLock auto_lock(lock_); - - if (paths_[watch].empty()) - return false; // We don't recognize this watch. - - watchers_[watch].erase(watcher); - - if (watchers_[watch].empty()) { - paths_.erase(watch); - watchers_.erase(watch); - return (inotify_rm_watch(inotify_fd_, watch) == 0); - } - - return true; -} - -void InotifyReader::OnInotifyEvent(const inotify_event* event) { - if (event->mask & IN_IGNORED) - return; - - // In case you want to limit the scope of this lock, it's not sufficient - // to just copy things under the lock, and then run the notifications - // without holding the lock. DirectoryWatcherImpl's dtor removes its watches, - // and to do that obtains the lock. After it finishes removing watches, - // it's destroyed. So, if you copy under the lock and notify without the lock, - // it's possible you'll copy the DirectoryWatcherImpl which is being - // destroyed, then it will destroy itself, and then you'll try to notify it. - AutoLock auto_lock(lock_); - - for (WatcherSet::iterator watcher = watchers_[event->wd].begin(); - watcher != watchers_[event->wd].end(); - ++watcher) { - (*watcher)->OnInotifyEvent(event); - } -} - -DirectoryWatcherImpl::DirectoryWatcherImpl() - : watch_(InotifyReader::kInvalidWatch), - recursive_setup_finished_(false, false) { -} - -DirectoryWatcherImpl::~DirectoryWatcherImpl() { - if (watch_ == InotifyReader::kInvalidWatch) - return; - - if (recursive_) - recursive_setup_finished_.Wait(); - for (WatchSet::iterator watch = watches_.begin(); - watch != watches_.end(); - ++watch) { - Singleton<InotifyReader>::get()->RemoveWatch(*watch, this); - } - watches_.clear(); - inodes_watched_.clear(); -} - -void DirectoryWatcherImpl::OnInotifyEvent(const inotify_event* event) { - loop_->PostTask(FROM_HERE, - new DirectoryWatcherImplNotifyTask(delegate_, root_path_)); - - if (!(event->mask & IN_ISDIR)) - return; - - if (event->mask & IN_CREATE || event->mask & IN_MOVED_TO) { - // TODO(phajdan.jr): add watch for this new directory. - NOTIMPLEMENTED(); - } else if (event->mask & IN_DELETE || event->mask & IN_MOVED_FROM) { - // TODO(phajdan.jr): remove our watch for this directory. - NOTIMPLEMENTED(); - } -} - -bool DirectoryWatcherImpl::IsInodeWatched(ino_t inode) const { - return inodes_watched_.find(inode) != inodes_watched_.end(); -} - -bool DirectoryWatcherImpl::OnEnumeratedSubtree(const FilePathSet& subtree) { - DCHECK(recursive_); - - if (watch_ == InotifyReader::kInvalidWatch) { - recursive_setup_finished_.Signal(); - return false; - } - - bool success = true; - - { - // Limit the scope of auto_lock so it releases lock_ before we signal - // recursive_setup_finished_. Our dtor waits on recursive_setup_finished_ - // and could otherwise destroy the lock before we release it. - AutoLock auto_lock(lock_); - - for (FilePathSet::iterator subdirectory = subtree.begin(); - subdirectory != subtree.end(); - ++subdirectory) { - ino_t inode; - if (!file_util::GetInode(*subdirectory, &inode)) { - success = false; - continue; - } - if (IsInodeWatched(inode)) - continue; - InotifyReader::Watch watch = - Singleton<InotifyReader>::get()->AddWatch(*subdirectory, this); - if (watch != InotifyReader::kInvalidWatch) { - watches_.insert(watch); - inodes_watched_.insert(inode); - } - } - } - - recursive_setup_finished_.Signal(); - return success; -} - -bool DirectoryWatcherImpl::Watch(const FilePath& path, - DirectoryWatcher::Delegate* delegate, - MessageLoop* backend_loop, bool recursive) { - - // Can only watch one path. - DCHECK(watch_ == InotifyReader::kInvalidWatch); - - ino_t inode; - if (!file_util::GetInode(path, &inode)) - return false; - - delegate_ = delegate; - recursive_ = recursive; - root_path_ = path; - loop_ = MessageLoop::current(); - watch_ = Singleton<InotifyReader>::get()->AddWatch(path, this); - if (watch_ == InotifyReader::kInvalidWatch) - return false; - - { - AutoLock auto_lock(lock_); - inodes_watched_.insert(inode); - watches_.insert(watch_); - } - - if (recursive_) { - Task* subtree_task = new RegisterSubtreeWatchesTask(this, root_path_); - if (backend_loop) { - backend_loop->PostTask(FROM_HERE, subtree_task); - } else { - subtree_task->Run(); - delete subtree_task; - } - } - - return true; -} - -} // namespace - -DirectoryWatcher::DirectoryWatcher() { - impl_ = new DirectoryWatcherImpl(); -} diff --git a/base/directory_watcher_mac.cc b/base/directory_watcher_mac.cc deleted file mode 100644 index dc3eba6..0000000 --- a/base/directory_watcher_mac.cc +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright (c) 2009 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 "base/directory_watcher.h" - -#include <CoreServices/CoreServices.h> - -#include "base/file_path.h" -#include "base/file_util.h" -#include "base/logging.h" -#include "base/message_loop.h" -#include "base/scoped_cftyperef.h" - -namespace { - -const CFAbsoluteTime kEventLatencySeconds = 0.3; - -class DirectoryWatcherImpl : public DirectoryWatcher::PlatformDelegate { - public: - DirectoryWatcherImpl() {} - ~DirectoryWatcherImpl() { - if (!path_.value().empty()) { - FSEventStreamStop(fsevent_stream_); - FSEventStreamInvalidate(fsevent_stream_); - FSEventStreamRelease(fsevent_stream_); - } - } - - virtual bool Watch(const FilePath& path, DirectoryWatcher::Delegate* delegate, - MessageLoop* backend_loop, bool recursive); - - void OnFSEventsCallback(const FilePath& event_path) { - DCHECK(!path_.value().empty()); - if (!recursive_) { - FilePath absolute_event_path = event_path; - if (!file_util::AbsolutePath(&absolute_event_path)) - return; - if (absolute_event_path != path_) - return; - } - delegate_->OnDirectoryChanged(path_); - } - - private: - // Delegate to notify upon changes. - DirectoryWatcher::Delegate* delegate_; - - // Path we're watching (passed to delegate). - FilePath path_; - - // Indicates recursive watch. - bool recursive_; - - // Backend stream we receive event callbacks from (strong reference). - FSEventStreamRef fsevent_stream_; - - DISALLOW_COPY_AND_ASSIGN(DirectoryWatcherImpl); -}; - -void FSEventsCallback(ConstFSEventStreamRef stream, - void* event_watcher, size_t num_events, - void* event_paths, const FSEventStreamEventFlags flags[], - const FSEventStreamEventId event_ids[]) { - char** paths = reinterpret_cast<char**>(event_paths); - DirectoryWatcherImpl* watcher = - reinterpret_cast<DirectoryWatcherImpl*> (event_watcher); - for (size_t i = 0; i < num_events; i++) { - watcher->OnFSEventsCallback(FilePath(paths[i])); - } -} - -bool DirectoryWatcherImpl::Watch(const FilePath& path, - DirectoryWatcher::Delegate* delegate, - MessageLoop* backend_loop, - bool recursive) { - DCHECK(path_.value().empty()); // Can only watch one path. - - DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); - - if (!file_util::PathExists(path)) - return false; - - path_ = path; - if (!file_util::AbsolutePath(&path_)) { - path_ = FilePath(); // Make sure we're marked as not-in-use. - return false; - } - delegate_ = delegate; - recursive_ = recursive; - - scoped_cftyperef<CFStringRef> cf_path(CFStringCreateWithCString( - NULL, path.value().c_str(), kCFStringEncodingMacHFS)); - CFStringRef path_for_array = cf_path.get(); - scoped_cftyperef<CFArrayRef> watched_paths(CFArrayCreate( - NULL, reinterpret_cast<const void**>(&path_for_array), 1, - &kCFTypeArrayCallBacks)); - - FSEventStreamContext context; - context.version = 0; - context.info = this; - context.retain = NULL; - context.release = NULL; - context.copyDescription = NULL; - - fsevent_stream_ = FSEventStreamCreate(NULL, &FSEventsCallback, &context, - watched_paths, - kFSEventStreamEventIdSinceNow, - kEventLatencySeconds, - kFSEventStreamCreateFlagNone); - FSEventStreamScheduleWithRunLoop(fsevent_stream_, CFRunLoopGetCurrent(), - kCFRunLoopDefaultMode); - FSEventStreamStart(fsevent_stream_); - - return true; -} - -} // namespace - -DirectoryWatcher::DirectoryWatcher() { - impl_ = new DirectoryWatcherImpl(); -} diff --git a/base/directory_watcher_stub.cc b/base/directory_watcher_stub.cc deleted file mode 100644 index 92cc5ff..0000000 --- a/base/directory_watcher_stub.cc +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2009 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. - -// This file exists for Linux systems which don't have the inotify headers, and -// thus cannot build directory_watcher_inotify.cc - -#include "base/directory_watcher.h" - -class DirectoryWatcherImpl : public DirectoryWatcher::PlatformDelegate { - public: - virtual bool Watch(const FilePath& path, DirectoryWatcher::Delegate* delegate, - MessageLoop* backend_loop, bool recursive) { - return false; - } -}; - -DirectoryWatcher::DirectoryWatcher() { - impl_ = new DirectoryWatcherImpl(); -} diff --git a/base/directory_watcher_unittest.cc b/base/directory_watcher_unittest.cc deleted file mode 100644 index 9d4c9f6..0000000 --- a/base/directory_watcher_unittest.cc +++ /dev/null @@ -1,426 +0,0 @@ -// Copyright (c) 2008 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 "base/directory_watcher.h" - -#include <limits> - -#include "base/basictypes.h" -#include "base/file_path.h" -#include "base/file_util.h" -#include "base/message_loop.h" -#include "base/path_service.h" -#include "base/platform_thread.h" -#include "base/string_util.h" -#include "base/thread.h" -#if defined(OS_WIN) -#include "base/win_util.h" -#endif // defined(OS_WIN) -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -// For tests where we wait a bit to verify nothing happened -const int kWaitForEventTime = 500; - -class DirectoryWatcherTest : public testing::Test { - public: - // Implementation of DirectoryWatcher on Mac requires UI loop. - DirectoryWatcherTest() - : loop_(MessageLoop::TYPE_UI), - notified_delegates_(0), - expected_notified_delegates_(0) { - } - - void OnTestDelegateFirstNotification(const FilePath& path) { - notified_delegates_++; - if (notified_delegates_ >= expected_notified_delegates_) - MessageLoop::current()->Quit(); - } - - protected: - virtual void SetUp() { - // Name a subdirectory of the temp directory. - FilePath path; - ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &path)); - test_dir_ = path.Append(FILE_PATH_LITERAL("DirectoryWatcherTest")); - - // Create a fresh, empty copy of this directory. - file_util::Delete(test_dir_, true); - file_util::CreateDirectory(test_dir_); - } - - virtual void TearDown() { - // Make sure there are no tasks in the loop. - loop_.RunAllPending(); - - // Clean up test directory. - ASSERT_TRUE(file_util::Delete(test_dir_, true)); - ASSERT_FALSE(file_util::PathExists(test_dir_)); - } - - // Write |content| to the |filename|. Returns true on success. - bool WriteTestFile(const FilePath& filename, - const std::string& content) { - return (file_util::WriteFile(filename, content.c_str(), content.length()) == - static_cast<int>(content.length())); - } - - // Create directory |name| under test_dir_. If |sync| is true, runs - // SyncIfPOSIX. Returns path to the created directory, including test_dir_. - FilePath CreateTestDirDirectoryASCII(const std::string& name, bool sync) { - FilePath path(test_dir_.AppendASCII(name)); - EXPECT_TRUE(file_util::CreateDirectory(path)); - if (sync) - SyncIfPOSIX(); - return path; - } - - void SetExpectedNumberOfNotifiedDelegates(int n) { - notified_delegates_ = 0; - expected_notified_delegates_ = n; - } - - void VerifyExpectedNumberOfNotifiedDelegates() { - // Check that we get at least the expected number of notified delegates. - if (expected_notified_delegates_ - notified_delegates_ > 0) - loop_.Run(); - EXPECT_EQ(expected_notified_delegates_, notified_delegates_); - } - - void VerifyNoExtraNotifications() { - // Check that we get no more than the expected number of notified delegates. - loop_.PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask, - kWaitForEventTime); - loop_.Run(); - EXPECT_EQ(expected_notified_delegates_, notified_delegates_); - } - - // We need this function for reliable tests on Mac OS X. FSEvents API - // has a latency interval and can merge multiple events into one, - // and we need a clear distinction between events triggered by test setup code - // and test code. - void SyncIfPOSIX() { -#if defined(OS_POSIX) - sync(); -#endif // defined(OS_POSIX) - } - - MessageLoop loop_; - - // The path to a temporary directory used for testing. - FilePath test_dir_; - - // The number of test delegates which received their notification. - int notified_delegates_; - - // The number of notified test delegates after which we quit the message loop. - int expected_notified_delegates_; -}; - -class TestDelegate : public DirectoryWatcher::Delegate { - public: - explicit TestDelegate(DirectoryWatcherTest* test) - : test_(test), - got_notification_(false), - original_thread_id_(PlatformThread::CurrentId()) { - } - - bool got_notification() const { - return got_notification_; - } - - void reset() { - got_notification_ = false; - } - - virtual void OnDirectoryChanged(const FilePath& path) { - EXPECT_EQ(original_thread_id_, PlatformThread::CurrentId()); - if (!got_notification_) - test_->OnTestDelegateFirstNotification(path); - got_notification_ = true; - } - - private: - // Hold a pointer to current test fixture to inform it on first notification. - DirectoryWatcherTest* test_; - - // Set to true after first notification. - bool got_notification_; - - // Keep track of original thread id to verify that callbacks are called - // on the same thread. - PlatformThreadId original_thread_id_; -}; - -// Basic test: add a file and verify we notice it. -TEST_F(DirectoryWatcherTest, NewFile) { - DirectoryWatcher watcher; - TestDelegate delegate(this); - ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, NULL, false)); - - SetExpectedNumberOfNotifiedDelegates(1); - ASSERT_TRUE(WriteTestFile(test_dir_.AppendASCII("test_file"), "content")); - VerifyExpectedNumberOfNotifiedDelegates(); -} - -// Verify that modifying a file is caught. -TEST_F(DirectoryWatcherTest, ModifiedFile) { - // Write a file to the test dir. - ASSERT_TRUE(WriteTestFile(test_dir_.AppendASCII("test_file"), "content")); - SyncIfPOSIX(); - - DirectoryWatcher watcher; - TestDelegate delegate(this); - ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, NULL, false)); - - // Now make sure we get notified if the file is modified. - SetExpectedNumberOfNotifiedDelegates(1); - ASSERT_TRUE(WriteTestFile(test_dir_.AppendASCII("test_file"), "new content")); - VerifyExpectedNumberOfNotifiedDelegates(); -} - -TEST_F(DirectoryWatcherTest, DeletedFile) { - // Write a file to the test dir. - ASSERT_TRUE(WriteTestFile(test_dir_.AppendASCII("test_file"), "content")); - SyncIfPOSIX(); - - DirectoryWatcher watcher; - TestDelegate delegate(this); - ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, NULL, false)); - - // Now make sure we get notified if the file is deleted. - SetExpectedNumberOfNotifiedDelegates(1); - ASSERT_TRUE(file_util::Delete(test_dir_.AppendASCII("test_file"), false)); - VerifyExpectedNumberOfNotifiedDelegates(); -} - -// Verify that letting the watcher go out of scope stops notifications. -TEST_F(DirectoryWatcherTest, Unregister) { - TestDelegate delegate(this); - - { - DirectoryWatcher watcher; - ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, NULL, false)); - - // And then let it fall out of scope, clearing its watch. - } - - // Write a file to the test dir. - SetExpectedNumberOfNotifiedDelegates(0); - ASSERT_TRUE(WriteTestFile(test_dir_.AppendASCII("test_file"), "content")); - VerifyExpectedNumberOfNotifiedDelegates(); - VerifyNoExtraNotifications(); -} - -TEST_F(DirectoryWatcherTest, SubDirRecursive) { - FilePath subdir(CreateTestDirDirectoryASCII("SubDir", true)); - - // Verify that modifications to a subdirectory are noticed by recursive watch. - TestDelegate delegate(this); - DirectoryWatcher watcher; - ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, NULL, true)); - // Write a file to the subdir. - SetExpectedNumberOfNotifiedDelegates(1); - ASSERT_TRUE(WriteTestFile(subdir.AppendASCII("test_file"), "some content")); - VerifyExpectedNumberOfNotifiedDelegates(); -} - -TEST_F(DirectoryWatcherTest, SubDirNonRecursive) { -#if defined(OS_WIN) - // Disable this test for earlier version of Windows. It turned out to be - // very difficult to create a reliable test for them. - if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) - return; -#endif // defined(OS_WIN) - - FilePath subdir(CreateTestDirDirectoryASCII("SubDir", false)); - - // Create a test file before the test. On Windows we get a notification - // when creating a file in a subdir even with a non-recursive watch. - ASSERT_TRUE(WriteTestFile(subdir.AppendASCII("test_file"), "some content")); - - SyncIfPOSIX(); - - // Verify that modifications to a subdirectory are not noticed - // by a not-recursive watch. - DirectoryWatcher watcher; - TestDelegate delegate(this); - ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, NULL, false)); - - // Modify the test file. There should be no notifications. - SetExpectedNumberOfNotifiedDelegates(0); - ASSERT_TRUE(WriteTestFile(subdir.AppendASCII("test_file"), "other content")); - VerifyExpectedNumberOfNotifiedDelegates(); - VerifyNoExtraNotifications(); -} - -namespace { -// Used by the DeleteDuringNotify test below. -// Deletes the DirectoryWatcher when it's notified. -class Deleter : public DirectoryWatcher::Delegate { - public: - Deleter(DirectoryWatcher* watcher, MessageLoop* loop) - : watcher_(watcher), - loop_(loop) { - } - - virtual void OnDirectoryChanged(const FilePath& path) { - watcher_.reset(NULL); - loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); - } - - scoped_ptr<DirectoryWatcher> watcher_; - MessageLoop* loop_; -}; -} // anonymous namespace - -// Verify that deleting a watcher during the callback -TEST_F(DirectoryWatcherTest, DeleteDuringNotify) { - DirectoryWatcher* watcher = new DirectoryWatcher; - Deleter deleter(watcher, &loop_); // Takes ownership of watcher. - ASSERT_TRUE(watcher->Watch(test_dir_, &deleter, NULL, false)); - - ASSERT_TRUE(WriteTestFile(test_dir_.AppendASCII("test_file"), "content")); - loop_.Run(); - - // We win if we haven't crashed yet. - // Might as well double-check it got deleted, too. - ASSERT_TRUE(deleter.watcher_.get() == NULL); -} - -TEST_F(DirectoryWatcherTest, BackendLoop) { - base::Thread thread("test"); - ASSERT_TRUE(thread.Start()); - - DirectoryWatcher watcher; - TestDelegate delegate(this); - ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, thread.message_loop(), - true)); -} - -TEST_F(DirectoryWatcherTest, MultipleWatchersSingleFile) { - DirectoryWatcher watcher1, watcher2; - TestDelegate delegate1(this), delegate2(this); - ASSERT_TRUE(watcher1.Watch(test_dir_, &delegate1, NULL, false)); - ASSERT_TRUE(watcher2.Watch(test_dir_, &delegate2, NULL, false)); - - SetExpectedNumberOfNotifiedDelegates(2); - ASSERT_TRUE(WriteTestFile(test_dir_.AppendASCII("test_file"), "content")); - VerifyExpectedNumberOfNotifiedDelegates(); -} - -TEST_F(DirectoryWatcherTest, MultipleWatchersDifferentFiles) { - const int kNumberOfWatchers = 3; - DirectoryWatcher watchers[kNumberOfWatchers]; - TestDelegate delegates[kNumberOfWatchers] = { - TestDelegate(this), - TestDelegate(this), - TestDelegate(this), - }; - FilePath subdirs[kNumberOfWatchers]; - for (int i = 0; i < kNumberOfWatchers; i++) { - subdirs[i] = CreateTestDirDirectoryASCII("Dir" + IntToString(i), false); - ASSERT_TRUE(watchers[i].Watch(subdirs[i], &delegates[i], - NULL, ((i % 2) == 0))); - } - for (int i = 0; i < kNumberOfWatchers; i++) { - // Verify that we only get modifications from one watcher (each watcher has - // different directory). - - for (int j = 0; j < kNumberOfWatchers; j++) - delegates[j].reset(); - - // Write a file to the subdir. - SetExpectedNumberOfNotifiedDelegates(1); - ASSERT_TRUE(WriteTestFile(subdirs[i].AppendASCII("test_file"), "content")); - VerifyExpectedNumberOfNotifiedDelegates(); - VerifyNoExtraNotifications(); - - loop_.RunAllPending(); - } -} - -#if defined(OS_WIN) || defined(OS_MACOSX) -// TODO(phajdan.jr): Enable when support for Linux recursive watches is added. - -TEST_F(DirectoryWatcherTest, WatchCreatedDirectory) { - TestDelegate delegate(this); - DirectoryWatcher watcher; - ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, NULL, true)); - - SetExpectedNumberOfNotifiedDelegates(1); - FilePath subdir(CreateTestDirDirectoryASCII("SubDir", true)); - VerifyExpectedNumberOfNotifiedDelegates(); - - delegate.reset(); - - // Verify that changes inside the subdir are noticed. - SetExpectedNumberOfNotifiedDelegates(1); - ASSERT_TRUE(WriteTestFile(subdir.AppendASCII("test_file"), "some content")); - VerifyExpectedNumberOfNotifiedDelegates(); -} - -TEST_F(DirectoryWatcherTest, RecursiveWatchDeletedSubdirectory) { - FilePath subdir(CreateTestDirDirectoryASCII("SubDir", true)); - - TestDelegate delegate(this); - DirectoryWatcher watcher; - ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, NULL, true)); - - // Write a file to the subdir. - SetExpectedNumberOfNotifiedDelegates(1); - ASSERT_TRUE(WriteTestFile(subdir.AppendASCII("test_file"), "some content")); - VerifyExpectedNumberOfNotifiedDelegates(); - - delegate.reset(); - - SetExpectedNumberOfNotifiedDelegates(1); - ASSERT_TRUE(file_util::Delete(subdir, true)); - VerifyExpectedNumberOfNotifiedDelegates(); -} - -TEST_F(DirectoryWatcherTest, MoveFileAcrossWatches) { - FilePath subdir1(CreateTestDirDirectoryASCII("SubDir1", true)); - FilePath subdir2(CreateTestDirDirectoryASCII("SubDir2", true)); - - TestDelegate delegate1(this), delegate2(this); - DirectoryWatcher watcher1, watcher2; - ASSERT_TRUE(watcher1.Watch(subdir1, &delegate1, NULL, true)); - ASSERT_TRUE(watcher2.Watch(subdir2, &delegate2, NULL, true)); - - SetExpectedNumberOfNotifiedDelegates(1); - ASSERT_TRUE(WriteTestFile(subdir1.AppendASCII("file"), "some content")); - SyncIfPOSIX(); - VerifyExpectedNumberOfNotifiedDelegates(); - VerifyNoExtraNotifications(); - - delegate1.reset(); - delegate2.reset(); - - SetExpectedNumberOfNotifiedDelegates(2); - ASSERT_TRUE(file_util::Move(subdir1.AppendASCII("file"), - subdir2.AppendASCII("file"))); - VerifyExpectedNumberOfNotifiedDelegates(); - - delegate1.reset(); - delegate2.reset(); - - SetExpectedNumberOfNotifiedDelegates(1); - ASSERT_TRUE(WriteTestFile(subdir2.AppendASCII("file"), "other content")); - VerifyExpectedNumberOfNotifiedDelegates(); - VerifyNoExtraNotifications(); -} -#endif // defined(OS_WIN) || defined(OS_MACOSX) - -// Verify that watching a directory that doesn't exist fails, but doesn't -// asssert. -// Basic test: add a file and verify we notice it. -TEST_F(DirectoryWatcherTest, NonExistentDirectory) { - DirectoryWatcher watcher; - ASSERT_FALSE(watcher.Watch(test_dir_.AppendASCII("does-not-exist"), - NULL, NULL, false)); -} - -} // namespace diff --git a/base/directory_watcher_win.cc b/base/directory_watcher_win.cc deleted file mode 100644 index e318d4b..0000000 --- a/base/directory_watcher_win.cc +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (c) 2009 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 "base/directory_watcher.h" - -#include "base/file_path.h" -#include "base/logging.h" -#include "base/object_watcher.h" -#include "base/ref_counted.h" - -namespace { - -class DirectoryWatcherImpl : public DirectoryWatcher::PlatformDelegate, - public base::ObjectWatcher::Delegate { - public: - DirectoryWatcherImpl() : delegate_(NULL), handle_(INVALID_HANDLE_VALUE) {} - - virtual bool Watch(const FilePath& path, DirectoryWatcher::Delegate* delegate, - MessageLoop* backend_loop, bool recursive); - - // Callback from MessageLoopForIO. - virtual void OnObjectSignaled(HANDLE object); - - private: - virtual ~DirectoryWatcherImpl(); - - // Delegate to notify upon changes. - DirectoryWatcher::Delegate* delegate_; - // Path we're watching (passed to delegate). - FilePath path_; - // Handle for FindFirstChangeNotification. - HANDLE handle_; - // ObjectWatcher to watch handle_ for events. - base::ObjectWatcher watcher_; - - DISALLOW_COPY_AND_ASSIGN(DirectoryWatcherImpl); -}; - -DirectoryWatcherImpl::~DirectoryWatcherImpl() { - if (handle_ != INVALID_HANDLE_VALUE) { - watcher_.StopWatching(); - FindCloseChangeNotification(handle_); - } -} - -bool DirectoryWatcherImpl::Watch(const FilePath& path, - DirectoryWatcher::Delegate* delegate, - MessageLoop* backend_loop, bool recursive) { - DCHECK(path_.value().empty()); // Can only watch one path. - - handle_ = FindFirstChangeNotification( - path.value().c_str(), - recursive, - FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_SIZE | - FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_DIR_NAME); - if (handle_ == INVALID_HANDLE_VALUE) - return false; - - delegate_ = delegate; - path_ = path; - watcher_.StartWatching(handle_, this); - - return true; -} - -void DirectoryWatcherImpl::OnObjectSignaled(HANDLE object) { - DCHECK(object == handle_); - // Make sure we stay alive through the body of this function. - scoped_refptr<DirectoryWatcherImpl> keep_alive(this); - - delegate_->OnDirectoryChanged(path_); - - // Register for more notifications on file change. - BOOL ok = FindNextChangeNotification(object); - DCHECK(ok); - watcher_.StartWatching(object, this); -} - -} // namespace - -DirectoryWatcher::DirectoryWatcher() { - impl_ = new DirectoryWatcherImpl(); -} diff --git a/base/mac_util_unittest.mm b/base/mac_util_unittest.mm index 801922a..b77472b 100644 --- a/base/mac_util_unittest.mm +++ b/base/mac_util_unittest.mm @@ -7,6 +7,7 @@ #include "base/mac_util.h" +#import "base/chrome_application_mac.h" #include "base/file_path.h" #include "base/file_util.h" #include "base/scoped_cftyperef.h" @@ -53,7 +54,7 @@ TEST_F(MacUtilTest, TestLibraryPath) { TEST_F(MacUtilTest, TestGrabWindowSnapshot) { // Launch a test window so we can take a snapshot. - [NSApplication sharedApplication]; + [CrApplication sharedApplication]; NSRect frame = NSMakeRect(0, 0, 400, 400); scoped_nsobject<NSWindow> window( [[NSWindow alloc] initWithContentRect:frame diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index e284f69..82bd20b 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -2242,14 +2242,13 @@ void AutomationProvider::InstallExtension(const FilePath& crx_path, void AutomationProvider::LoadExpandedExtension( const FilePath& extension_dir, IPC::Message* reply_message) { - if (profile_->GetExtensionsService() && profile_->GetUserScriptMaster()) { + if (profile_->GetExtensionsService()) { // The observer will delete itself when done. new ExtensionNotificationObserver(this, AutomationMsg_LoadExpandedExtension::ID, reply_message); profile_->GetExtensionsService()->LoadExtension(extension_dir); - profile_->GetUserScriptMaster()->AddWatchedPath(extension_dir); } else { AutomationMsg_LoadExpandedExtension::WriteReplyParams( reply_message, AUTOMATION_MSG_EXTENSION_INSTALL_FAILED); diff --git a/chrome/browser/extensions/user_script_master.cc b/chrome/browser/extensions/user_script_master.cc index d142e0a..3478b68 100644 --- a/chrome/browser/extensions/user_script_master.cc +++ b/chrome/browser/extensions/user_script_master.cc @@ -289,9 +289,6 @@ UserScriptMaster::UserScriptMaster(const FilePath& script_dir, Profile* profile) extensions_service_ready_(false), pending_scan_(false), profile_(profile) { - if (!user_script_dir_.value().empty()) - AddWatchedPath(script_dir); - registrar_.Add(this, NotificationType::EXTENSIONS_READY, Source<Profile>(profile_)); registrar_.Add(this, NotificationType::EXTENSION_LOADED, @@ -303,22 +300,6 @@ UserScriptMaster::UserScriptMaster(const FilePath& script_dir, Profile* profile) UserScriptMaster::~UserScriptMaster() { if (script_reloader_) script_reloader_->DisownMaster(); - -// TODO(aa): Enable this when DirectoryWatcher is implemented for linux. -#if defined(OS_WIN) || defined(OS_MACOSX) - STLDeleteElements(&dir_watchers_); -#endif -} - -void UserScriptMaster::AddWatchedPath(const FilePath& path) { -// TODO(aa): Enable this when DirectoryWatcher is implemented for linux. -#if defined(OS_WIN) || defined(OS_MACOSX) - DirectoryWatcher* watcher = new DirectoryWatcher(); - base::Thread* file_thread = g_browser_process->file_thread(); - watcher->Watch(path, this, file_thread ? file_thread->message_loop() : NULL, - true); - dir_watchers_.push_back(watcher); -#endif } void UserScriptMaster::NewScriptsAvailable(base::SharedMemory* handle) { @@ -343,17 +324,6 @@ void UserScriptMaster::NewScriptsAvailable(base::SharedMemory* handle) { } } -void UserScriptMaster::OnDirectoryChanged(const FilePath& path) { - if (script_reloader_.get()) { - // We're already scanning for scripts. We note that we should rescan when - // we get the chance. - pending_scan_ = true; - return; - } - - StartScan(); -} - void UserScriptMaster::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { diff --git a/chrome/browser/extensions/user_script_master.h b/chrome/browser/extensions/user_script_master.h index 3a7afd5..645e91d 100644 --- a/chrome/browser/extensions/user_script_master.h +++ b/chrome/browser/extensions/user_script_master.h @@ -5,9 +5,6 @@ #ifndef CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_ #define CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_ -#include <vector> - -#include "base/directory_watcher.h" #include "base/file_path.h" #include "base/scoped_ptr.h" #include "base/shared_memory.h" @@ -24,17 +21,12 @@ class StringPiece; // Manages a segment of shared memory that contains the user scripts the user // has installed. Lives on the UI thread. class UserScriptMaster : public base::RefCountedThreadSafe<UserScriptMaster>, - public DirectoryWatcher::Delegate, public NotificationObserver { public: // For testability, the constructor takes the path the scripts live in. // This is normally a directory inside the profile. explicit UserScriptMaster(const FilePath& script_dir, Profile* profile); - // Add a watched directory. All scripts will be reloaded when any file in - // this directory changes. - void AddWatchedPath(const FilePath& path); - // Kicks off a process on the file thread to reload scripts from disk // into a new chunk of shared memory and notify renderers. virtual void StartScan(); @@ -129,9 +121,6 @@ class UserScriptMaster : public base::RefCountedThreadSafe<UserScriptMaster>, }; private: - // DirectoryWatcher::Delegate implementation. - virtual void OnDirectoryChanged(const FilePath& path); - // NotificationObserver implementation. virtual void Observe(NotificationType type, const NotificationSource& source, @@ -143,10 +132,6 @@ class UserScriptMaster : public base::RefCountedThreadSafe<UserScriptMaster>, // The directories containing user scripts. FilePath user_script_dir_; - // The watcher watches the profile's user scripts directory for new scripts. - std::vector<DirectoryWatcher*> dir_watchers_; - - // ScriptReloader (in another thread) reloads script off disk. // We hang on to our pointer to know if we've already got one running. scoped_refptr<ScriptReloader> script_reloader_; diff --git a/chrome/browser/extensions/user_script_master_unittest.cc b/chrome/browser/extensions/user_script_master_unittest.cc index ef5ac2f..ec8c728 100644 --- a/chrome/browser/extensions/user_script_master_unittest.cc +++ b/chrome/browser/extensions/user_script_master_unittest.cc @@ -91,30 +91,6 @@ TEST_F(UserScriptMasterTest, NoScripts) { ASSERT_TRUE(shared_memory_ != NULL); } -// TODO(shess): Disabled on Linux because of missing DirectoryWatcher. -#if defined(OS_WIN) || defined(OS_MACOSX) -// Test that we get notified about new scripts after they're added. -TEST_F(UserScriptMasterTest, NewScripts) { - TestingProfile profile; - scoped_refptr<UserScriptMaster> master(new UserScriptMaster(script_dir_, - &profile)); - - FilePath path = script_dir_.AppendASCII("script.user.js"); - - const char content[] = "some content"; - size_t written = file_util::WriteFile(path, content, sizeof(content)); - ASSERT_EQ(written, sizeof(content)); - - // Post a delayed task so that we fail rather than hanging if things - // don't work. - message_loop_.PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask, 5000); - - message_loop_.Run(); - - ASSERT_TRUE(shared_memory_ != NULL); -} -#endif - // Test that we get notified about scripts if they're already in the test dir. TEST_F(UserScriptMasterTest, ExistingScripts) { TestingProfile profile; diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index e46cb81..63b8c1d 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -672,10 +672,6 @@ void ProfileImpl::InitExtensions() { if (command_line->HasSwitch(switches::kLoadExtension)) { FilePath path = command_line->GetSwitchValuePath(switches::kLoadExtension); extensions_service_->LoadExtension(path); - - // Tell UserScriptMaser to watch this extension's directory for changes so - // you can live edit content scripts during development. - user_script_master_->AddWatchedPath(path); } } |