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

Side by Side Diff: chrome/browser/media_galleries/fileapi/data_provider_helper.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/data_provider_helper.h"
6
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "base/format_macros.h"
vandebo (ex-Chrome) 2013/08/29 23:19:22 What's this for?
tommycli 2013/09/03 20:20:43 Done.
10 #include "base/location.h"
11 #include "base/logging.h"
12 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
13 #include "content/public/browser/browser_thread.h"
14
15 namespace chrome {
16
17 namespace {
18
19 // Bounces |path| and |error| to |callback| from the FILE thread to the media
20 // task runner.
21 void OnFilePathChangedOnFileThread(
22 const base::FilePathWatcher::Callback& callback,
23 const base::FilePath& path,
24 bool error) {
25 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
26 MediaFileSystemBackend::MediaTaskRunner()
27 ->PostTask(FROM_HERE, base::Bind(callback, path, error));
vandebo (ex-Chrome) 2013/08/29 23:19:22 nit: PostTask( on the previous line.
tommycli 2013/09/03 20:20:43 Done.
28 }
29
30 // The watch has to be started on the FILE thread, and the callback called by
31 // the FilePathWatcher also needs to run on the FILE thread.
32 void StartFilePathWatchOnFileThread(
33 const base::FilePath& path,
34 bool recursive,
35 const FileWatchStartedCallback& watch_started_callback,
36 const base::FilePathWatcher::Callback& path_changed_callback) {
37 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
38 // The watcher is created on the FILE thread because it is very difficult
39 // to safely pass an already-created file watcher to a different thread.
40 scoped_ptr<base::FilePathWatcher> watcher(new base::FilePathWatcher);
41 bool success = watcher->Watch(
42 path,
43 recursive,
44 base::Bind(&OnFilePathChangedOnFileThread, path_changed_callback));
45 if (!success)
46 LOG(ERROR) << "Adding watch for " << path.value() << " failed";
47 MediaFileSystemBackend::MediaTaskRunner()->PostTask(
48 FROM_HERE, base::Bind(watch_started_callback, base::Passed(&watcher)));
49 }
50
51 } // namespace
52
53 void StartFilePathWatchOnMediaTaskRunner(
54 const base::FilePath& path,
55 bool recursive,
56 const FileWatchStartedCallback& watch_started_callback,
57 const base::FilePathWatcher::Callback& path_changed_callback) {
58 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread());
59 content::BrowserThread::PostTask(content::BrowserThread::FILE,
60 FROM_HERE,
61 base::Bind(&StartFilePathWatchOnFileThread,
62 path,
63 recursive,
64 watch_started_callback,
65 path_changed_callback));
66 }
67
68 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698