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

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

Issue 2518053002: Always delete media galleries FilePathWatchers on the FILE thread. (Closed)
Patch Set: fix build error Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/media_galleries/fileapi/iapps_data_provider.h" 5 #include "chrome/browser/media_galleries/fileapi/iapps_data_provider.h"
6 6
7 #include <map> 7 #include <map>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/format_macros.h" 12 #include "base/format_macros.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/threading/thread_restrictions.h" 17 #include "base/threading/thread_restrictions.h"
18 #include "chrome/browser/media_galleries/fileapi/file_path_watcher_util.h"
19 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" 18 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
20 #include "chrome/common/media_galleries/itunes_library.h" 19 #include "chrome/common/media_galleries/itunes_library.h"
21 #include "storage/browser/fileapi/native_file_util.h" 20 #include "storage/browser/fileapi/native_file_util.h"
22 #include "third_party/icu/source/common/unicode/locid.h" 21 #include "third_party/icu/source/common/unicode/locid.h"
23 22
24 namespace iapps { 23 namespace iapps {
25 24
26 IAppsDataProvider::IAppsDataProvider(const base::FilePath& library_path) 25 IAppsDataProvider::IAppsDataProvider(const base::FilePath& library_path)
27 : library_path_(library_path), 26 : library_path_(library_path),
28 needs_refresh_(true), 27 needs_refresh_(true),
29 is_valid_(false), 28 is_valid_(false),
30 weak_factory_(this) { 29 weak_factory_(this) {
31 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); 30 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence();
32 DCHECK(!library_path_.empty()); 31 DCHECK(!library_path_.empty());
33 32
34 StartFilePathWatchOnMediaTaskRunner( 33 StartFilePathWatchOnMediaTaskRunner(
35 library_path_, 34 library_path_,
36 base::Bind(&IAppsDataProvider::OnLibraryWatchStarted, 35 base::Bind(&IAppsDataProvider::OnLibraryWatchStarted,
37 weak_factory_.GetWeakPtr()), 36 weak_factory_.GetWeakPtr()),
38 base::Bind(&IAppsDataProvider::OnLibraryChanged, 37 base::Bind(&IAppsDataProvider::OnLibraryChanged,
39 weak_factory_.GetWeakPtr())); 38 weak_factory_.GetWeakPtr()));
40 } 39 }
41 40
42 IAppsDataProvider::~IAppsDataProvider() { 41 IAppsDataProvider::~IAppsDataProvider() {}
43 StopFilePathWatchOnMediaTaskRunner(std::move(library_watcher_));
44 }
45 42
46 bool IAppsDataProvider::valid() const { 43 bool IAppsDataProvider::valid() const {
47 return is_valid_; 44 return is_valid_;
48 } 45 }
49 46
50 void IAppsDataProvider::set_valid(bool valid) { 47 void IAppsDataProvider::set_valid(bool valid) {
51 is_valid_ = valid; 48 is_valid_ = valid;
52 } 49 }
53 50
54 void IAppsDataProvider::RefreshData(const ReadyCallback& ready_callback) { 51 void IAppsDataProvider::RefreshData(const ReadyCallback& ready_callback) {
55 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); 52 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence();
56 if (!needs_refresh_) { 53 if (!needs_refresh_) {
57 ready_callback.Run(valid()); 54 ready_callback.Run(valid());
58 return; 55 return;
59 } 56 }
60 57
61 // TODO(gbillock): this needs re-examination. Could be a refresh bug. 58 // TODO(gbillock): this needs re-examination. Could be a refresh bug.
62 needs_refresh_ = false; 59 needs_refresh_ = false;
63 DoParseLibrary(library_path_, ready_callback); 60 DoParseLibrary(library_path_, ready_callback);
64 } 61 }
65 62
66 const base::FilePath& IAppsDataProvider::library_path() const { 63 const base::FilePath& IAppsDataProvider::library_path() const {
67 return library_path_; 64 return library_path_;
68 } 65 }
69 66
70 void IAppsDataProvider::OnLibraryWatchStarted( 67 void IAppsDataProvider::OnLibraryWatchStarted(
71 std::unique_ptr<base::FilePathWatcher> library_watcher) { 68 MediaFilePathWatcherUniquePtr library_watcher) {
72 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); 69 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence();
73 library_watcher_ = std::move(library_watcher); 70 library_watcher_ = std::move(library_watcher);
74 } 71 }
75 72
76 void IAppsDataProvider::OnLibraryChanged(const base::FilePath& path, 73 void IAppsDataProvider::OnLibraryChanged(const base::FilePath& path,
77 bool error) { 74 bool error) {
78 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); 75 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence();
79 DCHECK_EQ(library_path_.value(), path.value()); 76 DCHECK_EQ(library_path_.value(), path.value());
80 if (error) 77 if (error)
81 LOG(ERROR) << "Error watching " << library_path_.value(); 78 LOG(ERROR) << "Error watching " << library_path_.value();
82 needs_refresh_ = true; 79 needs_refresh_ = true;
83 } 80 }
84 81
85 } // namespace iapps 82 } // namespace iapps
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698