| 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_picasa_albums_indexer.h" | 5 #include "chrome/browser/media_galleries/fileapi/safe_picasa_albums_indexer.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" | 8 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
| 9 #include "chrome/common/chrome_utility_messages.h" | 9 #include "chrome/common/chrome_utility_messages.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/child_process_data.h" | 11 #include "content/public/browser/child_process_data.h" |
| 12 #include "content/public/browser/utility_process_host.h" | 12 #include "content/public/browser/utility_process_host.h" |
| 13 | 13 |
| 14 using chrome::MediaFileSystemBackend; | 14 using chrome::MediaFileSystemBackend; |
| 15 using content::BrowserThread; | 15 using content::BrowserThread; |
| 16 using content::UtilityProcessHost; | 16 using content::UtilityProcessHost; |
| 17 | 17 |
| 18 namespace picasa { | 18 namespace picasa { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // Arbitrarily chosen to be a decent size but not block thread too much. |
| 23 const int kPicasaINIReadBatchSize = 10; |
| 24 |
| 25 } // namespace |
| 26 |
| 22 // Picasa INI files are named "picasa.ini" on Picasa for Windows before version | 27 // Picasa INI files are named "picasa.ini" on Picasa for Windows before version |
| 23 // 71.18. Later versions and Picasa for Mac uses ".picasa.ini". | 28 // 71.18. Later versions and Picasa for Mac uses ".picasa.ini". |
| 24 // See: https://support.google.com/picasa/answer/11257?hl=en | 29 // See: https://support.google.com/picasa/answer/11257?hl=en |
| 25 const char kPicasaINIFilename[] = ".picasa.ini"; | 30 const char kPicasaINIFilename[] = ".picasa.ini"; |
| 26 const char kPicasaINIFilenameLegacy[] = "picasa.ini"; | 31 const char kPicasaINIFilenameLegacy[] = "picasa.ini"; |
| 27 | 32 |
| 28 // Arbitrarily chosen to be a decent size but not block thread too much. | 33 SafePicasaAlbumsIndexer::SafePicasaAlbumsIndexer(const AlbumMap& albums, |
| 29 const int kPicasaINIReadBatchSize = 10; | 34 const AlbumMap& folders) |
| 30 | 35 : parser_state_(INITIAL_STATE) { |
| 31 } // namespace | |
| 32 | |
| 33 SafePicasaAlbumsIndexer::SafePicasaAlbumsIndexer( | |
| 34 const AlbumMap& albums, | |
| 35 const AlbumMap& folders, | |
| 36 const DoneCallback& callback) | |
| 37 : callback_(callback), | |
| 38 parser_state_(INITIAL_STATE) { | |
| 39 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 36 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
| 40 DCHECK(!callback_.is_null()); | |
| 41 | 37 |
| 42 folders_inis_.reserve(folders.size()); | 38 folders_inis_.reserve(folders.size()); |
| 43 | 39 |
| 44 for (AlbumMap::const_iterator it = albums.begin(); it != albums.end(); ++it) | 40 for (AlbumMap::const_iterator it = albums.begin(); it != albums.end(); ++it) |
| 45 album_uids_.insert(it->second.uid); | 41 album_uids_.insert(it->second.uid); |
| 46 | 42 |
| 47 for (AlbumMap::const_iterator it = folders.begin(); it != folders.end(); ++it) | 43 for (AlbumMap::const_iterator it = folders.begin(); it != folders.end(); ++it) |
| 48 folders_queue_.push(it->second.path); | 44 folders_queue_.push(it->second.path); |
| 49 } | 45 } |
| 50 | 46 |
| 51 void SafePicasaAlbumsIndexer::Start() { | 47 void SafePicasaAlbumsIndexer::Start(const DoneCallback& callback) { |
| 52 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 48 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
| 49 DCHECK(!callback.is_null()); |
| 53 | 50 |
| 51 callback_ = callback; |
| 54 ProcessFoldersBatch(); | 52 ProcessFoldersBatch(); |
| 55 } | 53 } |
| 56 | 54 |
| 57 SafePicasaAlbumsIndexer::~SafePicasaAlbumsIndexer() { | 55 SafePicasaAlbumsIndexer::~SafePicasaAlbumsIndexer() { |
| 58 } | 56 } |
| 59 | 57 |
| 60 void SafePicasaAlbumsIndexer::ProcessFoldersBatch() { | 58 void SafePicasaAlbumsIndexer::ProcessFoldersBatch() { |
| 61 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 59 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
| 62 | 60 |
| 63 for (int i = 0; i < kPicasaINIReadBatchSize && !folders_queue_.empty(); ++i) { | 61 for (int i = 0; i < kPicasaINIReadBatchSize && !folders_queue_.empty(); ++i) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 UtilityProcessHost::Create(this, base::MessageLoopProxy::current()); | 100 UtilityProcessHost::Create(this, base::MessageLoopProxy::current()); |
| 103 host->EnableZygote(); | 101 host->EnableZygote(); |
| 104 host->Send(new ChromeUtilityMsg_IndexPicasaAlbumsContents(album_uids_, | 102 host->Send(new ChromeUtilityMsg_IndexPicasaAlbumsContents(album_uids_, |
| 105 folders_inis_)); | 103 folders_inis_)); |
| 106 parser_state_ = STARTED_PARSING_STATE; | 104 parser_state_ = STARTED_PARSING_STATE; |
| 107 } | 105 } |
| 108 | 106 |
| 109 void SafePicasaAlbumsIndexer::OnIndexPicasaAlbumsContentsFinished( | 107 void SafePicasaAlbumsIndexer::OnIndexPicasaAlbumsContentsFinished( |
| 110 const AlbumImagesMap& albums_images) { | 108 const AlbumImagesMap& albums_images) { |
| 111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 110 DCHECK(!callback_.is_null()); |
| 112 if (parser_state_ != STARTED_PARSING_STATE) | 111 if (parser_state_ != STARTED_PARSING_STATE) |
| 113 return; | 112 return; |
| 114 | 113 |
| 115 MediaFileSystemBackend::MediaTaskRunner()->PostTask( | 114 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
| 116 FROM_HERE, | 115 FROM_HERE, |
| 117 base::Bind(callback_, true, albums_images)); | 116 base::Bind(callback_, true, albums_images)); |
| 118 parser_state_ = FINISHED_PARSING_STATE; | 117 parser_state_ = FINISHED_PARSING_STATE; |
| 119 } | 118 } |
| 120 | 119 |
| 121 void SafePicasaAlbumsIndexer::OnProcessCrashed(int exit_code) { | 120 void SafePicasaAlbumsIndexer::OnProcessCrashed(int exit_code) { |
| 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 122 DCHECK(!callback_.is_null()); |
| 123 | 123 |
| 124 MediaFileSystemBackend::MediaTaskRunner()->PostTask( | 124 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
| 125 FROM_HERE, | 125 FROM_HERE, |
| 126 base::Bind(callback_, false, AlbumImagesMap())); | 126 base::Bind(callback_, false, AlbumImagesMap())); |
| 127 } | 127 } |
| 128 | 128 |
| 129 bool SafePicasaAlbumsIndexer::OnMessageReceived( | 129 bool SafePicasaAlbumsIndexer::OnMessageReceived( |
| 130 const IPC::Message& message) { | 130 const IPC::Message& message) { |
| 131 bool handled = true; | 131 bool handled = true; |
| 132 IPC_BEGIN_MESSAGE_MAP(SafePicasaAlbumsIndexer, message) | 132 IPC_BEGIN_MESSAGE_MAP(SafePicasaAlbumsIndexer, message) |
| 133 IPC_MESSAGE_HANDLER( | 133 IPC_MESSAGE_HANDLER( |
| 134 ChromeUtilityHostMsg_IndexPicasaAlbumsContents_Finished, | 134 ChromeUtilityHostMsg_IndexPicasaAlbumsContents_Finished, |
| 135 OnIndexPicasaAlbumsContentsFinished) | 135 OnIndexPicasaAlbumsContentsFinished) |
| 136 IPC_MESSAGE_UNHANDLED(handled = false) | 136 IPC_MESSAGE_UNHANDLED(handled = false) |
| 137 IPC_END_MESSAGE_MAP() | 137 IPC_END_MESSAGE_MAP() |
| 138 return handled; | 138 return handled; |
| 139 } | 139 } |
| 140 | 140 |
| 141 } // namespace picasa | 141 } // namespace picasa |
| OLD | NEW |