| OLD | NEW |
| 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 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "storage/browser/fileapi/native_file_util.h" | 21 #include "storage/browser/fileapi/native_file_util.h" |
| 22 #include "third_party/icu/source/common/unicode/locid.h" | 22 #include "third_party/icu/source/common/unicode/locid.h" |
| 23 | 23 |
| 24 namespace iapps { | 24 namespace iapps { |
| 25 | 25 |
| 26 IAppsDataProvider::IAppsDataProvider(const base::FilePath& library_path) | 26 IAppsDataProvider::IAppsDataProvider(const base::FilePath& library_path) |
| 27 : library_path_(library_path), | 27 : library_path_(library_path), |
| 28 needs_refresh_(true), | 28 needs_refresh_(true), |
| 29 is_valid_(false), | 29 is_valid_(false), |
| 30 weak_factory_(this) { | 30 weak_factory_(this) { |
| 31 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 31 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
| 32 DCHECK(!library_path_.empty()); | 32 DCHECK(!library_path_.empty()); |
| 33 | 33 |
| 34 StartFilePathWatchOnMediaTaskRunner( | 34 StartFilePathWatchOnMediaTaskRunner( |
| 35 library_path_, | 35 library_path_, |
| 36 base::Bind(&IAppsDataProvider::OnLibraryWatchStarted, | 36 base::Bind(&IAppsDataProvider::OnLibraryWatchStarted, |
| 37 weak_factory_.GetWeakPtr()), | 37 weak_factory_.GetWeakPtr()), |
| 38 base::Bind(&IAppsDataProvider::OnLibraryChanged, | 38 base::Bind(&IAppsDataProvider::OnLibraryChanged, |
| 39 weak_factory_.GetWeakPtr())); | 39 weak_factory_.GetWeakPtr())); |
| 40 } | 40 } |
| 41 | 41 |
| 42 IAppsDataProvider::~IAppsDataProvider() {} | 42 IAppsDataProvider::~IAppsDataProvider() {} |
| 43 | 43 |
| 44 bool IAppsDataProvider::valid() const { | 44 bool IAppsDataProvider::valid() const { |
| 45 return is_valid_; | 45 return is_valid_; |
| 46 } | 46 } |
| 47 | 47 |
| 48 void IAppsDataProvider::set_valid(bool valid) { | 48 void IAppsDataProvider::set_valid(bool valid) { |
| 49 is_valid_ = valid; | 49 is_valid_ = valid; |
| 50 } | 50 } |
| 51 | 51 |
| 52 void IAppsDataProvider::RefreshData(const ReadyCallback& ready_callback) { | 52 void IAppsDataProvider::RefreshData(const ReadyCallback& ready_callback) { |
| 53 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 53 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
| 54 if (!needs_refresh_) { | 54 if (!needs_refresh_) { |
| 55 ready_callback.Run(valid()); | 55 ready_callback.Run(valid()); |
| 56 return; | 56 return; |
| 57 } | 57 } |
| 58 | 58 |
| 59 // TODO(gbillock): this needs re-examination. Could be a refresh bug. | 59 // TODO(gbillock): this needs re-examination. Could be a refresh bug. |
| 60 needs_refresh_ = false; | 60 needs_refresh_ = false; |
| 61 DoParseLibrary(library_path_, ready_callback); | 61 DoParseLibrary(library_path_, ready_callback); |
| 62 } | 62 } |
| 63 | 63 |
| 64 const base::FilePath& IAppsDataProvider::library_path() const { | 64 const base::FilePath& IAppsDataProvider::library_path() const { |
| 65 return library_path_; | 65 return library_path_; |
| 66 } | 66 } |
| 67 | 67 |
| 68 void IAppsDataProvider::OnLibraryWatchStarted( | 68 void IAppsDataProvider::OnLibraryWatchStarted( |
| 69 std::unique_ptr<base::FilePathWatcher> library_watcher) { | 69 std::unique_ptr<base::FilePathWatcher> library_watcher) { |
| 70 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 70 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
| 71 library_watcher_.reset(library_watcher.release()); | 71 library_watcher_.reset(library_watcher.release()); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void IAppsDataProvider::OnLibraryChanged(const base::FilePath& path, | 74 void IAppsDataProvider::OnLibraryChanged(const base::FilePath& path, |
| 75 bool error) { | 75 bool error) { |
| 76 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 76 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
| 77 DCHECK_EQ(library_path_.value(), path.value()); | 77 DCHECK_EQ(library_path_.value(), path.value()); |
| 78 if (error) | 78 if (error) |
| 79 LOG(ERROR) << "Error watching " << library_path_.value(); | 79 LOG(ERROR) << "Error watching " << library_path_.value(); |
| 80 needs_refresh_ = true; | 80 needs_refresh_ = true; |
| 81 } | 81 } |
| 82 | 82 |
| 83 } // namespace iapps | 83 } // namespace iapps |
| OLD | NEW |