| 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/safe_itunes_library_parser.h" | 5 #include "chrome/browser/media_galleries/fileapi/safe_itunes_library_parser.h" |
| 6 | 6 |
| 7 #include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_p
rovider.h" | 7 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
| 8 #include "chrome/common/chrome_utility_messages.h" | 8 #include "chrome/common/chrome_utility_messages.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "content/public/browser/child_process_data.h" | 10 #include "content/public/browser/child_process_data.h" |
| 11 #include "ipc/ipc_platform_file.h" | 11 #include "ipc/ipc_platform_file.h" |
| 12 | 12 |
| 13 using chrome::MediaFileSystemMountPointProvider; | 13 using chrome::MediaFileSystemBackend; |
| 14 using content::BrowserThread; | 14 using content::BrowserThread; |
| 15 using content::UtilityProcessHost; | 15 using content::UtilityProcessHost; |
| 16 | 16 |
| 17 namespace itunes { | 17 namespace itunes { |
| 18 | 18 |
| 19 SafeITunesLibraryParser::SafeITunesLibraryParser( | 19 SafeITunesLibraryParser::SafeITunesLibraryParser( |
| 20 const base::FilePath& itunes_library_file, | 20 const base::FilePath& itunes_library_file, |
| 21 const ParserCallback& callback) | 21 const ParserCallback& callback) |
| 22 : itunes_library_file_(itunes_library_file), | 22 : itunes_library_file_(itunes_library_file), |
| 23 callback_(callback), | 23 callback_(callback), |
| 24 parser_state_(INITIAL_STATE) {} | 24 parser_state_(INITIAL_STATE) {} |
| 25 | 25 |
| 26 void SafeITunesLibraryParser::Start() { | 26 void SafeITunesLibraryParser::Start() { |
| 27 DCHECK(MediaFileSystemMountPointProvider::CurrentlyOnMediaTaskRunnerThread()); | 27 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
| 28 | 28 |
| 29 // |itunes_library_platform_file_| will be closed on the IO thread once it | 29 // |itunes_library_platform_file_| will be closed on the IO thread once it |
| 30 // has been handed off to the child process. | 30 // has been handed off to the child process. |
| 31 itunes_library_platform_file_ = base::CreatePlatformFile( | 31 itunes_library_platform_file_ = base::CreatePlatformFile( |
| 32 itunes_library_file_, | 32 itunes_library_file_, |
| 33 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, | 33 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, |
| 34 NULL, // created | 34 NULL, // created |
| 35 NULL); // error_code | 35 NULL); // error_code |
| 36 if (itunes_library_platform_file_ == base::kInvalidPlatformFileValue) { | 36 if (itunes_library_platform_file_ == base::kInvalidPlatformFileValue) { |
| 37 VLOG(1) << "Could not open iTunes library XML file: " | 37 VLOG(1) << "Could not open iTunes library XML file: " |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 parser_state_ = STARTED_PARSING_STATE; | 80 parser_state_ = STARTED_PARSING_STATE; |
| 81 } | 81 } |
| 82 | 82 |
| 83 void SafeITunesLibraryParser::OnGotITunesLibrary( | 83 void SafeITunesLibraryParser::OnGotITunesLibrary( |
| 84 bool result, const parser::Library& library) { | 84 bool result, const parser::Library& library) { |
| 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 86 | 86 |
| 87 if (parser_state_ != STARTED_PARSING_STATE) | 87 if (parser_state_ != STARTED_PARSING_STATE) |
| 88 return; | 88 return; |
| 89 | 89 |
| 90 MediaFileSystemMountPointProvider::MediaTaskRunner()->PostTask( | 90 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
| 91 FROM_HERE, | 91 FROM_HERE, |
| 92 base::Bind(callback_, result, library)); | 92 base::Bind(callback_, result, library)); |
| 93 parser_state_ = FINISHED_PARSING_STATE; | 93 parser_state_ = FINISHED_PARSING_STATE; |
| 94 } | 94 } |
| 95 | 95 |
| 96 void SafeITunesLibraryParser::OnOpenLibraryFileFailed() { | 96 void SafeITunesLibraryParser::OnOpenLibraryFileFailed() { |
| 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 98 parser_state_ = FINISHED_PARSING_STATE; | 98 parser_state_ = FINISHED_PARSING_STATE; |
| 99 } | 99 } |
| 100 | 100 |
| 101 void SafeITunesLibraryParser::OnProcessCrashed(int exit_code) { | 101 void SafeITunesLibraryParser::OnProcessCrashed(int exit_code) { |
| 102 OnGotITunesLibrary(false /* failed */, parser::Library()); | 102 OnGotITunesLibrary(false /* failed */, parser::Library()); |
| 103 } | 103 } |
| 104 | 104 |
| 105 bool SafeITunesLibraryParser::OnMessageReceived( | 105 bool SafeITunesLibraryParser::OnMessageReceived( |
| 106 const IPC::Message& message) { | 106 const IPC::Message& message) { |
| 107 bool handled = true; | 107 bool handled = true; |
| 108 IPC_BEGIN_MESSAGE_MAP(SafeITunesLibraryParser, message) | 108 IPC_BEGIN_MESSAGE_MAP(SafeITunesLibraryParser, message) |
| 109 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ProcessStarted, | 109 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ProcessStarted, |
| 110 OnUtilityProcessStarted) | 110 OnUtilityProcessStarted) |
| 111 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GotITunesLibrary, | 111 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GotITunesLibrary, |
| 112 OnGotITunesLibrary) | 112 OnGotITunesLibrary) |
| 113 IPC_MESSAGE_UNHANDLED(handled = false) | 113 IPC_MESSAGE_UNHANDLED(handled = false) |
| 114 IPC_END_MESSAGE_MAP() | 114 IPC_END_MESSAGE_MAP() |
| 115 return handled; | 115 return handled; |
| 116 } | 116 } |
| 117 | 117 |
| 118 } // namespace itunes | 118 } // namespace itunes |
| OLD | NEW |