| 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" | |
| 13 | 12 |
| 14 using chrome::MediaFileSystemBackend; | 13 using chrome::MediaFileSystemBackend; |
| 15 using content::BrowserThread; | 14 using content::BrowserThread; |
| 16 using content::UtilityProcessHost; | 15 using content::UtilityProcessHost; |
| 17 | 16 |
| 18 namespace picasa { | 17 namespace picasa { |
| 19 | 18 |
| 20 namespace { | 19 namespace { |
| 21 | 20 |
| 22 // Picasa INI files are named "picasa.ini" on Picasa for Windows before version | 21 // Picasa INI files are named "picasa.ini" on Picasa for Windows before version |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 BrowserThread::IO, | 97 BrowserThread::IO, |
| 99 FROM_HERE, | 98 FROM_HERE, |
| 100 base::Bind(&SafePicasaAlbumsIndexer::StartWorkOnIOThread, this)); | 99 base::Bind(&SafePicasaAlbumsIndexer::StartWorkOnIOThread, this)); |
| 101 } | 100 } |
| 102 } | 101 } |
| 103 | 102 |
| 104 void SafePicasaAlbumsIndexer::StartWorkOnIOThread() { | 103 void SafePicasaAlbumsIndexer::StartWorkOnIOThread() { |
| 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 106 DCHECK_EQ(FINISHED_READING_INI_FILES_STATE, parser_state_); | 105 DCHECK_EQ(FINISHED_READING_INI_FILES_STATE, parser_state_); |
| 107 | 106 |
| 108 UtilityProcessHost* host = | 107 utility_process_host_ = content::UtilityProcessHost::Create( |
| 109 UtilityProcessHost::Create(this, base::MessageLoopProxy::current()); | 108 this, |
| 110 host->EnableZygote(); | 109 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get()) |
| 111 host->Send(new ChromeUtilityMsg_IndexPicasaAlbumsContents(album_uids_, | 110 ->AsWeakPtr(); |
| 112 folders_inis_)); | 111 |
| 112 utility_process_host_->EnableZygote(); |
| 113 utility_process_host_->Send(new ChromeUtilityMsg_IndexPicasaAlbumsContents( |
| 114 album_uids_, folders_inis_)); |
| 113 parser_state_ = STARTED_PARSING_STATE; | 115 parser_state_ = STARTED_PARSING_STATE; |
| 114 } | 116 } |
| 115 | 117 |
| 116 void SafePicasaAlbumsIndexer::OnIndexPicasaAlbumsContentsFinished( | 118 void SafePicasaAlbumsIndexer::OnIndexPicasaAlbumsContentsFinished( |
| 117 const AlbumImagesMap& albums_images) { | 119 const AlbumImagesMap& albums_images) { |
| 118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 119 if (parser_state_ != STARTED_PARSING_STATE) | 121 if (parser_state_ != STARTED_PARSING_STATE) |
| 120 return; | 122 return; |
| 121 | 123 |
| 122 MediaFileSystemBackend::MediaTaskRunner()->PostTask( | 124 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
| 123 FROM_HERE, | 125 FROM_HERE, |
| 124 base::Bind(callback_, albums_images)); | 126 base::Bind(callback_, |
| 127 make_scoped_refptr(this), |
| 128 albums_images)); |
| 125 parser_state_ = FINISHED_PARSING_STATE; | 129 parser_state_ = FINISHED_PARSING_STATE; |
| 126 } | 130 } |
| 127 | 131 |
| 128 void SafePicasaAlbumsIndexer::OnProcessCrashed(int exit_code) { | 132 void SafePicasaAlbumsIndexer::OnProcessCrashed(int exit_code) { |
| 129 OnIndexPicasaAlbumsContentsFinished(AlbumImagesMap()); | 133 OnIndexPicasaAlbumsContentsFinished(AlbumImagesMap()); |
| 130 } | 134 } |
| 131 | 135 |
| 132 bool SafePicasaAlbumsIndexer::OnMessageReceived( | 136 bool SafePicasaAlbumsIndexer::OnMessageReceived( |
| 133 const IPC::Message& message) { | 137 const IPC::Message& message) { |
| 134 bool handled = true; | 138 bool handled = true; |
| 135 IPC_BEGIN_MESSAGE_MAP(SafePicasaAlbumsIndexer, message) | 139 IPC_BEGIN_MESSAGE_MAP(SafePicasaAlbumsIndexer, message) |
| 136 IPC_MESSAGE_HANDLER( | 140 IPC_MESSAGE_HANDLER( |
| 137 ChromeUtilityHostMsg_IndexPicasaAlbumsContents_Finished, | 141 ChromeUtilityHostMsg_IndexPicasaAlbumsContents_Finished, |
| 138 OnIndexPicasaAlbumsContentsFinished) | 142 OnIndexPicasaAlbumsContentsFinished) |
| 139 IPC_MESSAGE_UNHANDLED(handled = false) | 143 IPC_MESSAGE_UNHANDLED(handled = false) |
| 140 IPC_END_MESSAGE_MAP() | 144 IPC_END_MESSAGE_MAP() |
| 141 return handled; | 145 return handled; |
| 142 } | 146 } |
| 143 | 147 |
| 144 } // namespace picasa | 148 } // namespace picasa |
| OLD | NEW |