| 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. | |
| 29 const int kPicasaINIReadBatchSize = 10; | |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 33 SafePicasaAlbumsIndexer::SafePicasaAlbumsIndexer( | 33 SafePicasaAlbumsIndexer::SafePicasaAlbumsIndexer( |
| 34 const AlbumMap& albums, | 34 const AlbumMap& albums, |
| 35 const AlbumMap& folders, | 35 const AlbumMap& folders, |
| 36 const DoneCallback& callback) | 36 const DoneCallback& callback) |
| 37 : callback_(callback), | 37 : callback_(callback), |
| 38 parser_state_(INITIAL_STATE) { | 38 parser_state_(INITIAL_STATE) { |
| 39 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 39 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
| 40 DCHECK(!callback_.is_null()); | 40 DCHECK(!callback_.is_null()); |
| 41 | 41 |
| 42 folders_inis_.reserve(folders.size()); | 42 folders_inis_.reserve(folders.size()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } | 107 } |
| 108 | 108 |
| 109 void SafePicasaAlbumsIndexer::OnIndexPicasaAlbumsContentsFinished( | 109 void SafePicasaAlbumsIndexer::OnIndexPicasaAlbumsContentsFinished( |
| 110 const AlbumImagesMap& albums_images) { | 110 const AlbumImagesMap& albums_images) { |
| 111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 112 if (parser_state_ != STARTED_PARSING_STATE) | 112 if (parser_state_ != STARTED_PARSING_STATE) |
| 113 return; | 113 return; |
| 114 | 114 |
| 115 MediaFileSystemBackend::MediaTaskRunner()->PostTask( | 115 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
| 116 FROM_HERE, | 116 FROM_HERE, |
| 117 base::Bind(callback_, true, albums_images)); | 117 base::Bind(callback_, make_scoped_refptr(this), true, albums_images)); |
| 118 parser_state_ = FINISHED_PARSING_STATE; | 118 parser_state_ = FINISHED_PARSING_STATE; |
| 119 } | 119 } |
| 120 | 120 |
| 121 void SafePicasaAlbumsIndexer::OnProcessCrashed(int exit_code) { | 121 void SafePicasaAlbumsIndexer::OnProcessCrashed(int exit_code) { |
| 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 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_, make_scoped_refptr(this), 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 |