Chromium Code Reviews| Index: chrome/browser/media_galleries/fileapi/safe_picasa_albums_indexer.cc |
| diff --git a/chrome/browser/media_galleries/fileapi/safe_picasa_album_table_reader.cc b/chrome/browser/media_galleries/fileapi/safe_picasa_albums_indexer.cc |
| similarity index 30% |
| copy from chrome/browser/media_galleries/fileapi/safe_picasa_album_table_reader.cc |
| copy to chrome/browser/media_galleries/fileapi/safe_picasa_albums_indexer.cc |
| index 667303c5ad15fae7b5b6cbf9ca2352f3c7fd455c..a069b654c6ad6a2eafd5fd583c16ed8e420a1c4b 100644 |
| --- a/chrome/browser/media_galleries/fileapi/safe_picasa_album_table_reader.cc |
| +++ b/chrome/browser/media_galleries/fileapi/safe_picasa_albums_indexer.cc |
| @@ -2,122 +2,110 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "chrome/browser/media_galleries/fileapi/safe_picasa_album_table_reader.h" |
| +#include "chrome/browser/media_galleries/fileapi/safe_picasa_albums_indexer.h" |
| +#include "base/file_util.h" |
| #include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.h" |
| #include "chrome/common/chrome_utility_messages.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/child_process_data.h" |
| +#include "content/public/browser/utility_process_host.h" |
| using chrome::MediaFileSystemMountPointProvider; |
| using content::BrowserThread; |
| +using content::UtilityProcessHost; |
| namespace picasa { |
| -SafePicasaAlbumTableReader::SafePicasaAlbumTableReader( |
| - const AlbumTableFiles& album_table_files, |
| +namespace { |
| + |
| +// Picasa INI files are named either ".picasa.ini" OR "picasa.ini" for |
|
Lei Zhang
2013/07/02 22:08:17
This sentence is a bit hard to parse. I think you
tommycli
2013/07/03 00:58:28
Done.
|
| +// Windows versions before 71.18. |
| +// See: https://support.google.com/picasa/answer/11257?hl=en |
| +const char kPicasaINIFilename[] = ".picasa.ini"; |
| +const char kPicasaINIFilenameLegacy[] = "picasa.ini"; |
| + |
| +} |
| + |
| +SafePicasaAlbumsIndexer::SafePicasaAlbumsIndexer( |
| + const AlbumMap& albums, |
| + const AlbumMap& folders, |
| const ParserCallback& callback) |
| - : album_table_files_(album_table_files), |
| - callback_(callback), |
| + : callback_(callback), |
| parser_state_(INITIAL_STATE) { |
| DCHECK(MediaFileSystemMountPointProvider::CurrentlyOnMediaTaskRunnerThread()); |
| DCHECK(!callback_.is_null()); |
| + |
| + for (AlbumMap::const_iterator it = albums.begin(); it != albums.end(); ++it) { |
| + album_uids_.insert(it->second.uid); |
| + } |
| + |
| + for (AlbumMap::const_iterator it = folders.begin(); it != folders.end(); |
| + ++it) { |
| + folder_paths_.insert(it->second.path); |
| + } |
| } |
| -void SafePicasaAlbumTableReader::Start() { |
| +void SafePicasaAlbumsIndexer::Start() { |
| DCHECK(MediaFileSystemMountPointProvider::CurrentlyOnMediaTaskRunnerThread()); |
| BrowserThread::PostTask( |
| BrowserThread::IO, |
| FROM_HERE, |
| - base::Bind(&SafePicasaAlbumTableReader::StartWorkOnIOThread, this)); |
| + base::Bind(&SafePicasaAlbumsIndexer::StartWorkOnIOThread, this)); |
| } |
| -SafePicasaAlbumTableReader::~SafePicasaAlbumTableReader() { |
| +SafePicasaAlbumsIndexer::~SafePicasaAlbumsIndexer() { |
| } |
| -void SafePicasaAlbumTableReader::StartWorkOnIOThread() { |
| +void SafePicasaAlbumsIndexer::StartWorkOnIOThread() { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| DCHECK_EQ(INITIAL_STATE, parser_state_); |
| - utility_process_host_ = content::UtilityProcessHost::Create( |
| - this, |
| - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get()) |
| - ->AsWeakPtr(); |
| - // Wait for the startup notification before sending the main IPC to the |
| - // utility process, so that we can dup the file handle. |
| - utility_process_host_->Send(new ChromeUtilityMsg_StartupPing); |
| - parser_state_ = PINGED_UTILITY_PROCESS_STATE; |
| -} |
| + std::vector<picasa::FolderINIContents> folder_inis; |
| -void SafePicasaAlbumTableReader::OnProcessStarted() { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| - if (parser_state_ != PINGED_UTILITY_PROCESS_STATE) |
| - return; |
| + for (std::vector<base::FilePath>::const_iterator it = folder_paths_.begin(); |
| + it != folder_paths_.end(); ++it) { |
| + FolderINIContents folder_ini; |
| + folder_ini.folder_path = *it; |
| - if (utility_process_host_->GetData().handle == base::kNullProcessHandle) { |
| - DLOG(ERROR) << "Child process handle is null"; |
| + // See kPicasaINIFilename declaration for details. |
| + if (file_util::ReadFileToString(it->Append(kPicasaINIFilename), |
| + &folder_ini.ini_contents) || |
| + file_util::ReadFileToString(it->Append(kPicasaINIFilenameLegacy), |
| + &folder_ini.ini_contents)) { |
| + folder_inis.push_back(folder_ini); |
| + } |
| } |
| - AlbumTableFilesForTransit files_for_transit; |
| - files_for_transit.indicator_file = IPC::GetFileHandleForProcess( |
| - album_table_files_.indicator_file, |
| - utility_process_host_->GetData().handle, |
| - true /* close_source_handle */); |
| - files_for_transit.category_file = IPC::GetFileHandleForProcess( |
| - album_table_files_.category_file, |
| - utility_process_host_->GetData().handle, |
| - true /* close_source_handle */); |
| - files_for_transit.date_file = IPC::GetFileHandleForProcess( |
| - album_table_files_.date_file, |
| - utility_process_host_->GetData().handle, |
| - true /* close_source_handle */); |
| - files_for_transit.filename_file = IPC::GetFileHandleForProcess( |
| - album_table_files_.filename_file, |
| - utility_process_host_->GetData().handle, |
| - true /* close_source_handle */); |
| - files_for_transit.name_file = IPC::GetFileHandleForProcess( |
| - album_table_files_.name_file, |
| - utility_process_host_->GetData().handle, |
| - true /* close_source_handle */); |
| - files_for_transit.token_file = IPC::GetFileHandleForProcess( |
| - album_table_files_.token_file, |
| - utility_process_host_->GetData().handle, |
| - true /* close_source_handle */); |
| - files_for_transit.uid_file = IPC::GetFileHandleForProcess( |
| - album_table_files_.uid_file, |
| - utility_process_host_->GetData().handle, |
| - true /* close_source_handle */); |
| - utility_process_host_->Send(new ChromeUtilityMsg_ParsePicasaPMPDatabase( |
| - files_for_transit)); |
| + |
| + UtilityProcessHost* host = |
| + UtilityProcessHost::Create(this, base::MessageLoopProxy::current()); |
| + host->EnableZygote(); |
| + host->Send(new ChromeUtilityMsg_IndexPicasaAlbumsContents(album_uids_, |
| + folder_inis)); |
| parser_state_ = STARTED_PARSING_STATE; |
| } |
| -void SafePicasaAlbumTableReader::OnParsePicasaPMPDatabaseFinished( |
| - bool parse_success, |
| - const std::vector<AlbumInfo>& albums, |
| - const std::vector<AlbumInfo>& folders) { |
| +void OnIndexPicasaAlbumsContentsFinished(const AlbumImagesMap& albums_images) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| if (parser_state_ != STARTED_PARSING_STATE) |
| return; |
| MediaFileSystemMountPointProvider::MediaTaskRunner()->PostTask( |
| FROM_HERE, |
| - base::Bind(callback_, parse_success, albums, folders)); |
| + base::Bind(callback_, albums_images)); |
| parser_state_ = FINISHED_PARSING_STATE; |
| } |
| -void SafePicasaAlbumTableReader::OnProcessCrashed(int exit_code) { |
| - OnParsePicasaPMPDatabaseFinished(false, std::vector<AlbumInfo>(), |
| - std::vector<AlbumInfo>()); |
| +void SafePicasaAlbumsIndexer::OnProcessCrashed(int exit_code) { |
| + OnIndexPicasaAlbumsContentsFinished(AlbumImagesMap()); |
| } |
| -bool SafePicasaAlbumTableReader::OnMessageReceived( |
| +bool SafePicasaAlbumsIndexer::OnMessageReceived( |
| const IPC::Message& message) { |
| bool handled = true; |
| - IPC_BEGIN_MESSAGE_MAP(SafePicasaAlbumTableReader, message) |
| - IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ProcessStarted, |
| - OnProcessStarted) |
| - IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParsePicasaPMPDatabase_Finished, |
| - OnParsePicasaPMPDatabaseFinished) |
| + IPC_BEGIN_MESSAGE_MAP(SafePicasaAlbumsIndexer, message) |
| + IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_IndexPicasaAlbumContents_Finished, |
| + OnIndexPicasaAlbumsContentsFinished) |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP() |
| return handled; |