Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(499)

Side by Side Diff: chrome/browser/media_galleries/fileapi/file_path_watcher_util.cc

Issue 23499006: Media Galleries API Picasa: Add file watch to invalidate database data on disk write. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/media_galleries/fileapi/file_path_watcher_util.h"
6
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "base/location.h"
10 #include "base/logging.h"
11 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
12 #include "content/public/browser/browser_thread.h"
13
14 namespace chrome {
15
16 namespace {
17
18 // Bounces |path| and |error| to |callback| from the FILE thread to the media
19 // task runner.
20 void OnFilePathChangedOnFileThread(
21 const base::FilePathWatcher::Callback& callback,
22 const base::FilePath& path,
23 bool error) {
24 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
25 MediaFileSystemBackend::MediaTaskRunner()->PostTask(
26 FROM_HERE, base::Bind(callback, path, error));
27 }
28
29 // The watch has to be started on the FILE thread, and the callback called by
30 // the FilePathWatcher also needs to run on the FILE thread.
31 void StartFilePathWatchOnFileThread(
32 const base::FilePath& path,
33 const FileWatchStartedCallback& watch_started_callback,
34 const base::FilePathWatcher::Callback& path_changed_callback) {
35 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
36 // The watcher is created on the FILE thread because it is very difficult
37 // to safely pass an already-created file watcher to a different thread.
38 scoped_ptr<base::FilePathWatcher> watcher(new base::FilePathWatcher);
39 bool success = watcher->Watch(
40 path,
41 false /* recursive */,
42 base::Bind(&OnFilePathChangedOnFileThread, path_changed_callback));
43 if (!success)
44 LOG(ERROR) << "Adding watch for " << path.value() << " failed";
45 MediaFileSystemBackend::MediaTaskRunner()->PostTask(
46 FROM_HERE, base::Bind(watch_started_callback, base::Passed(&watcher)));
47 }
48
49 } // namespace
50
51 void StartFilePathWatchOnMediaTaskRunner(
52 const base::FilePath& path,
53 const FileWatchStartedCallback& watch_started_callback,
54 const base::FilePathWatcher::Callback& path_changed_callback) {
55 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread());
56 content::BrowserThread::PostTask(content::BrowserThread::FILE,
57 FROM_HERE,
58 base::Bind(&StartFilePathWatchOnFileThread,
59 path,
60 watch_started_callback,
61 path_changed_callback));
62 }
63
64 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698