1 // Copyright (c) 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 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_ITUNES_FINDER_H_ 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_ITUNES_FINDER_H_ 7 8 #include <string> 9 10 #include "base/callback.h" 11 12 namespace itunes { 13 14 typedef base::Callback<void(const std::string&)> ITunesFinderCallback; 15 16 // ITunesFinder looks for the iTunes library in an asynchronous manner and 17 // calls the given ITunesFinderCallback on the UI thread as soon as it knows 18 // the result. If an iTunes library exists, the ITunesFinderCallback gets the 19 // device id for the library. If an iTunes library does not exist, or the OS 20 // does not support iTunes, then the callback result is an empty string. 21 // In either case, the class deletes itself. 22 class ITunesFinder { 23 public: 24 virtual ~ITunesFinder(); 25 26 // |callback| runs on the UI thread. 27 static void FindITunesLibrary(const ITunesFinderCallback& callback); 28 29 protected: 30 explicit ITunesFinder(const ITunesFinderCallback& callback); 31 32 // Called on the FILE thread. Bounces |unique_id| back to the UI thread. 33 void PostResultToUIThread(const std::string& unique_id); 34 35 private: 36 // Per-OS implementation; always calls PostResultToUIThread() when complete, 37 // with a unique id argument on success or empty string on failure. 38 virtual void FindITunesLibraryOnFileThread() = 0; 39 40 // Converts |unique_id| to a media device id and passes it to |callback_|. 41 void FinishOnUIThread(const std::string& unique_id) const; 42 43 // Only accessed on the UI thread. 44 const ITunesFinderCallback callback_; 45 46 DISALLOW_COPY_AND_ASSIGN(ITunesFinder); 47 }; 48 49 } // namespace itunes 50 51 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_ITUNES_FINDER_H_ 52